Advertisement

Spline based road geometry UV mapping

Started by August 31, 2017 09:23 AM
6 comments, last by ErnieDingo 7 years, 5 months ago

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

road.thumb.png.a7952934db7bd08a042d8380fb4dc891.png

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

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.

Advertisement

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

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.

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

road.thumb.png.a7952934db7bd08a042d8380fb4dc891.png

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. 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

I am accumulating u:


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

 

Advertisement
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..

roadpic1.pngroadpic2.png

 

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 

roadpic3.png

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

 

roadpic4.png

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

This topic is closed to new replies.

Advertisement