Hi I’m curious whether it is possible to create an elevation map shader which would apply a gradient to a mesh depending on how high/low the parts of the mesh are. I have applied ramp shaders projected from the side in Maya to get this effect in the past. Is there a way to add “lines” every x ammount of units like in traditional cartography? I am attaching an example of the kind of effect I wish to achieve. Any help would be greatly appreciated.
You can write a shader that looks at the pixel’s position along the Y axis and outputs darker pixels every N units. This solution has an inherent problem - on areas with small slope contour lines get wider than on the slopy ones.
They’re using screen-space derivatives (ddx, ddy) to make sure that the line has constant width, so it’s not dependent on the slope. Their code is in HLSL and uses fwidth().
I had a look at the HSLS shader and it is pretty much what I need, judging by the screenshots. Unfortunately I’m a complete newb so haven’t got the slightest idea of how to implement it in Unity. I guess I would need to translate it into CG language? But again, I don’t have a clue how. More help is much needed, please.
Thank you so much. I realize that there are no promises, but if you can have a look, that would be fantastic. I actually want to apply this to a mesh rather than a terrain and if I can make it double-sided (see it from below and from the top) it would be even better. I guess it can be just a generic mesh with hills and dips, but I’m attaching a Maya file just in case.
If you do this, you’ll find that the dd(x|y) functions aren’t supported by OpenGL. You can make it a D3D-only shader, or try and use the technique for emulating derivatives explained in this GPUGems article.