2
0
Эх сурвалжийг харах

world: always clear sun shadow map

Daniele Bartolini 5 сар өмнө
parent
commit
1b4906dc9b

+ 1 - 0
docs/changelog.rst

@@ -18,6 +18,7 @@ Changelog
 **Fixes**
 
 * Runtime: fixed a crash when too many lights were spawned in a level.
+* Runtime: fixed cascaded shadows artifacts in some circumnstances.
 
 0.58.0 --- 01 Aug 2025
 ----------------------

+ 1 - 1
src/device/device.cpp

@@ -810,8 +810,8 @@ void Device::render(World &world, UnitId camera_unit)
 	const Matrix4x4 view = world.camera_view_matrix(camera);
 	const Matrix4x4 proj = world.camera_projection_matrix(camera, aspect_ratio);
 
-	_pipeline->render(_width, _height, view, proj);
 	world.render(view, proj);
+	_pipeline->render(_width, _height, view, proj);
 }
 
 World *Device::create_world()

+ 6 - 0
src/device/pipeline.cpp

@@ -407,6 +407,12 @@ void Pipeline::render(u16 width, u16 height, const Matrix4x4 &view, const Matrix
 			bgfx::setViewMode(id, bgfx::ViewMode::DepthAscending);
 			bgfx::setViewFrameBuffer(id, _colors[0]);
 			bgfx::touch(id);
+		} else if (id == View::CASCADE_CLEAR) {
+			view_name = "sm_cascade_clear";
+			bgfx::setViewFrameBuffer(id, _sun_shadow_map_frame_buffer);
+			bgfx::setViewRect(id, 0, 0, (u16)_render_settings.sun_shadow_map_size.x, (u16)_render_settings.sun_shadow_map_size.y);
+			bgfx::setViewClear(id, BGFX_CLEAR_DEPTH, 0xffffffff, 1.0f, 0);
+			bgfx::touch(id);
 		} else if (id >= View::CASCADE_0 && id < View::CASCADE_LAST) {
 			view_name = "sm_cascade";
 		} else if (id == View::LIGHTS) {

+ 1 - 0
src/device/pipeline.h

@@ -23,6 +23,7 @@ struct View
 	{
 		COLOR_0,
 		COLOR_1,
+		CASCADE_CLEAR,
 		CASCADE_0,
 		CASCADE_LAST          = CASCADE_0 + MAX_NUM_CASCADES,
 		LIGHTS                = CASCADE_LAST,

+ 0 - 2
src/world/render_world.cpp

@@ -734,8 +734,6 @@ void RenderWorld::render(const Matrix4x4 &view, const Matrix4x4 &proj, UnitId sk
 
 				bgfx::setViewRect(View::CASCADE_0 + i, rects[i].x, rects[i].y, rects[i].z, rects[i].w);
 				bgfx::setViewFrameBuffer(View::CASCADE_0 + i, _pipeline->_sun_shadow_map_frame_buffer);
-				bgfx::setViewClear(View::CASCADE_0 + i, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0xffffffff, 1.0f, 0);
-
 				bgfx::setViewTransform(View::CASCADE_0 + i, to_float_ptr(light_view), to_float_ptr(light_proj));
 
 				_mesh_manager.draw_shadow_casters(View::CASCADE_0 + i, *_scene_graph);