18
$\begingroup$

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.

Edit

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

Color ramp (c) -> (c) Diffuse BSDF (BSDF) -> (Surface) Material output
$\endgroup$
21
$\begingroup$

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

Result:

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

$\endgroup$
  • $\begingroup$ Ah! I knew it would be simple, I didn't know the existence of Mapping node. $\endgroup$ – ikel Dec 13 '13 at 2:15
17
$\begingroup$

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 seperator node, you can get values ranging from 0 to 1 for any of the primary axis. 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 "Seperate XYZ" node with a "Seperate RGB" node

$\endgroup$
  • 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 '15 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.