Sign in to follow this  
nullsquared

How would I go about stretching a quad-ish area in a texture over a whole quad?

Recommended Posts

Part 1:

Say that I have a texture like so: (obviously the colours won't be like that, but the diagram is coloured that way for easy understanding) I also have the 4 vertices of that "inner" quad in world space. Now, how would I go about "stretching" the inner quad's contents, as found in that texture, onto a whole quad?

Part 2:

The bad part is that the "inner" quad won't necessarily be fully inside the texture, as so: So, how would I go about getting "what I have" to stretch correctly? I don't really mind what happens to the part of the quad which is off the screen - it can be garbage, a single colour, anything, really. But I'm looking that for the part of the quad that IS seen, that part of the real quad I'm trying to texture is correct... Ideas? Thanks in advance!

Share this post


Link to post
Share on other sites
Hm... Anyone have any ideas?

I thought of getting the positions of the vertices in screen space, then using them as texture coordinates, but that doesn't work quite right. Especially when part of the quad is off-screen, and part is on-screen.

Share this post


Link to post
Share on other sites
Split the quad against the screen (i.e. clip it), and recalculate the screen coordinates to map it to.
e.g. in the example you have there, first split the source quad:
source quad = vertices s0, s1, s2, s3
Say it splits on edges s0-s1 and s2-s3, the new vertices created (v0 on edge s0-s1 and v1 on edge s2-s3) will be some fraction along the vectors of their edges. You take those fractions and use them to interpolate along the corrisponding edges of the target quad.
Say the fraction along s0-s1 that v0 occurs is f0 (i.e. f0 = (v0-s0)/(s1-s0)), and s0-s1 maps to the target edge t0-t1 then the new target coordinate is f0*(t1-t0).
If during the clipping it was s0 that fell outside the clip region then you replace t0 with the new coordinate, otherwise replace t1.
Hope this makes sense!

/edit, corrected silly math mistake.

[Edited by - bluntman on July 14, 2007 9:57:58 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this