How do I colour a 3D terrain based on the height? Say, bottom green, and gradually to brown in the middle and white at the top.

When I use colour ramp node, I can see gradient colour across the 3d terrain along x-y plane, but I'd like to have the gradient upwards, in x-z, y-z plane.


Currently, my setup is using cycles and nodes like this:

Color ramp (c) -> (c) Diffuse BSDF (BSDF) -> (Surface) Material output

3 Answers 3


Mapping node:

You can use the Mapping node to rotate the texture on the Y axis, making the gradient vertical.

Change the Location Z axis value so that one "end" of the gradient is at the tallest peak or valley of the mesh. Also ensure that the Mapping mode is set to Texture:

enter image description here


enter image description here

UV unwrapping:

You could also UV unwrap your mesh.

  1. Enter edit mode (Tab) and select all A

  2. Set the view to Orthographic (Numpad 5) and view your mesh from the front (Numpad 1)

  3. Press U>Project from view:

    enter image description here

  4. Rotate (R) the resulting UV map in the UV/Image Editor so it is standing on end:

enter image description here

  • $\begingroup$ Ah! I knew it would be simple, I didn't know the existence of Mapping node. $\endgroup$
    – ikel
    Dec 13, 2013 at 2:15
  • $\begingroup$ @gandalf3 That's awesome! I just do not get why there is the need to rotate it? $\endgroup$
    – Lenn
    Oct 12, 2022 at 17:50

I just had this issue myself, and I found that you don't need quite so many nodes. If you pass the "Texture Coordinate" node's generated output to an XYZ separator node, you can get values ranging from 0 to 1 for any of the primary axes. After that, you only need to pass the Z value output to the Fac input of the ColorRamp node. 0 will be the lowest point in the object, and 1 will be the highest point. Set the ColorRamp to the colors you desire, and pass its color output to whichever shader you want. This will also cut down on the processing required by avoiding the rotation action done in the Mapping Node.

Cycles Node setup for procedural color based on height

The example above was used on a sky-dome. The higher up you look, the blue-er the sky gets. I should also note that you should be able to replace the "Separate XYZ" node with a "Separate RGB" node.

  • 1
    $\begingroup$ Also your technique and gandalf3's are different in that his uses the World space and yours the Object space. With his if you move your object along the Z axis the gradient does not move with it and you'll need to readjust the Mapping node's Z Location value, however this could be good if you want the gradient shared across multiple objects at a uniform altitude. With your method the gradient will move and scale with the object and is based on its Object Dimensions. It's nice to have two techniques to choose from. Just a matter of using Generated vs Object outputs, so we can mix and match too. $\endgroup$
    – Mentalist
    Apr 22, 2015 at 19:50

Normalize is helpful in the mix, too. It will condense the values so the full range of gradient colors shows up on the model. enter image description here

  • $\begingroup$ can you share the node setup for this? $\endgroup$ Sep 6, 2021 at 20:53
  • $\begingroup$ Could you specify what "the mix" is? $\endgroup$ Apr 29 at 21:48

You must log in to answer this question.

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