0
$\begingroup$

I'm trying to add false coloring to a terrain to help me identify the slope of faces when looking at it from top-down. I'd like:

  • ~vertical faces (normal within 30 degrees of horizontal) faces to be one color
  • ~flat faces (normal within 30 degrees of vertical) to be one color
  • other faces to have a third color

I've hooked the Normal from a Geometry node to calculate a dot product with +z: the output of which should be -1 for faces pointing down, 0 for horizontal, and 1 for vertical. I've fed the result to a color ramp, with color stop changeovers to 0.333 and 0.666, which should be 1/3 and 2/3 of 90 degrees (30 and 60 degrees). However, there are faces (like the one selected) that are "obviously" within 30 degrees of vertical, yet they aren't showing the vertical color. Why?

landscape with normals displayed and false colors, along with screenshot of the shader node graph for the material

$\endgroup$

1 Answer 1

0
$\begingroup$

The relationship between the dot product and the angle is not linear. It is the output of the cos() function. So, some common normal angles placed on the color ramp after dot product with +Z would be:

  • 90 degrees: 1.0 (vertical normal)
  • 75 degrees: 0.966
  • 60 degrees: 0.866
  • 45 degrees: 0.707
  • 30 degrees: 0.5
  • 15 degrees: 0.259
  • 0 degrees: 0.0 (horizontal normal)

To calculate the color ramp value for an angle away from horizontal:
cos((90 - angle) * π/180)

terrain with fixed color ramp stops at 0.5 and 0.866

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .