Graphics Reference
In-Depth Information
// Determine decal world position
float3 decalPosWorld = mul(float4(DecalPosition, 1),
World).xyz;
// Calculate distance from vertex to decal
float distanceToDecal = distance(worldPosition,
decalPosWorld);
// if distance to the decal position is within radius
// then we need to perform displacement based on decal
if (distanceToDecal <= DecalRadius)
{
... SNIP see below
}
return result;
}
Within the if (distanceToDecal <= DecalRadius){…} block of the
DecalDisplacement function, if the distance to the decal from the current
vertex is within the decal radius we need to do the following:
5.
Determine the current decal UV coordinate based upon the decal's normal/tangent/
bitangent and the difference between the vertex position and decal position.
// Convert vectors to world space
float3 dT = normalize(mul(DecalTangent,
(float3x3)WorldInverseTranspose));
float3 dB = normalize(mul(DecalBitangent,
(float3x3)WorldInverseTranspose));
float3 dN = normalize(mul(DecalNormal,
(float3x3)WorldInverseTranspose));
float3x3 worldToDecal = float3x3(dT, dB, dN);
decalUV = mul(worldToDecal, worldPosition - decalPosWorld);
// Remap to range between 0 and 1
decalUV /= 2 * DecalRadius; // (-0.5,0.5)
decalUV += 0.5; // (0,1)
// z=1 tells pixel shader to sample decal diffuse texture
decalUV.z = 1.0;
6.
Sample the displacement value and perform the displacement in the same way as we
did for regular displacement mapping.
// Choose the most detailed mipmap level
const float mipLevel = 1.0f;
// Sample height map - using R channel
 
Search WWH ::




Custom Search