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
4
Question by Jeremy 6 · Oct 29, 2010 at 07:17 PM · proceduralverticesnormalstrianglescalculate

How do I manually calculate Normals for my Meshes?

I'm creating my own terrain tiling system for the iPhone so I don't have "SetNeighbours" or anything like that. I'm working in raw meshes. As such the normals near the edge of my meshes are screwed up.

Any way I can set the normals for my triangles manually?

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 MountDoomTeam · Feb 10, 2013 at 11:20 PM 0
Share

I am working on this at the moment, if anyone has a solution to the edges please squawk about them now. also, if you have procedural mesh, you can use the procedural function to calculate the normals uniformly rather than using the actual mesh. I don't know how to do that exactly also!

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fherbst · Oct 29, 2010 at 07:25 PM

Something like that should do it if you have a script-made mesh and want to recalculate the normals.

EDIT: Yes, you can edit the normals by hand, too:

function Update () { var mesh : Mesh = GetComponent(MeshFilter).mesh; var normals : Vector3[] = mesh.normals;

 // do custom normal calculations
 // (e.g. looking at the surrounding faces and their normals
 // and interpolating them - thats the vertex normal)

 for (var i = 0; i < normals.Length; i++)
     normals[i] = myCustomRecalculatedNormal;

 mesh.normals = normals;

}

I hope that helps - if you need help for the calculation itself, just comment; I will see what I can do (you could also take a look at this first - does exactly what you want, I think).

Comment
Add comment · Show 1 · 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 Jeremy 6 · Oct 29, 2010 at 09:00 PM 0
Share

"Imported meshes sometimes don't share all vertices. For example a vertex at a uv seam will be split into two vertices. Thus the RecalculateNormals function will create normals that are not smooth at the uv seam."

This is the exact problem I'm running into. $$anonymous$$y terrain tiles are separate meshes so the vertices on the edges of the tiles don't share the same meshes. Hence "manually" updating normals.

I can retrieve the common vertices.. can I hand set the normals?

avatar image
1

Answer by MountDoomTeam · Feb 11, 2013 at 05:36 AM

edit

Best way i found using procedural terrains, just get 2 points near the vertex using the same info you had to get the vertex height, it ll give you 3 points to cross product normal height and smooth shadows also. if you use 4 points around the vertex it may give you better results on peaks normals. works with hi res terrain height data. seamless. better quality normals.

there are various ways to calculate normals on the edges of the tiles. The question is, which one is easier, and which one is faster.

You can use the height map/procedural data to sample the points around the edge vertices and construct a normal from that. slow method.

You can use a separate mesh that is not visible and that is larger so that the visible tiles, and then you apply all the vertex/normal calculations to the hidden tile, and then copy the normals and the vertices from the hidden tile to the visible ones. I expect this is the slowest method.

The fastest by far method, I'm not sure how accurate it is I haven't tried it it should be hundred percent accurate, is that you go through the vertices of edges, and you will find that for a 10 x 10 plane, vertex 1 is on the same point as vertex 91 for the plane next to it, because vertices 0 to 10 is the south edge, and 90 to 100 is the North edge, and all the East ones all finish with 0, and the West ones all finish with 9. So when you have to vertices on the same points you can add the normal of both and divide by 2 to average it and get the actual normal of that point which I think should be correct. it should be true for the edges and corners.

What you can also do is rotate each tile by 90 so that all the edge vertices correspond one-to-one with each other in the array indices, and generate the height map data using transform point.

...

also go through edge vertices' normals for adjoining mesh and average normals that share same vertex position.

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
1

Answer by Fehr · Dec 20, 2019 at 10:52 AM

Thought this thread is now nearly ten years old, I recently had to solve this problem and wanted to share an amazing explanation and solution by Sebastian Lague on his YouTube channel as part of his procedural land mass generation tutorial:

https://www.youtube.com/watch?v=NpeYTcS7n-M&list=PLFt_AvWsXl0eBW2EiBtl_sxmDtSgZBxB3∈dex=12

Hopefully this helps someone in the future who needs to solve the same problem one day.

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 Jessy · Oct 29, 2010 at 10:20 PM

Triangles don't have normals. Vertices do.

http://unity3d.com/support/documentation/ScriptReference/Mesh-normals.html

Comment
Add comment · Show 3 · 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 Jeremy 6 · Oct 30, 2010 at 07:48 PM 1
Share

Strictly speaking triangles have normals because a point in space cannot have a face (unlike a plane). However, in this context, the normals of vertices is the average of the triangle normals that share the vertex.

Thanks for the info though. Now I just have to figure out how to do the normal calculation myself.

avatar image Jessy · Oct 30, 2010 at 08:21 PM 0
Share

No. The normal of the triangle itself isn't used for anything, except mesh colliders, which you're not talking about. There's no reason that the normal of a vertex has to have anything to do with the triangles that surround it; it just makes sense for realistic lighting, which is their intended purpose.

avatar image MountDoomTeam · May 05, 2013 at 07:19 PM 0
Share

in unity vertices have their own normals. in some code, each vertex of a triangle has the same normal for all 3 points of the triangle.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Holes in procedural mesh 0 Answers

Problem drawing a mesh with Graphics.DrawMeshNow 1 Answer

How to make sure two meshes have the same vertex count 0 Answers

Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer

Procedural cube code 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