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 /
avatar image
0
Question by druidowm · May 05, 2019 at 08:32 AM · meshshadows

Mesh not receiving shadows?

Hi,

I am new to Unity (this is my first project!), and I am running into some difficulties with a mesh not receiving shadows.

I am making a mesh for the graph of a function, and it seems to be working well, but my graph is very difficult to see (it is all the same color): alt text

I am thinking this is because it is not receiving shadows from itself. I noticed that it is in fact not receiving shadows from anything. I am not sure why, because I have set it to receive shadows: alt text Here is the code I used to generate the mesh:

 void Start () {
         verts = new Vector3[resolution * resolution];
         tris = new int[12 * resolution * resolution];
         Vector2[] uv = new Vector2[resolution * resolution];
 
 
         float step = 10f / (resolution-1);
         for (int i = 0; i < resolution; i++)
         {
             for (int j = 0; j < resolution; j++)
             {
                 verts[resolution * i + j] = new Vector3(step * i - 5f, Mathf.Sin(100 * i), step * j - 5f);
                 if (i != resolution-1){
                     if (j != resolution - 1)
                     {
                         //print(resolution * (i + 1) + j + 1);
                         tris[12 * (resolution * i + j)] = resolution * i + j;
                         tris[12 * (resolution * i + j) + 1] = resolution * i + j + 1;
                         tris[12 * (resolution * i + j) + 2] = resolution * (i + 1) + j;
                         tris[12 * (resolution * i + j) + 3] = resolution * (i + 1) + j;
                         tris[12 * (resolution * i + j) + 4] = resolution * i + j + 1;
                         tris[12 * (resolution * i + j) + 5] = resolution * (i + 1) + j + 1;
                         tris[12 * (resolution * i + j) + 6] = resolution * i + j;
                         tris[12 * (resolution * i + j) + 7] = resolution * (i + 1) + j;
                         tris[12 * (resolution * i + j) + 8] = resolution * i + j+1;
                         tris[12 * (resolution * i + j) + 9] = resolution * (i + 1) + j;
                         tris[12 * (resolution * i + j) + 10] = resolution * (i + 1) +j + 1;
                         tris[12 * (resolution * i + j) + 11] = resolution * i + j + 1;
                     }
                 }
                 uv[resolution * i + j] = new Vector2((float)i / resolution, (float)j / resolution);
             }
         }
 
         mesh = new Mesh();
 
         mesh.vertices = verts;
         mesh.uv = uv;
         mesh.triangles = tris;
 
         GameObject game = new GameObject("Mesh");
         MeshFilter meshFilter = game.AddComponent<MeshFilter>();
 
         meshFilter.mesh = mesh;
 
         MeshRenderer meshRenderer = game.AddComponent<MeshRenderer>();
         meshRenderer.material = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Material.mat");
     }

Is there some way to get the mesh to receive shadows? Any help would be greatly appreciated!

screen-shot-2019-05-04-at-23533-pm.png (96.3 kB)
screen-shot-2019-05-04-at-23057-pm.png (50.8 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 druidowm · May 04, 2019 at 07:02 PM 1
Share

I just found the solution! mesh.RecalculateNormals() does the trick! :)

0 Replies

· Add your reply
  • Sort: 

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

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

My mesh isnt creating any shadows 1 Answer

Imported mesh artifacts in casted shadow? 0 Answers

weird shadows 2 Answers

Problem in rendering meshes 2 Answers

Lighting Messed up with multiple meshes 1 Answer


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