It says that is is dividing this: ShadowCoord = texCoord / texCoord.w; //<- here
to get perspective-correct projective texture coordinates and save having to do the divide on the fragment shader. however with this line left as it is, my shadows show incorrectly where as changing it to ShadowCoord = texCoord;
makes them display correctly, albeit with plently of artifacts which is to be expected I believe.
The Fragment shader is also just as the book describes. and I construct gl_TextureMatrix[1] as
is there any really obvious mistake I could be making? I checked the deLight demo’s shaders (shadow_prologue.vert/frag i believe)on which this Vertex shader was based, it also doesn’t do the division by w.
I don’t have the answers you want, as I never did shadow mapping myself. But comparing the shaders to my projective texturing method I have an idea what may be going on.
The fragment shader is using shadow2DProj which AFAIK does the division for you.
You can try to do the division in the vertex shader (as the original code does) and use shadow2D instead of shadow2Dproj in the fragment shader.
Thank you for the suggestion, you are right that shadow2DProj divides through by the tex-coord’s q component (according to the Orange Book)
However leaving the Vertex shader in it’s original form and changing the Fragment shader’s lookup() function to use shadow2D doesn’t solve my problem.
It’s interesting to note that the Orange Book gives two subsequent Fragment shaders (in Listing 13.6 and 13.7, for generating anti-aliased edges) which are based on the one I posted above, however the lookup() function uses shadow2D and it does not explain the reason for the switch.
Could this be a mistake in the book? or maybe I am misreading somewhere and the 1 vertex and 3 fragment shaders they supplied for use in shadow mapping are not supposed to be used together?