Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
0
Question by michaelf2016 · Jan 29 at 04:09 AM · shadershadersshader programmingmesheslow poly

Any way to achieve low poly effect without duplicating verticies

So, as I understand it, colors and lighting and all that stuff are applied to triangles based on the normal vectors of the vertices. The fragment shader will interpolate between the normal vectors to smoothly apply lighting and coloring across the entire triangle. If you want to make a low poly effect (basically meaning an effect where you don't have this interpolation) you can give each triangle its own vertices that all have the same normal vector so then lighting and coloring will be applied the same across that triangle. The problem with this is that to render the same mesh you need 6 times as much vertex data, which is obviously not ideal. My question is, is there a way to make the fragment shader not interpolate between normals and instead just use one normal for shading the entire triangle.

You could use the ddx and ddy functions of the fragment shader to get two tangent vectors of the surface plane. You could then calculate the cross product of that to find the normal vector for that flat surface. This could then be used to do flat shading for that surface. The problem with this is that it's super demanding as you would need to be calculating a normal for every fragment. So, ideally, I wouldn't want to do this solution either.

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
1

Answer by Namey5 · Jan 29 at 07:29 AM

One thing to keep in mind is that shader performance is only as good or as bad as you measure it to be - recalculating the normals every fragment via derivatives is probably perfectly fine in most cases, so I would only rule it out if you know it has a visible impact on your game's performance.

That aside, there are a couple of other ways you could do this in a shader:

  1. Geometry shaders - this one is the most direct (i.e. literally defining one surface normal for every face) however it is also probably the least recommended. To slightly contradict my advice in the beginning, geometry shaders can have a significant performance impact and aren't properly supported everywhere. That + lack of support outside basic vert/frag shaders can make them a bit of a pain to work with in Unity.

  2. nointerpolation - you can add the nointerpolation keyword to your vertex normals output field and everything else should just be taken care of. This is probably the way I would recommend, however this also won't work with surface shaders as the vertex data struct will be regenerated when the shader is compiled.

    As much as it might not be ideal, duplicating the vertices is probably the most straightforward and well supported method - as long as your meshes aren't super high poly I don't necessarily see this being a bad option, especially when Unity lets you do this directly in the mesh importer. Ultimately if your concern is performance I would suggest creating some kind of stress test and just trying out each of the methods. See what works best for your needs.

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

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

Silhouette overlay shader 0 Answers

Displace and show normals in fragment shader 1 Answer

Custom UI Shader Stencil Problem [willing to pay for fix] 1 Answer

Unity Advanced Shader Help 0 Answers

Shader: 1 Base Texture Overlaid by 1 Transparent Texture. 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