- l.shadow_camera.set_object_matrix(*l.light->get_matrix());
- l.shadow_camera.set_position(target);
- // TODO support point and spot lights with a frustum projection.
- // Omnidirectional lights also need a cube shadow map.
- 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();
-
- shdata.uniform(format("shadows[%d].shd_world_matrix", l.index), shadow_matrix);
+ const ShadowedLight &light = lights[v.light_index];
+
+ if(light.type==DIRECTIONAL)
+ {
+ v.camera.set_object_matrix(*light.light->get_matrix());
+ v.camera.set_position(target);
+ v.camera.set_orthographic(radius*2, radius*2);
+ v.camera.set_depth_clip(-radius, radius);
+ }
+
+ Matrix to_texcoord = Matrix().translate(Vector3(0.5f, 0.5f, 0.5f-depth_bias/light.region.width)).scale(0.5f);
+ shadow_matrices.push_back(to_texcoord*v.camera.get_projection_matrix()*v.camera.get_view_matrix());