• 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
2
Question by Jihoon Lee · May 16, 2013 at 02:29 AM · meshlightingproceduralnormalsseams

[SOLVED]Procedural generated side by side cubes without 'seams'?

(SOLUTION IS AT BOTTOM!)

I apologize if this has been answered somewhere else, but I have been searching for a few days now and can't seem to find an answer to my problem. Here is my code and a picture of the results, and at the bottom I outline my issue I am trying to solve/wanting to achieve.

I am procedurally generating cubes with the code below:

 private GameObject CreateBoxes(Vector3 startPos)
     {
         Mesh myMesh = new Mesh();
 
         Vector3 topLeftFront = startPos;
         Vector3 topRightFront = new Vector3(startPos.x+1, startPos.y, startPos.z);
         Vector3 bottomLeftFront = new Vector3(startPos.x, startPos.y+1, startPos.z);
         Vector3 bottomRightFront = new Vector3(startPos.x+1, startPos.y+1, startPos.z);    
         
         Vector3 topLeftBack = new Vector3(startPos.x, startPos.y, startPos.z+1);
         Vector3 topRightBack = new Vector3(startPos.x+1, startPos.y, startPos.z+1);
         Vector3 bottomLeftBack = new Vector3(startPos.x, startPos.y+1, startPos.z+1);
         Vector3 bottomRightBack = new Vector3(startPos.x+1, startPos.y+1, startPos.z+1);
         
         //Assigning vertices to the mesh
         Vector3[] verts = new Vector3[8] {topLeftFront, topRightFront, topLeftBack, topRightBack,
                             bottomLeftFront, bottomRightFront, bottomLeftBack, bottomRightBack};
         myMesh.vertices = verts;
         
         //Assigning UV coordinates (Texture coordinates)
         myMesh.uv = tempChunk.Uvs;
         
         //Assigning triangles for faces from chunk tri array
         myMesh.triangles = tempChunk.Tris;
         
         //Calculating normals, adding Mesh to object, adding texture to mesh, and collider
         myMesh.RecalculateNormals();
         
         GameObject myBox = new GameObject("Block");
         myBox.tag = "Block";
         myBox.AddComponent("MeshFilter");
         myBox.AddComponent("MeshRenderer");
         myBox.GetComponent<MeshFilter>().mesh = myMesh;
         myBox.AddComponent("MeshCollider");
         myBox.renderer.sharedMaterial = new Material(Shader.Find("Diffuse"));
         return myBox;
     }

For the Triangles and UV's, it is here:

 private int[] tris = new int[36] {5, 1, 0, 0, 4, 5, 
                                       6, 4, 0, 0, 2, 6,
                                       7, 5, 4, 4, 6, 7,
                                       5, 7, 3, 3, 1, 5,
                                       3, 7, 6, 6, 2, 3,
                                       3, 2, 0, 0, 1, 3};
     
     private Vector2[] uvs = new Vector2[8] 
                            {new Vector2( 0, 0 ),
                             new Vector2( 1, 0 ),
                             new Vector2( 1, 1 ),
                             new Vector2( 0, 1 ),
                             new Vector2( 0, 0 ),
                             new Vector2( 1, 0 ),
                             new Vector2( 1, 1 ),
                             new Vector2( 0, 1 )};

Using a for loop with proper increments, I am resulting in this cube generation (Which is exactly what I want):

alt text

THE PROBLEM: I want to have the cubes instead of looking like seperate cubic objects, look like a smooth singular surface (even though they are still seperate.) I have tried sharing normals among some vertices, and sharing vertices alone, but nothing I do seems to work, they always have that cubic 'outline' on them with seams.

If anyone could shed some light on this for me, I'd greatly appreciate it. Thanks in advance, guys!

THE SOLUTION: Taking the knowledge from Loius, and Fattie's great advice and question/answer link in the comments, I stopped trying to fiddle with an 8 vertex cube and instead went to my original 24 vertex per cube setup. The cubes side by side this way appeared seamless and lit correctly.

What I took from it is, don't share vertices between faces on a shape. It seems like it gave me nothing but trouble. I hope this helps someone in the future who might have the same issue!

Comment
Add comment · Show 10
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 Fattie · May 16, 2013 at 06:54 AM 1
Share

you need to be able to control the normals to achieve what you want.

avatar image Loius · May 16, 2013 at 07:23 AM 2
Share

The normals need to match. A cube with flat-shaded sides has 6 sides * 4 vertices per side = 24 vertices. All those vertices visible in your screenshot should have Vector3.up as their normal.

avatar image Fattie · May 16, 2013 at 07:58 AM 1
Share

we shouldn't give away such mesh building secrets man :)

indeed Jihoon you must understand RecalculateNormals, which you would NOT use here

pls read the many questions about it on here.

http://answers.unity3d.com/questions/329116/do-we-need-to-call-recalculatenormals-if-normal-ve.html

Be sure to vote-up that answer with the thumb button. I need moar points

http://answers.unity3d.com/questions/336967/constructive-advice-needed-for-using-builtin-array.html

avatar image Fattie · May 16, 2013 at 08:30 AM 1
Share

"As this is a simple cube with all shared vertices"

you CAN NOT SHARE VERTICES. generally NEVER SHARE VERTICES when you are weaving mesh.

this is a highly misunderstood topic.

NEVER EVER EVER SHARE VERTICES.

that's clear now right?

carefully CAREFULLY read this LONG article that shows even advanced people are often stupid on this issue

http://answers.unity3d.com/questions/193695/in-unity-is-there-a-fast-way-to-find-nearby-triang.html

read all of these

http://answers.unity3d.com/questions/423569/meshvertices-is-too-small.html

http://answers.unity3d.com/questions/417483/is-there-a-way-to-assign-meshverticesi-directly.html

there are a vast number of long excellent answers on this topic if you would just search here

avatar image Fattie · May 16, 2013 at 08:32 AM 1
Share

what Loius meant is all the normals must point "upwards from that face"

got it ? so each face has six vertices and hence six normals.

got it ?

each of the six normals must point straight-upwards from that face.

this has actually been answered many many times here

Show more comments

2 Replies

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

Answer by Fattie · May 16, 2013 at 11:33 AM

Never share vertices when weaving mesh

articles on this

http://answers.unity3d.com/questions/193695/in-unity-is-there-a-fast-way-to-find-nearby-triang.html

http://answers.unity3d.com/questions/423569/meshvertices-is-too-small.html

http://answers.unity3d.com/questions/417483/is-there-a-way-to-assign-meshverticesi-directly.html

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
avatar image
0

Answer by mezzostatic · Jan 01, 2017 at 09:20 AM

Not 100 percent sure of this because i solved it a while back, i'm pretty sure however:

If you send mesh objects with different positions to the graphics card, unity's precision is not high enough and the actual vertex positions in the graphics cards, the seams, will not be the same. hence you will see seams inside the graphics card.

If you put all your cubes on 0,0,0 and instead change their vertex positions to the positions you want, and send them all to the graphics card, they will not contain seams.

AFAIK i solved the issue after some time and puzzling, perhaps waster 50 hours to solve it, becaues i was told that my problem was inside the game engine not the graphics card.

So... keep all cubes on zero zero zero, edit their vertex positions, rewrite all the vertices to the new positions you want the cubes to be in, there should be no mesh, please confirm, ive done it with terrain and the seams completely vanished.

Its a weird error inside Unity that no one else than me knows about because i am a lame coder who never managed to code a game but i know so much about everything.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Seam between meshes 1 Answer

Determine whether or not model is "inside out" 2 Answers

Trying to create a hard edged procedural torus mesh 2 Answers

Lighting induced seams 0 Answers

Seam on Procedural Mesh 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