Graphics Reference
In-Depth Information
float height = DecalDisplacementMap .SampleLevel(Sampler,
decalUV.xy , mipLevel).r;
// remap height from (0,1) to (-1, 1)
height = (2 * height) - 1;
// Return offset along DecalNormal. This allows the decal
// to be applied at an angle to the surface, e.g. to allow
// the direction of a bullet to decide the direction of
// deformation. Using the worldNormal instead will result
// in uniform decals.
result = height * DecalDisplaceScale * dN;// worldNormal;
7.
We now have the decal UV property that needs to be forwarded to the pixel shader.
For this, we add a new property to the PixelShaderInput structure within
Common.hlsl
float3 DecalUV: TEXCOORD5; // .z==1 means there is a decal
In the domain shaders that we want to support displacement decals, we can now
add the following:
8.
Include CommonDecal.hlsl after the other includes within the domain shader's
HLSL file:
#include "Common.hlsl"
#include "CommonTess.hlsl"
#include "CommonDecal.hlsl"
9.
After the existing displacement code in the domain shader, add a call to the
DecalDisplacement function we just created.
// Perform displacement
normal = normalize(normal);
position += CalculateDisplacement(UV, normal);
// Perform decal displacement
position += DecalDisplacement(normal, position,
result.DecalUV);
10. Next, we need to update each pixel shader that implements texture and normal map
sampling (for example, BlinnPhongPS.hlsl , DiffusePS.hlsl , and PhongPS.
hlsl ).
11. Then, we include the CommonDecal.hlsl shader file after Common.hlsl .
 
Search WWH ::




Custom Search