Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
4 replies to this topic

#1 StasB   Members   -  Reputation: 144

Like
0Likes
Like

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:

Posted Image

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

Sponsor:

#2 clb   Members   -  Reputation: 1787

Like
0Likes
Like

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!

#3 StasB   Members   -  Reputation: 144

Like
0Likes
Like

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

#4 Brother Bob   Moderators   -  Reputation: 8570

Like
0Likes
Like

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.


#5 StasB   Members   -  Reputation: 144

Like
0Likes
Like

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.



PARTNERS