while continuing my work on my deferred shader engine I descided to implement a shadowmapping feature.
Here is the process i do for each light that casts shadows:
1. render the scene from light point of view to create depth-shadowmap
2. store modelview and projection matrix
3. draw light to lightmap using g-buffer and shadowmap
3.1 build transformation matrix that goes from cameraspace to light-view-clipping space by using this matrix:
transformation-matrix = light_projection_matrix * light_modelview_matrix * camera_modelview_matrix_inverse
3.2 In the shader: read fragment position from gbuffer, calculate shadowmap_texture_coordinate with:
shadowmap_texture_coordinate = transformation-matrix * gbuffer_pos
3.3 do the is-in-shadow check stuff
I have several problems:
1. The shadowmap_texture_coordinate does not seem to have an orthographic projection. I fixed this by applying this to the shadowmap_texture_coordinate (sc):
sc.xy = sc.xy / sc.z
This is not correct in any way I think but I have no idea what else could cause the projection-bug.
2. When I read from the shadowmap I get values in [0,1]. How do I transform these to compare them with the distance of a fragment from the light-position since those are given in engine-units.
I hope someone will understand what I am doing

Find content
Not Telling