Question

I don't know if "bulged" is the correct term for it but it's all I can think of right now. I'm trying to map a 1-pixel wide (though technically every texture would have this problem) image along a triangle strip to simulate a laser. When it's completely uniform and square, this is how it looks:

enter image description here

And a wireframe of that:

enter image description here

But the problem arises when you slide the points inwards. The UV is now wrong, since it tries to map it as if that triangle were perfectly horizontal.

enter image description here

And the wireframe of that:

enter image description here

Right now I can't think of the term to even search for to work out how I'd map it. I want to map it so the stripe shrinks along with the strip itself, so not just frontal mapping. Any tips? I'm sure it's something very easy that I'm not able to think of right now.

Was it helpful?

Solution

You want a perspective correct texture mapping. What you see is an affine transformation, it doesn't take depth into account.

This link explains the problem and suggests how to solve it:

http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/

I did this myself but from what I recall you would pass a 3rd attribute in addition to the UV coordinates so you would have a homogeneous texture vector passed from the vertex shader to the fragment shader. In the fragment shader you would divide the UV by this 3rd argument and use that to sample the texture.

Sadly I don't have that code in front of me so this is the best I could do. But the page I linked should lead you to the solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top