fix frustum culling for entities

This commit is contained in:
MihailRis 2024-08-03 17:41:03 +03:00
parent e399e95930
commit 78e274dec4
3 changed files with 14 additions and 10 deletions

View File

@ -194,6 +194,7 @@ void WorldRenderer::renderLevel(
auto assets = engine->getAssets();
auto atlas = assets->get<Atlas>("blocks");
bool culling = engine->getSettings().graphics.frustumCulling.get();
float fogFactor = 15.0f / ((float)settings.chunks.loadDistance.get()-2);
auto shader = assets->get<Shader>("main");
@ -207,7 +208,8 @@ void WorldRenderer::renderLevel(
auto entityShader = assets->get<Shader>("entity");
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) {
scripting::on_frontend_render();
@ -252,7 +254,9 @@ void WorldRenderer::renderLines(
renderBlockSelection();
}
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);
}
}

View File

@ -472,7 +472,7 @@ static void debug_render_skeleton(
}
void Entities::renderDebug(
LineBatch& batch, const Frustum& frustum, const DrawContext& pctx
LineBatch& batch, const Frustum* frustum, const DrawContext& pctx
) {
{
auto ctx = pctx.sub(&batch);
@ -482,7 +482,7 @@ void Entities::renderDebug(
const auto& hitbox = rigidbody.hitbox;
const auto& pos = transform.pos;
const auto& size = transform.size;
if (!frustum.isBoxVisible(pos-size, pos+size)) {
if (frustum && !frustum->isBoxVisible(pos-size, pos+size)) {
continue;
}
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
@ -507,7 +507,7 @@ void Entities::renderDebug(
auto config = skeleton.config;
const auto& pos = transform.pos;
const auto& size = transform.size;
if (!frustum.isBoxVisible(pos-size, pos+size)) {
if (frustum && !frustum->isBoxVisible(pos-size, pos+size)) {
continue;
}
auto bone = config->getRoot();
@ -517,7 +517,7 @@ void Entities::renderDebug(
}
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) {
scripting::on_entities_render(delta);
@ -530,7 +530,7 @@ void Entities::render(
}
const auto& pos = transform.pos;
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;
rigConfig->render(assets, batch, skeleton, transform.combined);
}

View File

@ -177,7 +177,7 @@ public:
struct RaycastResult {
entityid_t entity;
glm::ivec3 normal;
float distance;
float distance;
};
Entities(Level* level);
@ -186,8 +186,8 @@ public:
void updatePhysics(float delta);
void update(float delta);
void renderDebug(LineBatch& batch, const Frustum& frustum, const DrawContext& ctx);
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, float delta, bool pause);
void renderDebug(LineBatch& batch, const Frustum* frustum, const DrawContext& ctx);
void render(Assets* assets, ModelBatch& batch, const Frustum* frustum, float delta, bool pause);
entityid_t spawn(
EntityDef& def,