How would I go about stretching a quad-ish area in a texture over a whole quad?
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.
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.
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement