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 Bunnybomb7670 · Aug 27, 2013 at 02:47 PM · meshissuenormals

Mesh Normal

So, i am working on a script what reads terrain data values and makes them into a mesh, i can do it fine with voxels, but when it comes to just pretty much printing the heightmap into a mesh, it has these weird " normal " issues, does this look right? is it actually the normals causing this? or could it be something else?

alt text

The flat parts are fine, its the slopes which seem to have normal issues.

Here is my script i am using :

 void renderExternalHeightmap()
     {
         Generator noise;
 
         RidgeNoise temperature = new RidgeNoise(83573);
 
         PinkNoise noiseMod = new PinkNoise(32562356);
 
         temperature.Lacunarity = 0.9f;
         temperature.Frequency = 0.01f;
         temperature.Offset = 1.2f; // sharpness
         temperature.OctaveCount = 8;
 
         noiseMod.Lacunarity = 0.9f;
         noiseMod.Frequency = 0.01f;
         noiseMod.Persistence = 1.2f; // sharpness
         noiseMod.OctaveCount = 8;
 
         noise = noiseMod;
 
 
         int X, Y, Z;
 
         X = BaseClass.WORLD_CHUNK_DIMENSION_X * BaseClass.WORLDCHUNK_LOADED_LIMIT_X;
         Y = BaseClass.WORLD_CHUNK_DIMENSION_Y * BaseClass.WORLDCHUNK_LOADED_LIMIT_Y;
         Z = BaseClass.WORLD_CHUNK_DIMENSION_Z * BaseClass.WORLDCHUNK_LOADED_LIMIT_Z;
 
         List<int> triangles = new List<int>();
 
         List<Vector3> vertices = new List<Vector3>();
 
         List<Vector2> uvs = new List<Vector2>();
 
         int index = 0; // index used for triangle work around
 
         for (int i = 0; i < 50; i++)
         {
             for (int j = 0; j < 1; j++)
             {
                 for (int k = 0; k < 50; k++)
                 {
 
 
                     vertices.Add(new Vector3(i - 0.5f, Mathf.FloorToInt(noise.GetValue(i - 0.5f, 0.5f, k + 0.5f) * temperature.GetValue(i - 0.5f, 0, k + 0.5f)), k + 0.5f));
                     vertices.Add(new Vector3(i + 0.5f, Mathf.FloorToInt(noise.GetValue(i + 0.5f, 0.5f, k + 0.5f) * temperature.GetValue(i + 0.5f, 0, k + 0.5f)), k + 0.5f));
                     vertices.Add(new Vector3(i + 0.5f, Mathf.FloorToInt(noise.GetValue(i + 0.5f, 0.5f, k - 0.5f) * temperature.GetValue(i + 0.5f, 0, k - 0.5f)), k - 0.5f));
                     vertices.Add(new Vector3(i - 0.5f, Mathf.FloorToInt(noise.GetValue(i - 0.5f, 0.5f, k - 0.5f) * temperature.GetValue(i - 0.5f, 0, k - 0.5f)), k - 0.5f));
 
                     triangles.Add(index + 0);
                     triangles.Add(index + 1);
                     triangles.Add(index + 2);
                     triangles.Add(index + 0);
                     triangles.Add(index + 2);
                     triangles.Add(index + 3);
 
                     index += 4;
 
                 }
             }
         }
 
         Mesh mesh = GetComponent<MeshFilter>().mesh;
 
         Vector4[] tangents = new Vector4[vertices.Count];
 
         for (int i = 0; i < vertices.Count; i++)
         {
             uvs.Add(new Vector2(vertices[i].x, vertices[i].z));
         }
 
         mesh.Clear();
 
         mesh.vertices = vertices.ToArray();
         mesh.triangles = triangles.ToArray();
         mesh.uv = uvs.ToArray();
         mesh.tangents = tangents;
 
         mesh.RecalculateNormals();
         mesh.Optimize();
 
     }


Comment
Add comment · Show 1
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 asdfghjkloi87654 · Oct 07, 2013 at 03:40 PM 0
Share

I have the same problem with marchingcubes

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DarkPixel · Oct 08, 2013 at 12:04 AM

First, I think some of your plane are not coplanar. I'm not 100% sure, if you can add a wireframe screenshot, it would help.

Second, If you check the documentation, RecalculateNormals use the shared vertices to calculate the normal. RecalculateNormals

In your case, each plane have 4 unique vertex. Even if the position is the same, you duplicate the vertex. So each vertices on the plane have the plane normal

I think what you want is a smooth shading. You should build all you vertex first, then build the face and reuse the vertices instead of creating unique vertex for each face.

And here's an algorithm to manually generate smooth normal: OpenGL Normal Smoothing

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

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

About merging meshes and their normals 2 Answers

Algorithm for automatic mesh creation 1 Answer

Any script to 'fix' normals/winding order? 3 Answers

Model faces arent showing up even though I reversed my normals. Anyone know what's wrong? 3 Answers

Seing through triangles in runtime edited mesh 0 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