Cycles Height based material

I remember you could make “height” based textures in blender internal to blend different materials by setting the mapping to z - z - z. However, I’m not sure how to do this in cycles.

In other words, what node setup would achieve a result similar to the image below?


This is my take(does not work)


An easy way to do that: Take your mountain or anything, in front orthographic view, unwrap it with “Project from View (Bounds)”. This way, the whole height of your object goes from 0 to 1 on the Y axis of the UV map. After that, you just need to get to that Y coordinate and to use it as a factor.


This is a quick example with 4 colors representing 4 materials (grass, dirt, rock, snow). You just need to replace the colors by materials (using Object coordinates or another UV map) and the Color Mix nodes by Mix Shader nodes.

The color ramps are here to set the limits in between the materials. Where and how sharp or how smooth.

The blend file to play with: Forum Z-map.blend (286 KB)

Enjoy! :smiley:

EDIT: What I forgot to say… The “Separate RGB” node is the way to access separately to the components of any vector.

The use of a rotated gradient texture (set to object coordinates) with the help of the mapping node should give you the same thing without wasting a UVmap slot.

You can go even further by using some vector math to create masks based on slope as well, which will greatly help the realism.

Sorry I didn’t reply sooner. Just wanted to say: That was easy :). Excellent instructions and thanks for the blend file!

Hmm, do you have a link explaining how to achieve this? I googled around but I’m not sure how to use the vector math node. What would the node setup look like?

Let me dig up an old image from my attachments list



This is an example of how you can use the vector nodes to create a mask based on terrain slope, nodes that are not required if all you’re going to do is map a gradient texture to fade out based on the height of the geometry.

Anyway, with a combination of gradient texture mapping and this setup, you should be able to create some extremely realistic terrain.

I am coming back to this with a sphere shaped object and I can’t seem to get it to work. Does anyone have some tips on how I can get a spherical landscape to color map based upon height? I want the low areas to be blue and the higher areas to be white. I tried the various options on the Mapping node but it is still a hunt-and-peck mystery to me.

Attachments


27_height_landscape_shader.blend (221 KB)

Thanks for the link I have always been afraid of that thread because of the number of posts. I tried to download the BLEND file but it has expired. I’m not sure that is what would work in this case however. That looked like a procedural planet. So the source for the height is in the noise texture. What I have is an already sculpted sphere with no associated height information other than the location of the vertices.

I guess I am looking for some way to measure how far a vertex is compared to the center/origin of the object. That should be a distance value that can plug into a color ramp.

Upon (very quick) experimentation, this seems to work for me


Thanks for the suggestion, I can’t seem to get a positive result, however. It seems like the result of the Dot Product is always 1.0 or greater and thus returns the color on the right side of the ramp.

Do I have my nodes setup wrong?

Attachments


Atom, you were right, that was done based on displacement texture i was referring to.
There is a file with 2 versions, one from anurag.k which works here. Only thing i can think of is Objects scale or that Object’s mesh is far from it’s origin.
http://www.pasteall.org/blend/28349

Hi all,
to colormap the ‘height’ on a spherical mesh i use a 3 dimensional spherical gradient :wink:
Something like this:


J.

Here is a slightly modified setup,



The only change is the addition of the ‘power’ math operation. The nodegroup now gives the ‘real’ distance from origin. The problem is as eppo mentioned, the distance easily goes out of the range for the color ramp to work. This can be solved by adding a multiplication factor (the ‘radius’ of the object) to scale the value back into range. If only there was a way to get the ‘size’ of the object via a node :slight_smile:

However the spherical gradient method is the best way to do it i guess, no vector math required :slight_smile:

Thanks for all the replies.

@jimmy: For some reason I could not get your spherical gradient setup to work on my geometry using Blender 2.70 official release.

@anurag.k: You setup does work in a very narrow color ramp range.:cool: It would be nice if there was a way to scale the color mapping so I could use the range more fully. I tried playing around with the Power and Multiply nodes that feed the color ramp but I can’t achieve a better scale.

Attachments

27_sperical_height_landscape_shader.blend (184 KB)


Hi Atom, here is a .blend file with my setup: http://www.pasteall.org/blend/28360

I extended my node setup a little, now it accepts min and max distance values (in blender units ofc).



With this setup, the whole color ramp is used between the given max and min distance values

EDIT:
and dont forget that you can (ab?)use the brightness/contrast and color curves nodes to stretch the range before plugging it into color ramp!

Edited…Silly mistake…

Examples with somehow improved adjustments http://www.pasteall.org/blend/28375

I think power node is required because without it the value returned would be the square of the distance from origin. Ofcourse we can always adjust the range to our liking using curves but it would not be the ‘real’ distance right :P? The advantage with having real values is that we can easily adjust the min and max values in the node

EDIT:
In case i was not clear, the min dist in the node is the value of distance(blender units) that the lower end of color ramp will correspond to and the max dist corresponds to the upper end of ramp. So we just plug in the size values for our required model.

Here is my blend setup

Ouch, my apologies. That was mistake on my side - instead of Vector used simple Math node…
File above corrected.

Thanks everyone, those node setups work!