• 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 Gochida · Aug 30, 2015 at 03:49 AM · meshlightingprocedural-generation

Generated Mesh not being lit?

I'm creating a simple mesh (literally just a one sided plane). I'm applying a custom material (default settings from creation). Then I'm applying an 'advanced' texture which has Read/Write enabled and wrap mode set to repeat.

this is the code I'm using specifically, to generate and set-up the mesh

     public Mesh GenerateMesh()
     {
         vertices = new Vector3[] {  //positions are off by 0.5f because coordinates point to the CENTER of a tile, not a corner
             new Vector3( -0.5f, -0.5f, 0),                   //0
             new Vector3( -0.5f, height - 0.5f, 0),          //1
             new Vector3( width - 0.5f, height - 0.5f, 0),  //2
             new Vector3( width - 0.5f, -0.5f, 0)            //3
         };
 
         uv = new Vector2[]
         {
             new Vector2(0, 0),  //0
             new Vector2(0, 1),  //1
             new Vector2(1, 1),  //2
             new Vector2(1, 0)   //3
         };
 
         triangles = new int[]
         {
             3, 0, 1,
             1, 2, 3
         };
 
         roomMesh = new Mesh();
         roomMesh.vertices = vertices;
         roomMesh.uv = uv;
         roomMesh.triangles = triangles;
 
         MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
         meshFilter.mesh = roomMesh;
 
         MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer>();
         meshRenderer.material = Sys.LoadMaterial("Materials/floor_material");
         meshRenderer.material.SetTexture("_MainTex", Sys.LoadTexture(texPath));
         meshRenderer.material.SetTextureScale("_MainTex", new Vector2(width, height));
         
 
         return roomMesh;
     }

All the textures used are fairly bright, vibrant colors, however when I run the game they look dark as seen in game

I've tried adding local lights and directional lights, set for runtime lighting (baking is not an option as I'm generating the floors at run time)

Surely there's something I'm missing? Why won't these planes light up?

I could switch the shader to an unlit shader, but Ideally I'd like to do lighting in the scene to simulate torches, lanterns, etc.

Comment
Scribe
Kr0meel

People who like this

2 Show 4
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 cjdev · Aug 30, 2015 at 07:39 AM 0
Share

Try GetComponent<Renderer>() instead of GetComponent<MeshRenderer>().

avatar image EvilTak · Aug 30, 2015 at 09:40 AM 0
Share

What shader is the floor_material material using? Also its better to add a private serialized Material variable instead, assign your floor material to the above made variable in the inspector and assign the renderer's material to be that variable instead of dynamically looking for it each time.

avatar image Scribe · Aug 30, 2015 at 11:01 AM 2
Share

Maybe you need t recalculate normals? roomMesh.RecalculateNormals(); or set them yourself as it is likely they should all be -Vector3.forward for a 2D game!

avatar image Gochida · Aug 31, 2015 at 01:50 AM 0
Share

Thank you Scribe, recalculating the normals was exactly the fix!

1 Reply

  • Sort: 
avatar image

Answer by smugleafdev · Apr 01, 2021 at 03:22 AM

It would be nice if people posted actual replies instead of comments that are hidden and for some reason rendering full of $$anonymous$$.

You need to call roomMesh.RecalculateNormals(); and then it will render properly.

Comment
Kr0meel

People who like this

1 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 Kr0meel · Oct 07, 2022 at 08:42 PM 0
Share

This worked for me. Thanks!

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

30 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

Related Questions

Weird lighting behaviour when mirroring mesh 0 Answers

Weird shadows on my mesh 1 Answer

Meshes appears very dark than expectation 0 Answers

Why are the corners of my generated Mesh going dark/light like this? 1 Answer

Why won't spotlight light anything above its z location? 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