Graphics Reference
In-Depth Information
It is important to note that too many small triangles can impact the GPUs
ability to process many pixel shaders in parallel resulting in adverse
performance. This is where dynamic level of detail and other tessellation
optimizations become quite important.
In our recipe, we will support moving the vectors outwards if the value sampled from the
displacement map is larger than 0.5, and inwards if it is less. In an optimized asset workflow,
it may be desirable to support a single direction only. Moving excessively in either direction
can result in problems. Moving too far outwards can cause the object to be too large to fit
inside its bounding box, resulting in issues with geometry intersections; whereas, moving
too far inwards can result in degenerate, thin, and strange-looking meshes. Applying both
displacement directions within the one displacement map can make it more difficult to fine
tune these artifacts.
When our domain shader is processing newly created vertices from the fixed function
tessellation stage, we sample the displacement map for the given UV coordinates. If the value
is closer to black, we push the vertices in the opposite direction of the normal; and if the value
is closer to white, we pull the vertices out in the direction of the normal. Note that the normal
used here must be in world space .
// Perform displacement
position += CalculateDisplacement(UV, normal);
The distance that the vertices are moved depends not only on the sampled displacement
value, but also on the value of the newly created DisplaceScale property in the per
material constant buffer. The meshes used in this project all require different scales for
optimal display. Ideally, this value would be stored with the mesh, or the models and
displacement maps would all be created with the same scale in mind.
// Sample height map - using Red channel
float height = DisplacementMap.SampleLevel(Sampler, UV, mipLevel).r;
// remap height from 0 to 1, to -1 to 1 (with midlevel offset)
... SNIP
// Return offset along normal.
return height * DisplaceScale * normal;
 
Search WWH ::




Custom Search