• 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 /
  • Help Room /
avatar image
Question by OswaldP · Feb 01, 2016 at 04:42 PM · meshlightingprocedural meshfaces

Procedurally generated mesh having some faces that don't receive light

Hi,

I'm having some troubles using lights on a procedurally generated mesh. It seems that depending on the point light position, some faces will not receive light, even if they are fully exposed.

T$$anonymous$$s is how I generate the mesh :

 using UnityEngine;
 using System.Collections;
 
 public class MeshGen : MonoBehaviour {
 
     public GameObject obj;
 
     void Start () {
         generate();
     }
 
     void generate(){
         Vector3 pt0 = new Vector3(0,0,0);
         Vector3 pt1 = new Vector3(0,1,0);
         Vector3 pt2 = new Vector3(1,1,0);
         Vector3 cross = GetNormal (pt0, pt1, pt2);
         Vector3 pt3 = pt0+cross;
         Vector3 pt4 = pt1+cross;
         Vector3 pt5 = pt2+cross;
         Vector3[] newVertices = {pt2, pt1, pt0, 
             pt3, pt4, pt5, 
             pt0, pt1, pt3, 
             pt1, pt4, pt3, 
             pt0, pt3, pt2, 
             pt2, pt3, pt5,
             pt1, pt2, pt4, 
             pt2, pt5, pt4};
         int[] newTriangles = {0,1,2,
             3,4,5,
             6,7,8,
             9,10,11,
             12,13,14,
             15,16,17,
             18,19,20,
             21,22,23
         };
         GameObject myFace = (GameObject) Instantiate(obj, new Vector3(0,0,0), Quaternion.identity);
         Mesh mesh = new Mesh();
         myFace.GetComponent<MeshFilter>().mesh = mesh;
         mesh.vertices = newVertices;
             Vector3[] vertices = mesh.vertices;
         Vector2[] uvs = new Vector2[vertices.Length];
         for (int i=0; i < uvs.Length; i++) {
             uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
         }
         mesh.uv = uvs;
         mesh.triangles = newTriangles;
     }
 
     public static Vector3 GetNormal(Vector3 a, Vector3 b, Vector3 c) {
         Vector3 side1 = b - a;
         Vector3 side2 = c - a;
         return Vector3.Cross(side1, side2).normalized;
     }
 }


And t$$anonymous$$s is the result (the generated mesh is on the left) :

Illustration

Could someone tell me what I'm doing wrong please ?

Thanks a lot.

lightmesh.jpg (141.7 kB)
Comment
ahungrybear

People who like this

1 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 hexagonius · Feb 01, 2016 at 09:36 PM 0
Share

I think you're forgetting the call to RecalculateNormals at the end.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by OswaldP · Feb 01, 2016 at 09:36 PM

I found the solution to my problem, I only needed to recalculate the normals of the mesh at the end of the mesh generation script using :

 mesh.RecalculateNormals();

Hope it will help someone else !

Comment
ahungrybear

People who like this

1 Show 0 · 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

44 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

Related Questions

Mesh wont render although there are no errors! 1 Answer

Mesh combining makes an incomplete mesh? 0 Answers

Question about fixing normals 0 Answers

Thin black lines between meshes 1 Answer

when i snap the walls (without textures) it makes a difference in the colors ?? why is that ? 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