Graphics Reference
In-Depth Information
public float _padding1;
public Vector3 DecalPosition;
public float DecalRadius;
}
14. Within D3DApp.cs , create the new private member fields to hold the decal buffer
and textures:
// A buffer that is used to update the displacement decal
Buffer decalBuffer;
ShaderResourceView decalDiffuse;
ShaderResourceView decalDisplacement;
ShaderResourceView decalNormal;
15. Within D3DApp.CreateDeviceDependentResources , add the obligatory
RemoveAndDispose calls for these new properties; and after the existing
constant buffers, initialize, the new resources as follows:
// Create the decal buffer
decalBuffer = ToDispose(new Buffer(device, Utilities.
SizeOf<ConstantBuffers.DecalBuffer>(), ResourceUsage.
Default, BindFlags.ConstantBuffer, CpuAccessFlags.None,
ResourceOptionFlags.None, 0));
// Load the decal textures
decalDiffuse = ToDispose(ShaderResourceView.FromFile(
device, "Crater_Diffuse.png"));
decalDisplacement = ToDispose(ShaderResourceView.FromFile(
device, "Crater_Displacement.png"));
decalNormal = ToDispose(ShaderResourceView.FromFile(
device, "Crater_Normal.png"));
16. Next, apply the constant buffer to the shader stages (remember that we used
the b4 constant buffer slot in the shader code):
// Add the decal buffer to the pixel, hull and domain
// shaders (it uses the 5th slot 0-indexed)
context.HullShader.SetConstantBuffer(4, decalBuffer);
context.DomainShader.SetConstantBuffer(4, decalBuffer);
context.PixelShader.SetConstantBuffer(4, decalBuffer);
17. As our DisplacementMeshRenderer class will clear the pixel shader resources,
we will make its textureViews property publicly available so that we can assign
the decal shader resources to the active mesh:
public List<ShaderResourceView> TextureViews
{ get { return textureViews; } }
 
Search WWH ::




Custom Search