Projecting Textures

Started by
3 comments, last by StasB 11 years, 6 months ago
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:

TFQ3F.png

I'll be glad if someone could explain. Thanks. =)
Advertisement
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.
I don't understand.
Getting the texture coordinate for a world vertex involves a division by the distance from the projector's near plane. That's a non-linear function. =S
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.
I didn't know texture coordinates had Z and W components. I think I get it now. I guess I should do some more reading about how OpenGL works. Thanks, guys.

This topic is closed to new replies.

Advertisement