Brief information about where I am (to make sure that we are on the same page, and to check if I am absent / assume something stupid):
- Purpose: I want to make my scene shadows using deferred lighting and shadowmaps.
- Fight: search for clear and consistent documentation on how to use shadow2D and sampler2DShadow.
Here is what I am doing now:
In the fragment shader of my final rendering (the one that actually calculates the final fragment values) I have the MVP matrices from the passage from an easy point of view, the depth texture from this passage (also called the "shadow map" "), and the position / normal / color textures from my geometric buffer.
From what I understand, I need to find that the UV shadow map corresponds to the position of the current fragment. I do it as follows:
//Bring position value at fragment (in world space) to screen space from lights POV vec4 UVinShadowMap = (lightProjMat * lightViewMat * vec4(texture(pos_tex, UV).xyz,1.0)).xy; //Convert screen space to 'texture space' (from -1to1 to 0to1) UVinShadowMap = (UVinShadowMap+1)/2;
Now that I have this UV, I can get the missing โdepthโ from the light wave with
float depFromLightPOV = texture2D(shadowMap, UVinShadowMap).r;
and compare this with the distance between the position on the current fragment and the light:
float actualDistance = distance(texture2D(pos_tex, UV).xyz, lightPos);
The problem arises because the "depth" is stored in the values โโ0-1, and the actual distance is in world coordinates. I tried to do this conversion manually, but could not get it to work. And on an internet search, it looks like I MUST do this with sampler2DShadow ...
So here is my question (s):
What changes do I need to make to use shadow2D instead? What does shadow2D do? Is this more or less the texture of automatic conversion from depth to world? Can I use the same depth texture? Or do I need to make the depth texture another way? What should I pass to shadow2D? I want to check the position in the world of fragment space? Or the same UV as before?
If all of these questions can be answered on a simple documentation page, I would like someone to just post this. But I swear I was looking for a watch and can't find anything that just says what happens to shadow2D!
Thanks!