I need to project some textures to simulate sprite shadows but I can't wrap my head around how it's done in OpenGL. From what I understand, for each vertex of the projection surface, I need to calculate the coordinates on the projected texture and let OpenGL interpolate them automatically. This doesn't quite make sense to me because the interpolated function isn't even linear since it's basically a perspective projection. Pic related:
Perspective projection IS linear, after all, it is representible by a 4x4 matrix!
But note that the homogeneous/perspective divide by W is not a linear operation, but since that's done inside the GPU per-pixel, it's ok.
To do projective texturing, project the world space position of the vertex using the projection matrix of the projector and pass the projected point out as a varying vector. In pixel shader, sample the texture using the projected coordinates as the UV coordinates for the sampler.
You always, either directly or implicitly, work in three-dimensional homogeneous space. That is why all coordinates, even texture coordinates, are four dimensional. In three-dimensional homogeneous space, your texture coordinates as well as the interpolation are linear. The non-linearity comes from the division, that is correct, but the division happens after interpolation.
Edited by Brother Bob, 10 October 2012 - 10:44 AM.