Graphics Reference
In-Depth Information
How it works…
Basically, displacement decals work in the same way as regular displacement mapping.
The main differences are that the existence and location of the decal is dependent upon
information passed into a constant buffer, and the UV coordinates for the displacement/
normal and diffuse sampling are determined based on the difference between the current
vertex position and decal position.
Reviewing the tangent space that we covered in Adding surface detail with normal mapping ,
we can see how the normal, tangent, and bitangent vectors that we assign to the decal
constant buffer are controlling the orientation (rotation and angle) of the decal on the
surface it is applied.
The example decal position and tangent vectors in the code for this recipe will result in no
decal appearing on the plane. This is not only due to the position not meeting the surface,
but also because the angle of the decal will look odd. The following code snippet includes
values that will appear on the plane in the example scene:
Vector3.Orthonormalize(decalVectors, new[] {
new Vector3(0, 0.5f, 0.2f), Vector3.UnitX, Vector3.UnitZ });
decal.DecalPosition = new Vector3(0, 0, 0);
Our current implementation blends the two displacements together; although in certain
circumstances, such as the crater shown previously, you may want to replace the existing
displacement. This is easy enough to do; however, it is also necessary to blend the normal
correctly, otherwise the two surfaces will appear disjointed. A solution for this is to include
another channel in the decal displacement map that controls where and to what extent the
decal overrides the existing displacement and normal (functioning like an alpha channel).
There's more…
The constant buffer could be easily extended to support multiple decals by changing it
to an array of parameters. Chapter 4 , Animating Meshes with Vertex Skinning , has an
example of how to use arrays of elements in a constant buffer structure for the bones.
Currently we are just setting the decal properties directly in code; instead, we could have
this event based (for example, mouse click) and determine the correct location from there.
The decal constant buffer only needs to be updated when a decal is changed. If a significant
number of decals need to be supported, then it may be a better option to store the decal
properties within a regular buffer or texture.
Another interesting effect can be easily created by decreasing the decal displacement scale
over time to simulate a fading decal (for example, a fading footstep). However, you will want to
apply the same decay on the diffuse/normal texture samples.
 
Search WWH ::




Custom Search