No announcement yet.

Contour map material

  • Filter
  • Time
  • Show
Clear All
new posts

    Contour map material

    Dear All,

    I want to display the contours on a landscape. I kinda know how to go about this in general, however, I am rather unfamiliar with the material editor and I fall at the first step.

    How I'd go about it is:

    (1) Get the z component of the world position for each position on the landscape.
    (2) Calculate modulus of z by my contour separation.
    (3) Clamp 1.0 to 0.99 to 1.0 and everything else to 0.
    (4) Use this value for alpha and combine with a diffuse of the color I want for my contours.

    This should produce contours, albeit not ones of constant thickness when viewed from above.

    My question is, how do I get the z component of the world position? This would be easy in HLSL but isn't obvious in the material editor. I am guessing that worldPosition outputs a float3 vector, how to extract just the z component as a float?

    Many thanks!

    I realised their is an answer...but it is rather an unpleasant one. I can get the z component by taking the dot product of the position vector of every point on the landscape by a unit z vector. This is, however, madly inefficient when I could just write worldposition.z in HLSL. So if you do know a simpler way of extracting the z component, or adding a HLSL statement into the shader, do post.


      CustomNode allows you to write HLSL straight into the material. You may or may not be able to access what you need from there though.

      If you only want to the Z component of the world position node, use a component mask node.


        Many thanks! Just what I needed.

        We have success, below is a screen shot of the contour material. It will work on any objects, not just on landscape:

        We are using the material to create landscapes for scenes for Forester Pro, an easy to use tree creator for UDK ( It is often difficult using the landscape tools to see the orientation of a surface is correct, for example, to ensure that valleys go down hill from their top to their bottom. With contours it makes this obvious and shows any low depressions. I guess you could also use it to create a contour map of your level (for example for a player map), although the contour lines will not be constant thickness from above (I will think about how to do this). You could also use it to generate contours for a heads up display.

        Here is the materials shader code, it is quite simple. Notice you can specify the vertical line width and the contour separation:


          Ok so I've managed to get the contours approximately equal width when viewed above. This was achieved simply by scaling the vertical width of the contour line in the shader above, by the inverse of the z component of the landscape surface. Actually, I found had to add in a fiddle factor of power to the 0.4 to make the contour lines on low angle surfaces look right. The effect (viewed from above with a perspective camera and midday lighting) is shown below. With a iso camera and only ambient light I guess it could be used to create a player contour map texture.

          The shader is shown below. Notice I had to calculate the normals by transforming a vector3 0,0,1 from tangent to world coordinates since you can't use worldNormals as an input to the pixel shader.

          From here I could get the shader to add grid lines and remove contours below sea/lake level.


            One last post. This is the shader with a few tweeks. It makes every fifth contour thicker, removes contours below a height set as sea level, and projects a grid on the landscape. I'll leave it to you to figure out how these tweeks are achieved.