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 mikeInside · May 13, 2015 at 10:57 AM · lightingnormalsprocedural mesh

Procedural-mesh normals reversed, but only when lit from the left

I am creating a procedural cylinder mesh using code from the Jayelinda's Web: Modelling by numbers tutorial, and ending up with some odd results.

The images below show the default unity cylinder side-by-side with the procedural mesh.

As you can see, when lit from the right both objects more or less look the same, however when lit from the left, the procedural mesh has normals reversed, i.e. what should be protruding is instead recessed and vice-versa.

When lit from above, the procedural mesh still looks like it is being lit from the side.

alt text

Rotating the object does not change what the lighting looks like, it seems purely dependent on the direction of the light.

Below is the code where most of the action happens, BuildRing is called a few times at increasing heights in order to create a cylinder.

 public static void BuildRing (MeshBuilder meshBuilder, int segmentCount, 
     Vector3 centre, float radius, 
     float v, bool buildTriangles)
 {
     float angleInc = (Mathf.PI * 2.0f) / segmentCount;
     
     for (int i = 0; i <= segmentCount; i++)
     {
         float angle = angleInc * i;
         
         Vector3 unitPosition = Vector3.zero;
         unitPosition.x = Mathf.Cos (angle);
         unitPosition.z = Mathf.Sin (angle);
         
         meshBuilder.Vertices.Add (centre + unitPosition * radius);
         meshBuilder.Normals.Add (unitPosition);
         meshBuilder.UVs.Add (new Vector2 ((float)i / segmentCount, v));
         
         if (i > 0 && buildTriangles)
         {
             int baseIndex = meshBuilder.Vertices.Count - 1;
             
             int vertsPerRow = segmentCount + 1;
 
             int index0 = baseIndex;
             int index1 = baseIndex - 1;
             int index2 = baseIndex - vertsPerRow;
             int index3 = baseIndex - vertsPerRow - 1;
             
             meshBuilder.AddTriangle (index0, index2, index1);
             meshBuilder.AddTriangle (index2, index3, index1);
         }
     }
 }

Do you have any ideas what I might be doing wrong? I'm at a total loss, appreciate any advice!

meshlightingexamples.png (255.1 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

· Add your reply
  • Sort: 
avatar image
0

Answer by mikeInside · Jun 23, 2015 at 05:43 PM

Mesh needs tangents. Details here: http://forum.unity3d.com/threads/procedural-mesh-normals-reversed-but-only-when-lit-from-the-left.325601/

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

2 People are following this question.

avatar image avatar image

Related Questions

Procedural mesh generation - problem with normals. 2 Answers

Are normals from Mesh.RecalculateNormals() normalized? 1 Answer

What's wrong with this simple mesh manipulation? 1 Answer

HDRP - The closer I get to a procedurally generated object the brigther everything in the scene becomes 0 Answers

Normals on procedural 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