Original Post
I am working on code for rendering a procedural road. A particular segment of a road is a quad, but its a quad that might have no parallel edges. This quad in reality contains many sub triangles because the road is a decal placed onto the terrain ( So these sub triangles are the clipped terrain polys ). So I need to calculate the UVs for each vert within this road segment and its giving me a lot of trouble. I tried dividing the quad into two triangles. Then for each vert I determine which triangle it is in and then calculate its barycentric coordinates, which are used to determin the UVs. The problem is that there is no smooth transition between the texture "alignment" between the two triangle halves of the quad. Image the top two X(s) are also connected. Then the result I'm getting is the lower triangle has a perfectly aligned / unstretched texture ( and it shouldnt' be ), and the upper triangle has the texture stretched quite extreme.
X
X |
|\ |
| \ |
| \ |
| \|
X----X
I also tried dividing the quad into 4 triangles like..
X----X
|\ /|
| \/ |
| /\ |
|/ \|
X----X
With the idea that at least then all the triangles are sharing one point ( and the correct UV for that point ). With this approach, at the center point the texture does seem to roughly match up between the triangles, but along the rest of the edges there is a "break" in texture scale. It seems like using barycentric coords just isn't going to work unless there is a way for it to take all 4 points into account... Keep in mind, I cannot simply calculate the UVs of the corner points of the quad (I already have). I need to calculate the correct UV(s) for every captured/clipped terrain vert contained within this quad.