Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by gonzalitosk8 · Aug 13, 2019 at 12:12 AM · procedural meshuv mappingtexturinguv coordinates

uv Tiling y error

edit Follow up question


hello community! I am having a problem coordinating the uv. I currently have this done, but it does not work as it should, it is something basic but, ALMOST, it meets the requirements. What I want is that the texture always keeps its "tiling Y" and is divided by the total distance between nodes ...

This is what I currently have for UV: Vector2[] uvs = new Vector2[road.verts.Count];

     for (int i = 0; i < road.verts.Count; i+=2) {    
         float total = i / (float)(road.verts.Count-1);
         float v = 1 - Mathf.Abs (2 * total - 1);
         uvs [i] = new Vector2 (0, v); 
         uvs [i + 1] = new Vector2 (1, v); 
     }
     m.uv = uvs; 

I leave a sample image alt text

roaddd.png (493.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Aug 13, 2019 at 01:26 AM

Your approach does not take the actual distance between the nodes into account. If that screenshot actually represents the result of the code you've posted, it looks like your actually used texture is not a tiled texture but a texture with about 24 center marks, is that correct?


Usually for procedural roads you want to use a tilable texture that only contains a single segment of the road. So simply one space and one line so when placing the same texture after the first it continues the road pattern perfectly.


When you have a tilable texture (which usually would be about a square texture) you should make sure the texture's wrap mode is set to repeat. This way UV coordinates outside the range of 0-1 are repeated properly. So for example if the first V coordinate is "0" and the next one is set to "5" that single segment will have 5 copies of the whole texture. Now it's only a matter of actually calculating the distance between two nodes and use the accumulated distance as V coordinate. Usually you want to scale that V coordinate additionally by your road width and maybe also by a "correction factor" in case the texture isn't perfectly square or you actually want to stretch / squish the texture along the road.


You would simply do that like this:

// Note I assume the for loop from your other question where you iterated through your nodes list:

 float vScale = 1f;
 
 int count = nodes.Count;
 List<Vector2> uvs = new List<Vector2>(count * 2);
 Vector3 lastPoint = new Vector3();
 float currentV = 0;
 for (int i = 0; i < count; i++)
 {
     // your vertex and normal generation code
     
     if (i == 0)
     {
         uvs.Add(new Vertex(0, 0));
         uvs.Add(new Vertex(0, 1));
         lastPoint = nodes[i];
     }
     else
     {
         Vector3 p = nodes[i];
         Vector3 dist = p - lastPoint;
         currentV += dist.magnitude * 2 * width * vScale;
         uvs.Add(new Vertex(currentV, 0));
         uvs.Add(new Vertex(currentV, 1));
         lastPoint = p;
     }
 }

This should generate UV coordinates so that the center of the road roughly has the same distance mapping everywhere. With a vScale of 1 we essentially map 1 unity unit onto the whole texture. If you want to actually use your "~24" segment texture, you can simply set your vScale to 1f/24f. This assumes that "width" is half the road width like you used it in your other question.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 13, 2019 at 01:56 AM 0
Share

Note: If that's not the behaviour you want, you should have been more precise when you said:

it does not work as it should

and

AL$$anonymous$$OST, it meets the requirements

We don't know exactly how it "should" work and what your "requirements" are ^^. Note since the actual edges at the corners are slanted when you have any kind of direction change the texture is sheared, This might be irrelevant depending on the details on the texture. However if a proper parallel projection is wanted you essentially loose the continuity of the texture across the connecting edges. Though most the times this is is less important. Though calculating the proper UVs for a parallel projected texture is slightly more complicated since you need different UVs for the two corners of an edge. This also means you need a UV seam at each connecting edge, so you would need to duplicate the vertices at each connection.


Though as long as you don't have too many larger details on the road texture and the road doesn't have too narrow corners this shouldn't be an issue.

avatar image Bunny83 · Aug 13, 2019 at 01:59 AM 0
Share

Oh and just as a remainder: Unity does support other mesh topologies than triangles. Since your street always consists of quads you could actually model your road out of quads. So you would only need 4 indices ins$$anonymous$$d of 6 for one segment.

avatar image
0

Answer by gonzalitosk8 · Aug 13, 2019 at 02:57 AM

Thanks for the prompt response, I am using unity 5, applying your code, it didn't work ... update it and it looks similar to how I currently have italt text

And yes, I use a special texture for this case, which I try at 3ds max and it looks great!


roaddd.png (465.5 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

111 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Procedural Mesh UV problem 0 Answers

need guide in uv texture 0 Answers

Update a texture at runtime using UV 0 Answers

SkinnedMeshRenderer UV scale problem. 0 Answers

UV mapping on procedural mesh isn't pixel perfect 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges