# 3D Spline based road geometry UV mapping

## Recommended Posts

Hi,

Im working on a procedural road system and I use bezier splines to genereate the mesh ( tri strip ) but I have a problem with calculating proper uv coordinates. The texture looks distorted on curved segments like on the attached picture

When calculating uv i first init them to ( 0.0f, 0.0f ) or ( 0.0f, 1.0f ) for each vertex, and then add the distance between current and previous point on a curve to the previous vert U coord ( V stays the same ). Something like this:

float dist = ( pos - prevPos ).Magnitude();
float lenScale = roadWidth / m_uvStretch;

dist /= lenScale;

verts[ currVertIndex ].uv.X = outVerts[ currVertIndex - 1 ].uv.X + dist;

What am I missing?

Thanks

##### Share on other sites

The lengths of your inner and outer curves are different so each curve will cause your inner and outer u coordinates to drift apart. Compute your u along the center line instead.

##### Share on other sites

I believe I am doing that: pos and prevPos in my code are the points on the spline ( center of the road ).

##### Share on other sites

This may be a manifestation of the "how to UV map a trapezoid" problem... The simplest solution is to further tesselate your faces (i.e. use more vertices/triangles), such as by adding a line of verts down the center of the road too.

##### Share on other sites
On 31/08/2017 at 7:23 PM, quaikohc said:

Hi,

Im working on a procedural road system and I use bezier splines to genereate the mesh ( tri strip ) but I have a problem with calculating proper uv coordinates. The texture looks distorted on curved segments like on the attached picture

When calculating uv i first init them to ( 0.0f, 0.0f ) or ( 0.0f, 1.0f ) for each vertex, and then add the distance between current and previous point on a curve to the previous vert U coord ( V stays the same ). Something like this:

float dist = ( pos - prevPos ).Magnitude();
float lenScale = roadWidth / m_uvStretch;

dist /= lenScale;

verts[ currVertIndex ].uv.X = outVerts[ currVertIndex - 1 ].uv.X + dist;

What am I missing?

Thanks

You not only need to calculate from the middle you should also accumulate your u value so you don't restart your u value each section. Your white line down the middle indicates you are restarting.

##### Share on other sites

I am accumulating u:

verts[ currVertIndex ].uv.X = outVerts[ currVertIndex - 1 ].uv.X + dist;

##### Share on other sites
12 hours ago, quaikohc said:

I am accumulating u:


verts[ currVertIndex ].uv.X = outVerts[ currVertIndex - 1 ].uv.X + dist; 

I would check that its accumulating correctly.

Side by side, I just quickly chucked in a road texture to show..

My corners can have a higher def spline, I just have no such need of high detail due to the nature of my game, but here is an example of what you are trying to achieve.  The UV is only updated along the run of the road.  I calculate the U component on each row, hence you

if I up my spline sample set I get a nice smoother component like hodge mentioned.

## Create an account

Register a new account

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631765
• Total Posts
3002213
×