• 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 ntclark4 · Jul 09, 2018 at 05:15 PM · meshprocedural meshmesh vertices

Uneven lighting with shared vertices when building mesh

I'm in the process of creating a script that generates a mesh. The mesh will cover the top surface of several side-by-side cubes, and if the cube does not have a neighbor on a given side (right, left, forward, backward), it should get a rounded lip. I have the script up and running, and it works well. However, I have noticed that the rounded lip has uneven lighting.

To achieve the rounded lip, I'm creating 6 vertices. Example:

 Vector3[] verts = new Vector3[] { 
   new Vector3(0, 0, 0),
   new Vector3(0, 0, .1f),
   new Vector3(1, 0, .1f),
   new Vector3(1, 0, 0),
   new Vector3(0, -.1f, .1f),
   new Vector3(1, -.1f, .1f)
 };

And then using these shared vertices, I create two quads.

 int[] tris = new int[] {
   0, 1, 2, 2, 3, 0,
   1, 4, 5, 5, 2, 1
 };

When I build the mesh, everything is fine except that the lighting is uneven on either end of the rounded edge. Here are some screenshots of what's happening (these are side-by-side rounded lips that were created in the mesh).

alt text alt text

ss-001.png (180.7 kB)
ss-002.png (68.6 kB)
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 ntclark4 · Jul 09, 2018 at 05:20 PM 0
Share

alt text alt text

ss-003.png (133.8 kB)
ss-004.png (296.7 kB)

1 Reply

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

Answer by ntclark4 · Jul 10, 2018 at 08:18 PM

After spending more time looking into this issue, I figured out the problem was with the normals. At either end, the shared vertices on the edge weren't perfectly between the top and bottom vertices. They were staggered toward the bottom or top. When they were side-by-side, each end reflected light differently.

I solved this by tracking where the edge vertices were in my mesh vertices array. Then I let Unity recalculate normals, and at the edge normals, I manually recalculated with (pseudo code):

 edgeNormal = (topNormal + bottomNormal) * .5f;
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

98 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

Related Questions

Perlin Resources system 1 Answer

Simple plane generation 1 Answer

Weird bounce on collision with perfectly aligned (generated) meshes for fast object 3 Answers

How to identify mesh faces 2 Answers

How to generate a track / path mesh using waypoints,How do I generate a track / path mesh using waypoints 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