Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Snakeruler · Jun 07, 2014 at 05:49 PM · texturemeshrenderervoxel

My voxel terrain is being rendered stretched in some places, but not in others. Why is this and how can it be fixed?

I am working on a voxel terrain generation, and for some reason, some of the textures appear stretched randomly, and I don't know how to go about fixing it. This is the problem:

alt text

As you can see, some blocks (most blocks) appear textured correctly and fine, however some are completely stretched like this. I'm generating the vertices etc, and then having them rendered, so only the faces visible are rendered. The textures are being read from a UV texture. Here is the code I'm working with:

 public virtual void BuildFace(byte brick, Vector3 corner, Vector3 up, Vector3 right, bool reversed, List<Vector3> verts, List<Vector2> uvs, List<int> tris)
     {
         int index = verts.Count;
         
         verts.Add (corner);
         verts.Add (corner + up);
         verts.Add (corner + up + right);
         verts.Add (corner + right);
         
         Vector2 uvWidth = new Vector2(0.25f, 0.25f);
         Vector2 uvCorner = new Vector2(0.00f, 0.75f);
         
         uvCorner.x += (float)(brick - 1) / 4;
         
         uvs.Add(uvCorner);
         uvs.Add(new Vector2(uvCorner.x, uvCorner.y + uvWidth.y));
         uvs.Add(new Vector2(uvCorner.x + uvWidth.x, uvCorner.y + uvWidth.y));
         uvs.Add(new Vector2(uvCorner.x + uvWidth.x, uvCorner.y));
         
         if (reversed)
         {
             tris.Add(index + 0);
             tris.Add(index + 1);
             tris.Add(index + 2);
             tris.Add(index + 2);
             tris.Add(index + 3);
             tris.Add(index + 0);
         }
         else
         {
             tris.Add(index + 1);
             tris.Add(index + 0);
             tris.Add(index + 2);
             tris.Add(index + 3);
             tris.Add(index + 2);
             tris.Add(index + 0);
         }
         
     }


The Mesh generator is as follows:

 public virtual void CreateVisualMesh(){
         visualMesh = new Mesh ();
         List<Vector3> verts = new List<Vector3>();
         List<Vector2> uvs = new List<Vector2> ();
         List<int> tris = new List<int> ();
         for(int x = 0; x < width; x++)
         {
             for(int y = 0; y < height; y++)
             {
                 for(int z = 0; z < width; z++)
                 {
                     if(map[x, y, z] == 0) continue;
                     
                     byte brick = map[x,y,x];
                     //Left wall
                     if(IsTransparent(x-1, y, z))
                         BuildFace (brick, new Vector3(x,y,z), Vector3.up, Vector3.forward, false, verts, uvs, tris);
                     //Right wall
                     if(IsTransparent(x+1, y, z))
                         BuildFace (brick, new Vector3(x+1,y,z), Vector3.up, Vector3.forward, true, verts, uvs, tris);
                     //Bottom wall
                     if(IsTransparent(x, y-1, z))
                         BuildFace (brick, new Vector3(x,y,z), Vector3.forward, Vector3.right, false, verts, uvs, tris);
                     //Top wall
                     if(IsTransparent(x, y+1, z))
                         BuildFace (brick, new Vector3(x,y+1,z), Vector3.forward, Vector3.right, true, verts, uvs, tris);
                     //Back wall
                     if(IsTransparent (x, y, z-1))
                         BuildFace (brick, new Vector3(x,y,z), Vector3.up, Vector3.right, true, verts, uvs, tris);
                     //Front wall
                     if(IsTransparent(x, y, z+1))
                         BuildFace (brick, new Vector3(x,y,z+1), Vector3.up, Vector3.right, false, verts, uvs, tris);
                 }
             }
         }
         visualMesh.vertices = verts.ToArray ();
         visualMesh.uv = uvs.ToArray ();
         visualMesh.triangles = tris.ToArray ();
         visualMesh.RecalculateBounds ();
         visualMesh.RecalculateNormals ();
 
         meshFilter.mesh = visualMesh;
         meshCollider.sharedMesh = visualMesh;
     }

I'm very confused and don't know how to fix this. If anyone could please offer some advice, I'd be very grateful! Thanks a lot in advance :)

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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Textures do not render in not so long distances,Textures do not render in not log distances 0 Answers

How do I texture this voxel cube? 1 Answer

Voxel texturing with single texture instead of texturesheet? 0 Answers

Mesh renderer with three submesh textures - only one renders properly, others are solid colors 1 Answer

UV Map, change texture color (lighter/darker) 1 Answer


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