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
0
Question by JooZ · Feb 27, 2016 at 04:22 PM · shadermeshflat

Standard shader issue with generated mesh

Even though I looked in many places in the forum on this known issue, I was not able to fix it. I am posting my code here to check if somebody can find what is wrong.

I am generating a mesh for a cylinder from scratch in the code directly, but the standard shader still displays flat faces for the mesh.

     public int nbase = 15;
     public int nspan = 10;
 
     private Mesh mesh;
     void Start () {
         MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
         mesh = new Mesh();
         mesh.name = "cylinder";
         meshFilter.sharedMesh = mesh;
         mesh.Clear();        
         mesh.vertices = getVertices();
         mesh.triangles = getTriangles();
         mesh.RecalculateNormals();
         mesh.RecalculateBounds();
         mesh.Optimize();
     }
 
     Vector3[] getVertices() {
         Vector3[] vertices = new Vector3[(int)(nspan * nbase)];
         int index = 0;
         for (int j = 0; j < nspan; j++)
         {
             for (int i = 0; i < nbase; i++)
             {
                 float a = (float)i * 2f * Mathf.PI / nbase;
                 vertices[index] = 0.5f * (new Vector3(Mathf.Cos(a), (float)j, Mathf.Sin(a)));
                 index++;
             }
         }
         return vertices;
     }
 
     int[] getTriangles() {
         int[] myTriangles = new int[(int)(3f * 2f * ((float)nspan - 1f) * ((float)nbase - 1f))];
         int index = 0;
         for (int j = 0; j < nspan - 1; j++)
         {
             for (int i = 0; i < nbase - 1; i++)
             {
                 myTriangles[index] = i + (int)((float)j * (float)nbase);
                 myTriangles[index + 1] = i + (int)((float)(j + 1) * (float)nbase);
                 myTriangles[index + 2] = i + 1 + (int)((float)j * (float)nbase);
                 myTriangles[index + 3] = i + 1 + (int)((float)j * (float)nbase);
                 myTriangles[index + 4] = i + (int)((float)(j + 1) * (float)nbase);
                 myTriangles[index + 5] = i + 1 + (int)((float)(j + 1) * (float)nbase);
                 index += 6;
             }
         }
 
         return myTriangles;
     }

Here is a picture of the result. I used the MeshDisplay script to represent my normals in the editor. I tried also to use the NormalSolver from http://schemingdeveloper.com to use alternative method to compute my normals, but it did not change the result.

What I am looking for here is to get my cylinder smooth. Any idea/suggestion would be very welcomed.

alt text

screenshot.png (275.7 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JooZ · Feb 29, 2016 at 12:42 PM

Unfortunately, my question did not seem to raise huge interest here. Just in case somebody shows up and is willing to have a look, I post here a new screenshot where I display tangents as well. It kind of emphasizes the fact that my normals seem to be off (like normal to the next face and not to the average of two adjacent faces?). Does it make sense?

alt text


screenshot2.png (511.6 kB)
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

67 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

Related Questions

Change mesh texture when a line renderer has formed a loop on it 0 Answers

Project turns "read only" after a while 0 Answers

Outline Shader Problem with generated mesh 2 Answers

Texturing procedural generated meshes 0 Answers

wierd black spots/shadows on mesh from blender to unity 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