Displacement Maps
Displacement maps are very similar to Normal maps except for one difference: they actually deform geometry. If you recall my blog on normal maps, I talked about how the normal's were used with lighting to create depth which gave geometry detail without having to actually deform it. Displacement maps work very similarly, except now you are deforming geometry to the given map, and are creating the detail through this displacement.
In the above picture, the ground is mapped with the same texture, except one uses normal mapping, and the other uses displacement mapping. The top one uses displacement. As you can see, the bricks on the ground are generated through moving the necessary geometry specified by the displacement map. The normal mapped ground creates detail through the normal's casting shadows, creating depth and giving the look of raised bricks.
The displacement is done in the vertex shader. The shader reads in the necessary vertices from the map, and then displaces the vertices accordingly.
You can also do displacement mapping through ray casting. With this, you need the coarse mesh, displaced texture and assume that the displacement is a negative displacement. You find the intersection point and then find the displaced texture coordinate. Per vertex, you determine the eye ray, light ray etc. in tangent space, and per fragment you find the intersection of the eye ray with the height field, (offset the surface point and texture coordinate) and add the shadow ray to light source. You walk along the ray in small steps, and interpolate the height field linearily.
The interpolation is important as you can see in the following pictures. The top picture is through a piece-wise constant interpolation. Notice how it seems to be chopped into levels, and isn't very smooth with no discernible shape. The bottom picture is through a piece-wise linear interpolation, and is much smoother and more accurate to the actual displacement map. You can make out a face in the bottom picture.
Displacement mapping is a great way to create detailed objects within your game through actual manipulation of the geometry. The only downside is that your objects need to be much higher poly rather than objects that are normal-mapped. The more detail, the higher the poly count. However, if your game can handle it, the payoffs are worth it.
No comments:
Post a Comment