Arc mesh for correct texture coordinates interpolation

Hello!
In our project programmatically generated mesh consists of circular arcs and straight segments.

Road markings are applyed in shader: for each vertex two float values are assigned: the number of lanes and the distance from the begining of the road.

When arc has a lot enougth number of vertices (and trianlges) everything is fine

But I have some problem when arc has a low count of triangles.

On that image each point is marked with (lane_number, distance). Lane is interpolated correctly. The problem is with distance interpolation in center triangle. I suppose that it’s also true for texture application.

So how to split an arc in triangles to get rid of that problem? Does it have a solution?

1 Like

Sometimes it can be better to add a center point and split the ‘quad’ four ways instead of two. It evens out the error.

Excuse my poor drawing:

Thank you for the reply!
But your suggestion won’t help:the center (yellow) point will have coordinates (1.5, 1). So y coordinate will be the same.

X is interpolated correctly, but not y.

@dendrit said: Thank you for the reply! But your suggestion won't help:the center (yellow) point will have coordinates (1.5, 1). So y coordinate will be the same.

X is interpolated correctly, but not y.

The issue is that when you split it two ways the shape is lopsided. One triangle is huge and the other is thin and tiny. If you split it into four then everything is even.

Did you try it or are you just guessing? Also, I’m not sure where you are getting 1.5, 1 as the center. Is that what you think the texture coordinate would be? (because that’s not right, I think, since it should be the center.)

I have implemented you solution. Here is mesh and marking

It looks better than earlier having the same numer of vertices and 1 more triangle.

Is there something else I can do?

Well, now your problem is down to a more basic problem. If you painted lines on a real road with one vehicle you’d have similar problems where around turns the stripes would stretch and compress depending on how close to the inside curve they are. That’s not really a mesh problem… it’s a ‘geometry’ problem in the mathematical sense.

There is no solution to this problem without tracking the distance of each striped line separately since one striped line needs to be shorter than the other but the stripes need to stay the same size.

Given your approach, your current version is accurate as you can get, really.

There may be some solution where you can pick better texture coordinates for the inside and outside curves, making sure that they end on an even distance so as not to mess up the straight parts. For example, if you know five stripes will fit in the outside and three stripes will fit in the inside then you can stretch them differently as long as they end in the same place relative to the end of a stripe. Not sure I’m making sense. You might have to fudge the length of stripes to make them line up but overall the error would be slight and certainly better than what you are doing now. Possibly tricky, though.

Thank you for detailed explanation.