Thursday, 9 May 2013

Textured Displaced Height Map

To correctly implement Dynamic Hight Map Displacement, my approach to render tree textures, (not just sampling directly from the ground)  is to render a contour reference map containing x and y coordinates that could then be used to sample from a separate tree texture.









Saving the correct height to a separate render target required a few solutions to different problems.

Near far sampling -

Up close, trees should show a gradient from 0 to the relative maximum value.  This height value is calculated by dividing the current pixel height by the maximum pixel height, giving a height value in the [0,1] range.

This calculation quickly breaks down when trees are viewed from farther away, as the current pixel height range is smaller-

Rather than sampling from the bottom of the tree, we would want to sample from the middle as distance grows -  Thus a solution to this problem is to take the average value between the relative maximum height and the current height value-
(is this really that good of a solution??  ... does not give full range??)


Up/Down sampling-

The maximum amount of displacement occurs when viewing trees from the side, and no displacement occurs when looking down on the trees.   The height calculation is taken care of in the general height formula, but the correct height value is not saved to the forest volume layer. 

When looking from the side, there should be a gradient with height values from 0 to the max height of the tree.  When looking above, only the value of the maximum height should be seen.

This problem is soluved a linear interpolation between the current hight value and the relative maximum hight value based on the ViewUp dot product value-

Height saved to displacement map



Having correct sampling and smearing of tree height / shape is a critical step in implementing this process.  So far this process looks smooth and transitions fluidly with the camera constraints-  




Now with proper height or y values, we need x values to determine how to sample tree color-


A simple but powerful approach to this problem is to include "offset" values in the height map, essentially randomized pixel values in the green channel-



Forest Height Map with Offset values



Rendering the offset value to the displacement map gives x and y coordinates to sample from a displacement texture-

Displacement Map with x and y texture coordinates


Rendering the tree color texture with the coordinates from the displacement map allows for dynamic coloring of the displacement map-


Textured Forest
Forest Color Texture




No comments:

Post a Comment