Geek Culture
Published in

Geek Culture

Height Maps And Displacement In Unity HDRP

HDRP allows for some impressive graphical features. Texture Heightmaps and Pixel/Vertex Displacement are such features.

Today’s Objective: Explore texture heightmap, normal map, and Displacement options, to create realistic visuals.

What are Height Maps?

Height Maps are not a Unity/HDRP-specific feature, and are a common part of most material/environment creation software.

Put simply, Height Maps are an image that is applied to a material, along with the separate texture (appearance) image, which gives the illusion of depth/height to a 2D shape using that material.

https://docs.unity3d.com/540/Documentation/Manual/StandardShaderMaterialParameterHeightMap.html
https://docs.unity3d.com/540/Documentation/Manual/StandardShaderMaterialParameterHeightMap.html

This is pretty amazing already, considering what all our favourite modern AAA games would look like if they only used Albedo textures shown on the left.

And what’s even more amazing, is this:

Despite how it looks, all the objects shown above are still 2D planes with no 3D geometry what-so-ever!

But they look truly 3D, don’t they?

How the different options affect a Material:

Albedo without Normal or Height maps:

The surface is textured realistically, but looks completely flat and 2D, which it is.

Albedo✅ Normal❎ Height❎

Albedo with Normal map but no Height map:

This is a little better, with slight shadows and brighter lighting appearing around the individual rocks, giving the impression that it is slightly raised.

Albedo✅ Normal✅ Height❎

Albedo with Normal and Height Maps:

Now it’s really starting to look like a 3D cobbled surface. Even though the object and material is all still 2D, the renderer uses the Heightmap data to change where specific pixels are rendered, giving the impression that they are sitting higher than other pixels.

Albedo✅ Normal✅ Height✅

Note: This is just a quick example I set up, and is no where near as good as the effect can be. You can see that by looking at the images from the official Unity documentation at the top of this post.
Sharp changes in the Height Map levels can sometimes make the result look a bit worse, so using smoother images like the Unity Docs did is recommended.

To create a material like this:

(These sorts of materials can be created in non-HDR pipelines too, but I am currently using HDRP so my options may look a little different if you’re not.)

The Base (Albedo) Map and Normal Map options are usually available on most shaders.
You can set the Base Map with just a color, or a texture file and a color.
The Normal Map requires a texture (marked as “Normal” on import) and an intensity.

In HDRP, the Height Map options are not visible by default. You need to set the “Displacement Mode” first:

Pixel Displacement: The texture pixels will be rendered displaced, giving the illusion that the material/object is 3D.

Pixel Displacement

Vertex Displacement: The actual vertices of the object will be moved based on the data from the Height Map, making the object 3D.
This method is extremely dependant on the number of vertices in the object’s mesh, as more per unit means more accurate displacement.

Vertex Displacement

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store