Shader Graph: How to create shader that sets different colors on faces depending on the vertex normals.
I'm trying to create a shader in shader graph that can check the normal of a face, and then assign it a color if it reaches a threshold angle. I'm looking to achieve this kind of look for my terrain:
I'm new to shader graph so any node examples would help tremendously. Thanks!
Answer by Eimhin · May 26, 2020 at 03:56 AM
This graph should work for what you're trying to accomplish. (Note I'm using URP, there is a misleading difference in HDRP with the world space of the Transform node. A quick web search can fix it for HDRP)
The graph works by getting using the gradient to determine the face normal, which is then used to determine the albedo (top half) and normal for a flat shading lighting effect (bottom half). The color is determined by using the angle between the face normal and the up vector, as this angle is compared to a threshold angle property to select between two color properties.
Hope this helps :)
Hi Eimhin
your example works pretty well. I have a question if it is possible to create something similar but for spherical terrain. I am using distance calculation from the center of the object which helps me to define where can be grass and mountain, but I would like to implement something like you did for flat terrain with smoothness.
Is possible to grab neighbors vertices and compare them? and based on distance it will decide if its flat or slope?
ok, I found solution. Anyway, thanks for inspiring with this graph
Hey what was your solution? I'm trying to accomplish the same thing.