elevation map

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.

Thanks in advance.

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.

Look at this thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=529926&forum_id=12&gforum_id=0

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().

Thanks Kuba

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.

Cheers

I might look into that later on, can’t promise. Do you have a sample terrain I should try it on? PM me.
Of course I’ll post the results here.

I would be very interested in seeing how you do this also. Where are you getting your original data to generate the elevation maps? DEM data?

Hi Kuba

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.

Thanks a million.

229447–8240–$nurbsmb_730.zip (471 KB)

Hi Bigkahuna

I’m taking grayscale images and then applying them as heightfields/displacement maps in Maya. But I guess you can take DEM files too.

Hey Kuba,

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.