Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
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
Add comment · 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>() ins$$anonymous$$d of GetComponent<$$anonymous$$eshRenderer>().

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 $$anonymous$$aterial variable ins$$anonymous$$d, assign your floor material to the above made variable in the inspector and assign the renderer's material to be that variable ins$$anonymous$$d of dynamically looking for it each time.

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

$$anonymous$$aybe you need t recalculate normals? room$$anonymous$$esh.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

· Add your reply
  • Sort: 
avatar image
0

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
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

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

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

Problem with Spot Lights on Terrain 0 Answers

Meshes appears very dark than expectation 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