Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
This question was closed Jan 31 at 04:48 PM by weltraumimport for the following reason:

Other

avatar image
0
Question by weltraumimport · Jan 20 at 09:49 AM · normalsmesh verticesgeneratednormalize

Unity generated mesh average normals on seperate vertices on same position/ smooth shade generated mesh

I have been following this tutorial from catlikecoding on a mesh generator and currently have this result. alt text

I'm a beginner at all of this but i thought it would automatically smooth shade if i use RecalculateNormals() but i'm guessing it doesn't work well because it's all seperate vertices.

Would it make sense to create a seperate list of shared vertices and somehow find the normals per vertice cluster and average them on all? I can't find a good way to approach that problem, so any hint would help greatly!

Here is what i have so far on the mesh generation

 [NonSerialized] List<Vector3> vertices;
 [NonSerialized] List<int> triangles;
 [NonSerialized] List<Vector3> normals;
 
 void Awake () {
     GetComponent<MeshFilter>().mesh = hexMesh = new Mesh();
     hexMesh.name = "Hex Mesh";
 }
 
 public void Clear () {
     hexMesh.Clear();
     vertices = ListPool<Vector3>.Get();
     triangles = ListPool<int>.Get();
     normals = ListPool<Vector3>.Get();
 }
 
 public void Apply () {
     hexMesh.SetVertices(vertices);
     ListPool<Vector3>.Add(vertices);    
     hexMesh.SetTriangles(triangles, 0);
     hexMesh.SetNormals(normals);
     ListPool<int>.Add(triangles);
     ListPool<Vector3>.Add(normals);
     hexMesh.RecalculateNormals();
 }
 
 public void AddTriangle (Vector3 v1, Vector3 v2, Vector3 v3) {
     int vertexIndex = vertices.Count;
     vertices.Add(HexMetrics.Perturb(v1));
     vertices.Add(HexMetrics.Perturb(v2));
     vertices.Add(HexMetrics.Perturb(v3));
     triangles.Add(vertexIndex);
     triangles.Add(vertexIndex + 1);
     triangles.Add(vertexIndex + 2);
 }
 
 public void AddQuad (Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4) {
     int vertexIndex = vertices.Count;
     vertices.Add(HexMetrics.Perturb(v1));
     vertices.Add(HexMetrics.Perturb(v2));
     vertices.Add(HexMetrics.Perturb(v3));
     vertices.Add(HexMetrics.Perturb(v4));
     triangles.Add(vertexIndex);
     triangles.Add(vertexIndex + 2);
     triangles.Add(vertexIndex + 1);
     triangles.Add(vertexIndex + 1);
     triangles.Add(vertexIndex + 2);
     triangles.Add(vertexIndex + 3);
 }


flatshaded.jpg (143.9 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

1 Reply

  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 20 at 11:43 AM

Of course this won't work. As you said yourself, they are seperate vertices. Why should Unity assume that two vertices which share the same position to be exactly the same in regards of normals? Also in order to do generate smooth normals one has to first figure out which vertices actually share the same position.

Apart from that, why do you generate an empty normals list which you assign to your mesh when you're currently using RecalculateNormals?


Anyways, if you want smooth normals between your disconnected faces, you have to calculate them yourself. So you have to determine which vertices belong logically together, calculate the face normal for each of the faces that meet at that point and just calculate the arithmetic mean between those normals. That's the normal that all of the vertices at that point would get.

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

Follow this Question

Answers Answers and Comments

133 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 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

How to identify mesh faces 2 Answers

Importing from Blender causes tangent/normal errors 0 Answers

How to get the right equation of and edge normal in motion? 1 Answer

Pointcast? - Raycast Point X from same Point X 0 Answers

Vector3.normalize not behaving as expected? 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