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
1
Question by fherbst · Jun 04, 2011 at 02:15 PM · normalsurface shaderinterpolation

Not interpolating surface shader normals (by purpose)

Hey all,

is it possible to tell a surface shader to NOT interpolate the normals from vertex level to fragment level? What I am trying to do is a faceted shader (hard edges for every face) without changing the actual surface normals (because I finally want to use the shader as a terrain replacement shader, so I cannot change the surface normals).

Is that possible? And if not, could it be done with a non-surface shader? It seems to be quite hard to find a solution to this, because everyone tries to get a smooth surface :).

Felix

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

Answer by Owen-Reynolds · Jun 04, 2011 at 03:58 PM

It's nearly impossible. The only way for pixels to get any values at all is by auto-interpolation during rasterizing. It seems like turning off interpolation could use the "face" normal, but faces don't have normals or any other values. Everything is interpolated from verts. The pixel shader has no access to the verts it was built from, or even whether it was made from a line, tri, quad... , so there is no hope of computing the "face" normal in the pixel shader.

A surf/non-surf shader won't matter. If you have any lighting at all, it goes off of the normals.

Mechanics-wise, the question is "can the rasterizer be told to compute a single "average of all verts" value, used for all pixels in the face, instead of linear interpolation?"

The common way to do it is to split all the verts (which is what flat shading does for you automatically.) All verts in a face get the exact same "face" normal, which interpolates to that normal. But there's no way to tell Unity's terrain mesh to do that.

I could see where you make a low-res normal map of the terrain (Unity provides enough access you could auto-generate it from the Terrain,) have the pixel shader compute UVnormMap = floor(IN.UV.xz/5+0.5), so that all pixels in a square use the exact same value, then look that up and use it for the normal.

Comment
Add comment · Show 1 · 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 fherbst · Jun 05, 2011 at 03:28 PM 0
Share

Okay, thank you. So I am going to use a custom mesh ins$$anonymous$$d of a Unity Terrain. I thought about generating an inverse normal map as well, but that wouldn't align with the face edges very well and wouldn't provide the effect I am going for (one could make a really strange UV map to get sharp face edges, but that would be a bit too much). Thanks again!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Normal vectors not interpolating in custom lighting surface shaders 1 Answer

How to not require normals in a surface shader 1 Answer

What subspace are SurfaceOutput vectors in? 0 Answers

Dynamically generated bump map for Surface Shader? 0 Answers

Prevent ColorMask obscuring parts of an object's mesh 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