Quote:Original post by glaeken
You can calculate the projected texture coordinates in the vertex shader or the pixel shader. Calculating them in the pixel shader will be slower than in the vertex shader but should be a little more accurate.
The key here is though, you want to transform the vertex with your camera matrices and calculate the projected texture coords with the light matrices.
//assuming you're using column matrices, otherwise swap
ProjTexCoords = LightViewProj * worldSpacePos
ProjTexCoords.xy /= ProjTexCoords.w;
You say you transform the vertex with the camera matrices and then you multiply with light's matrices but here:
ProjTexCoords = LightViewProj * worldSpacePos
you take into account only the world space transformation and not the viewing transformation of the camera. Is this a typo?
I was confused and addressed the initial question because of this
article. Looking at the picture and at the formula:
(When rendering from the camera these are all happening to the texture coordinates)
LightClipSpaceTexCoord = LightProj * LightView * CameraView-1 * CameraViewTexCoord
I say CameraViewTexCoord because this vertex is calculated with respect to the position of the camera when requesting automatic texture generation.
But isn't this equivalent to:
LightClipSpaceVertex = LightProj * LightView * WorldSpaceVertex
Please bare with me, but i think i'm missing a simple thing down the road.