12
$\begingroup$

I have a terrain with two materials going into a Mix Shader, I want the fac input to be the slope of the terrain. Steep parts should be one color, flat part another.

objects showing which parts should have which color, and nodes

$\endgroup$
1
  • $\begingroup$ Use the Input > Geometry node's Normal output. $\endgroup$
    – PGmath
    Commented Feb 24, 2016 at 20:31

2 Answers 2

17
$\begingroup$

You can easily blend different shaders based on the angle of an object's face.

You can get the face's angle using the Normal output of the Geometry node. Separate out the axis you need (in my case the Z axis) using a Separate XYZ node. Then I use the ColorRamp node to fine tune the range I want the transition to happen in. Do note a RGB Curves node would work just as well, it is just up to which you prefer. cycles material nodes

Here is what those nodes look like rendered.
cycles render - a slice of a single lonely hill

$\endgroup$
5
  • $\begingroup$ thanks, this works. i.imgur.com/vb3p9V5.png In your example it is a little hard to see the effect because of how similar the colors are. $\endgroup$
    – Vader
    Commented Feb 24, 2016 at 22:32
  • 5
    $\begingroup$ @Vader Interesting. By any chance are you color blind? Because to me there is a big difference between the green on top/bottom, and the brown in the middle. $\endgroup$
    – David
    Commented Feb 24, 2016 at 22:34
  • $\begingroup$ There is a noticeable difference, I just prefer harsh contrasts. (yes, I am :( ) $\endgroup$
    – Vader
    Commented Feb 24, 2016 at 22:42
  • 3
    $\begingroup$ @Vader ok, thanks. I will try to keep color contrast for color blind folks in mind. This was eye opening for me. $\endgroup$
    – David
    Commented Feb 24, 2016 at 22:45
  • $\begingroup$ If you do this the shader takes on the vertex colors of the normals which appear not smooth at all. Conveniently you used an extremely subdivided mesh. $\endgroup$
    – Unknow0059
    Commented Jan 11 at 2:17
2
$\begingroup$

I have a variation to this, and depending on what you are doing, it may make sense to use one of these answers over the other.

You may need to use true normal, depending on if you are animating the object(s) in rotation for any reason, and anything in the world that would be rotated may need to keep its material selection to be at the top of the rotated object.

so same basic steps but slightly alternate node setup.

enter image description here

Here's The result.

enter image description here

$\endgroup$
2
  • 2
    $\begingroup$ Have a UV :) I too some times use the greater then or less then node, but only when I want a hard edge. Also, you can use a ColorRamp node set to consent to create the same hard edge. $\endgroup$
    – David
    Commented Feb 24, 2016 at 22:39
  • $\begingroup$ Agreed, ColorRamp is just more flexible. $\endgroup$
    – Rick Riggs
    Commented Feb 25, 2016 at 0:35

You must log in to answer this question.

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