From a313d4a1050815d987f855cafaea046dba158625 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 7 Oct 2021 18:04:19 +0300 Subject: [PATCH] Use the shadow camera's projection matrix to form the shadow matrix This makes it easier to support different types of projection, such as perspective projection for point lights. --- source/effects/shadowmap.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index 1b5f531b..a0627faa 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -153,10 +153,8 @@ void ShadowMap::setup_frame(Renderer &renderer) l.shadow_camera.set_orthographic(radius*2, radius*2); l.shadow_camera.set_depth_clip(-radius, radius); - Matrix shadow_matrix = l.shadow_camera.get_object_matrix(); - shadow_matrix.scale(radius*2, radius*2, -radius*2); - shadow_matrix.translate(-0.5, -0.5, depth_bias/l.region.width-0.5); - shadow_matrix.invert(); + Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f-depth_bias/l.region.width)).scale(0.5f); + Matrix shadow_matrix = to_texcoord*l.shadow_camera.get_projection_matrix()*l.shadow_camera.get_view_matrix(); shdata.uniform(format("shadows[%d].shd_world_matrix", l.index), shadow_matrix); } -- 2.43.0