I’m currently working on trying to implement shadow mapping on my old GF2MX (Personal project, just to see if I can), and I’ve run into some trouble.
I understand how the algorithm works, but I’m having trouble getting the distance from the light to each fragment into a texture that I can do some register combiner trickery on to get it to work right.
I’m trying to use a vertex shader to compute this distance, and I think I know what I’m doing wrong, but I don’t know how to fix it.
In the VS, I subtract the vertex position from the light’s position, then get the distance of that vector, and then figure out where that distance is between the near and far planes of the light’s view frustum, on a linear scale, which then maps to an alpha-ramp texture (because that clamps it to 0, 1). The problem, however, is figuring out where each vertex will actually be.
The modelview matrix contains all the transformations that have been applied to the vertex, such as scales and rotations and translations and such, which should be applied before figuring out the distance from it to the light. But, it ALSO contains the transformations that the CAMERA applies to the modelview matrix, and this should NOT be used when trying to find the world-space location of the vertex.
I’m not really sure how I can separate the camera transformations out of the modelview matrix so that I can find this distance, so I’m asking here.
Any help would be GREATLY appreciated,
- Dylan Barrie