fix frustum culling for entities
This commit is contained in:
parent
e399e95930
commit
78e274dec4
@ -194,6 +194,7 @@ void WorldRenderer::renderLevel(
|
|||||||
auto assets = engine->getAssets();
|
auto assets = engine->getAssets();
|
||||||
auto atlas = assets->get<Atlas>("blocks");
|
auto atlas = assets->get<Atlas>("blocks");
|
||||||
|
|
||||||
|
bool culling = engine->getSettings().graphics.frustumCulling.get();
|
||||||
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance.get()-2);
|
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance.get()-2);
|
||||||
|
|
||||||
auto shader = assets->get<Shader>("main");
|
auto shader = assets->get<Shader>("main");
|
||||||
@ -207,7 +208,8 @@ void WorldRenderer::renderLevel(
|
|||||||
auto entityShader = assets->get<Shader>("entity");
|
auto entityShader = assets->get<Shader>("entity");
|
||||||
setupWorldShader(entityShader, camera, settings, fogFactor);
|
setupWorldShader(entityShader, camera, settings, fogFactor);
|
||||||
|
|
||||||
level->entities->render(assets, *modelBatch, *frustumCulling, delta, pause);
|
level->entities->render(
|
||||||
|
assets, *modelBatch, culling ? frustumCulling.get() : nullptr, delta, pause);
|
||||||
|
|
||||||
if (!pause) {
|
if (!pause) {
|
||||||
scripting::on_frontend_render();
|
scripting::on_frontend_render();
|
||||||
@ -252,7 +254,9 @@ void WorldRenderer::renderLines(
|
|||||||
renderBlockSelection();
|
renderBlockSelection();
|
||||||
}
|
}
|
||||||
if (player->debug && showEntitiesDebug) {
|
if (player->debug && showEntitiesDebug) {
|
||||||
level->entities->renderDebug(*lineBatch, *frustumCulling, ctx);
|
bool culling = engine->getSettings().graphics.frustumCulling.get();
|
||||||
|
level->entities->renderDebug(
|
||||||
|
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -472,7 +472,7 @@ static void debug_render_skeleton(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Entities::renderDebug(
|
void Entities::renderDebug(
|
||||||
LineBatch& batch, const Frustum& frustum, const DrawContext& pctx
|
LineBatch& batch, const Frustum* frustum, const DrawContext& pctx
|
||||||
) {
|
) {
|
||||||
{
|
{
|
||||||
auto ctx = pctx.sub(&batch);
|
auto ctx = pctx.sub(&batch);
|
||||||
@ -482,7 +482,7 @@ void Entities::renderDebug(
|
|||||||
const auto& hitbox = rigidbody.hitbox;
|
const auto& hitbox = rigidbody.hitbox;
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
if (!frustum.isBoxVisible(pos-size, pos+size)) {
|
if (frustum && !frustum->isBoxVisible(pos-size, pos+size)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
||||||
@ -507,7 +507,7 @@ void Entities::renderDebug(
|
|||||||
auto config = skeleton.config;
|
auto config = skeleton.config;
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
if (!frustum.isBoxVisible(pos-size, pos+size)) {
|
if (frustum && !frustum->isBoxVisible(pos-size, pos+size)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto bone = config->getRoot();
|
auto bone = config->getRoot();
|
||||||
@ -517,7 +517,7 @@ void Entities::renderDebug(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Entities::render(
|
void Entities::render(
|
||||||
Assets* assets, ModelBatch& batch, const Frustum& frustum, float delta, bool pause
|
Assets* assets, ModelBatch& batch, const Frustum* frustum, float delta, bool pause
|
||||||
) {
|
) {
|
||||||
if (!pause) {
|
if (!pause) {
|
||||||
scripting::on_entities_render(delta);
|
scripting::on_entities_render(delta);
|
||||||
@ -530,7 +530,7 @@ void Entities::render(
|
|||||||
}
|
}
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
if (frustum.isBoxVisible(pos-size, pos+size)) {
|
if (!frustum || frustum->isBoxVisible(pos-size, pos+size)) {
|
||||||
const auto* rigConfig = skeleton.config;
|
const auto* rigConfig = skeleton.config;
|
||||||
rigConfig->render(assets, batch, skeleton, transform.combined);
|
rigConfig->render(assets, batch, skeleton, transform.combined);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,7 +177,7 @@ public:
|
|||||||
struct RaycastResult {
|
struct RaycastResult {
|
||||||
entityid_t entity;
|
entityid_t entity;
|
||||||
glm::ivec3 normal;
|
glm::ivec3 normal;
|
||||||
float distance;
|
float distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
Entities(Level* level);
|
Entities(Level* level);
|
||||||
@ -186,8 +186,8 @@ public:
|
|||||||
void updatePhysics(float delta);
|
void updatePhysics(float delta);
|
||||||
void update(float delta);
|
void update(float delta);
|
||||||
|
|
||||||
void renderDebug(LineBatch& batch, const Frustum& frustum, const DrawContext& ctx);
|
void renderDebug(LineBatch& batch, const Frustum* frustum, const DrawContext& ctx);
|
||||||
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, float delta, bool pause);
|
void render(Assets* assets, ModelBatch& batch, const Frustum* frustum, float delta, bool pause);
|
||||||
|
|
||||||
entityid_t spawn(
|
entityid_t spawn(
|
||||||
EntityDef& def,
|
EntityDef& def,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user