optimize shadow maps generation a bit
This commit is contained in:
parent
e24d1bdb9c
commit
6debc92ae5
@ -185,6 +185,9 @@ const Mesh<ChunkVertex>* ChunksRenderer::retrieveChunk(
|
|||||||
void ChunksRenderer::drawChunksShadowsPass(
|
void ChunksRenderer::drawChunksShadowsPass(
|
||||||
const Camera& camera, Shader& shader
|
const Camera& camera, Shader& shader
|
||||||
) {
|
) {
|
||||||
|
Frustum frustum;
|
||||||
|
frustum.update(camera.getProjView());
|
||||||
|
|
||||||
const auto& atlas = assets.require<Atlas>("blocks");
|
const auto& atlas = assets.require<Atlas>("blocks");
|
||||||
|
|
||||||
atlas.getTexture()->bind();
|
atlas.getTexture()->bind();
|
||||||
@ -193,19 +196,29 @@ void ChunksRenderer::drawChunksShadowsPass(
|
|||||||
if (chunk == nullptr) {
|
if (chunk == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
glm::ivec2 pos {chunk->x, chunk->z};
|
||||||
const auto& found = meshes.find({chunk->x, chunk->z});
|
const auto& found = meshes.find({chunk->x, chunk->z});
|
||||||
if (found == meshes.end()) {
|
if (found == meshes.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto mesh = found->second.mesh.get();
|
|
||||||
if (mesh) {
|
|
||||||
glm::vec3 coord(
|
glm::vec3 coord(
|
||||||
chunk->x * CHUNK_W + 0.5f, 0.5f, chunk->z * CHUNK_D + 0.5f
|
pos.x * CHUNK_W + 0.5f, 0.5f, pos.y * CHUNK_D + 0.5f
|
||||||
);
|
);
|
||||||
|
|
||||||
|
glm::vec3 min(pos.x * CHUNK_W, chunk->bottom, chunk->z * CHUNK_D);
|
||||||
|
glm::vec3 max(
|
||||||
|
chunk->x * CHUNK_W + CHUNK_W,
|
||||||
|
chunk->top,
|
||||||
|
chunk->z * CHUNK_D + CHUNK_D
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!frustum.isBoxVisible(min, max)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), coord);
|
glm::mat4 model = glm::translate(glm::mat4(1.0f), coord);
|
||||||
shader.uniformMatrix("u_model", model);
|
shader.uniformMatrix("u_model", model);
|
||||||
mesh->draw();
|
found->second.mesh->draw();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -400,7 +400,6 @@ void WorldRenderer::generateShadowsMap(
|
|||||||
shadowCamera.setProjection(glm::ortho(min.x, max.x, min.y, max.y, 0.1f, 1000.0f));
|
shadowCamera.setProjection(glm::ortho(min.x, max.x, min.y, max.y, 0.1f, 1000.0f));
|
||||||
|
|
||||||
{
|
{
|
||||||
frustumCulling->update(shadowCamera.getProjView());
|
|
||||||
auto sctx = pctx.sub();
|
auto sctx = pctx.sub();
|
||||||
sctx.setDepthTest(true);
|
sctx.setDepthTest(true);
|
||||||
sctx.setCullFace(true);
|
sctx.setCullFace(true);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user