View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Projecting Textures

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1StasB  Members

Posted 10 October 2012 - 05:03 AM

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:

I'll be glad if someone could explain. Thanks. =)

### #2clb  Members

Posted 10 October 2012 - 05:20 AM

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.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #3StasB  Members

Posted 10 October 2012 - 10:12 AM

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

### #4Brother Bob  Moderators

Posted 10 October 2012 - 10:43 AM

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.

### #5StasB  Members

Posted 10 October 2012 - 11:47 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.