Graphics Reference
In-Depth Information
Texture2D DecalDiffuse : register(t3);
Texture2D DecalNormalMap : register(t4);
// Assumes that SamplerState Sampler : register(s0); exists
3.
Now, add our new DecalBuffer constant buffer (note that we use the fifth constant
buffer slot b4 ).
// Controls the decal displacement
cbuffer DecalBuffer : register(b4) {
float DecalDisplaceScale; // If 0 no decal applied
float3 DecalNormal;// If normal is 0 no decal applied
float3 DecalTangent; // used to determine texcoord
float3 DecalBitangent;// used to determine texcoord
float3 DecalPosition; // decal position in local space
float DecalRadius; // decal size
}
4.
We will create three new functions: one for sampling the normal, one for sampling the
diffuse, and one for calculating the displacement.
float3 DecalNormalSample(float2 decalUV)
{
return DecalNormalMap.Sample(Sampler, decalUV).rgb;
}
float4 DecalDiffuseSample(float2 decalUV)
{
return DecalDiffuse.Sample(Sampler, decalUV).rgba;
}
// The float3 result should be added to the vertex position
float3 DecalDisplacement(float3 worldNormal, float3 worldPosition,
out float3 decalUV)
{
float3 result = (float3)0;
// Note: if the decalUV.z == 0 the pixel shader will
// assume no decal map needs to be queried
decalUV = (float3)0;
// Skip displacement sampling if 0 multiplier or if the
// decal normal is not set
if (DecalDisplaceScale == 0 || (DecalNormal.x == 0.0 &&
DecalNormal.y == 0.0 && DecalNormal.z == 0))
return result;
 
Search WWH ::




Custom Search