Custom shader: Color gradient based off different heights in a model

Hi all :slight_smile:

I’ve got a question regarding a custom shader to display a color gradient based on the height of the vertex over a massive terrain. The problem is the following:

  • Im trying to visualize a survey of channel in Unity, i’ve got the model all ready and in Unity but i want to visualize the high-low spots of the oceanfloor by using a gradient. Highest spots are red → Yellow → Green → Lowest spots Blue.

I created the following shader:

It should put a color gradient based of the height of the vertices of the model. The problem is that it will only do this based on the height of the camera in relation to the model. If i zoom in i can see the gradient. But as soon as i go up with the camera the entire model gets the same color. The position node is set to World so it shouldn’t be influenced by the cameras position right?

This is the first time for me to create a shader, as you can probably tell im very new to this.
It should look kinda like this (example of a different software)

I would very much appreciate it if someone could point in the correct way :slight_smile:

How you set the MinHeight and MaxHeight in material? Are they constant values?

Thanks for your reply!
Yes I set the min and max height to the min and max vertice world position of the model (roughly -4 up to -18)

What if you directly connect the World Position to the Base Color? Will the color change when moving camera?

Yeah, the camera always influences how the colors are layed out on the model.
Very strange :open_mouth:

What if using a different version editor or creating a new project? Will the problem still be there?

The same shader works fine on my end. Does it behave differently when you apply it to normal meshes like a standard sphere? I can’t think of any reason camera position should be brought into that equation.

Since it’s being affected by the camera, I assume you can move the terrain itself to reveal the gradient again after it disappears?