I'm trying to write a shader for terrain that will color the mesh based on slope angle, ie color the sides of mountains or other steep surfaces a different color than the ground. In my shader I am checking the normal of a vertex, and if its angle is past a certain threshold then I set the vertex color to black, otherwise white.
What I'm getting is that solid colors are being applied across entire faces:
But I'm expecting the colors to smoothly transition between vertices:
Here's my shader code:
shader_type spatial;
uniform float slope_threshold;
varying vec3 vColor;
void vertex() {
float slope_angle = degrees(dot(NORMAL, vec3(0, 1, 0)));
if (slope_angle < slope_threshold) {
vColor = vec3(0, 0, 0);
}
else {
vColor = vec3(1, 1, 1);
}
}
void fragment() {
ALBEDO = vColor;
}
Am I writing the shader wrong somehow? Am I exporting my terrain model from Blender incorrectly? Any help would be greatly appreciated!