Jump to content
  • Advertisement
Sign in to follow this  
quaikohc

3D Spline based road geometry UV mapping

This topic is 438 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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

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. 

Share this post


Link to post
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..

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!