Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Szyu · Jun 21, 2018 at 09:00 AM · shadermeshoutlinegenerated

Outline Shader Problem with generated mesh

Hello,

I try to generate a wall structure from vertices. After putting the generated mesh into a meshfilter and meshrenderer, the wall is displayed correctly. However, when I try to apply an outline shader (i.e. this one: https://github.com/Shrimpey/Outlined-Diffuse-Shader-Fixed), it got some strange behaviour although it works with default meshes. alt text

The mesh generation method works like this:

 Vector3[] meshVertices = new Vector3[entity.Triangles.Count * 3];
 int[] indices = new int[entity.Triangles.Count * 3];
 int j = 0;
 int k = 0;
 for (int i = 0; i < entity.Triangles.Count; i++)
 {
     indices[j] = j;
     meshVertices[j++] = entity.Triangles[i].A;
     indices[j] = j;
     meshVertices[j++] = entity.Triangles[i].C;
     indices[j] = j;
     meshVertices[j++] = entity.Triangles[i].B;
 }
 mesh.vertices = meshVertices;
 mesh.triangles = indices;
 
 mesh.RecalculateBounds();
 mesh.RecalculateNormals();
 mesh.RecalculateTangents();


The Triangle class contains just 3 Vector3 Objects for each edge of the triangle.

I cant figure out why the shader behaves like shown on the picture instead of just laying an outline around the object. So help would be appreciated.

shader-problem.png (194.4 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by callebo_FK · Jun 25, 2018 at 12:43 PM

I'm guessing your outline shader duplicates the mesh, pushes its vertices out and turns black. Your problem is that your vertices, or edges, are "hard". The vertices are not shared in the edges, so they go their seperate ways.

One way to solve this is by smoothing the meshes edges in your 3D program or inside unity, although I'm not sure how to do it in unity.

Same problem explained here: https://answers.unity.com/questions/625968/unitys-outline-shader-sharp-edges.html

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
avatar image
0

Answer by Szyu · Jun 28, 2018 at 10:58 AM

Ok so the main problem stated on the other question seems to be, that multiple vertices on the same position have different normal vectors? Guess this will be a tough one, since the positions are coming from another system. I'll see what I can do to get the vertice structure of the base model, so that I can examine whether the normals are correct or not.

If there would be a simpler way to do this using unity, I'd appreciate a suggestion on how to do it.

But thanks in Advance @callebo_FK for this hint.

Comment
Add comment · Show 4 · 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 callebo_FK · Jun 28, 2018 at 11:01 AM 0
Share

One idea is to ins$$anonymous$$d look for another shader that does outlines, since this is not the only way to do them. Not saying you should learn how to program your own shaders but I'm pretty sure there are out-of-the-box ready ones available with some googling.

avatar image Szyu callebo_FK · Jun 28, 2018 at 11:48 AM 0
Share

I tried many different shaders... All with the same result... But something that came to my $$anonymous$$d: If the normals would be wrong, after letting unity recalculate them, should the objects be distorted ins$$anonymous$$d of displayed correctly?

avatar image Szyu callebo_FK · Jun 28, 2018 at 12:05 PM 0
Share

I tried many different shaders... All with the same result... But something that came to my $$anonymous$$d: If the normals would be wrong, after letting unity recalculate them, should the objects be distorted ins$$anonymous$$d of displayed correctly?

EDIT: After mesh.RecalculateNormals(), I checked vertices and normals of the mesh and tried to visualize them using shapes in the editor (with a little offset). The result looks like this: Forum Img Upload doesnt seem to work, so I uploaded an image

So there are multiple vertices at the same position with different normals. but how could I avoid this without the model being distorted?

avatar image callebo_FK Szyu · Jun 28, 2018 at 12:36 PM 0
Share

I'm sorry I'm not sure I understand what's going on :D I haven't worked with meshes in scripts in Unity ever, so I'm not sure what RecalculateNormals() does. I'm also not sure what you are talking about the model being distorted? You mean like what your outline shader is doing?

If you want to use that shader, the normals need to be soft. That's all I can say, how you accomplish that I do not know. alt text The green/blue lines are the vertices normals. You want the one on the left, where in the middle the vertices share the normals. That way, your mesh won't go separate ways when distorted/inflated/displaced (which your outline shader does).

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

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

Trying outline with Shader Graph 2020 causes weird glitchy effect 0 Answers

Glowing outline with occlusion 0 Answers

why outline is drawed only on front side of skinned mesh render 1 Answer

How to add a MeshCollider to a plane that has been modified with a shader displacement map 1 Answer

Render transparent mesh over sprite 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