Graphics Reference
In-Depth Information
// If displace scale > 0 then assign texture resource
if (material.DisplaceScale > 0)
{
context.DomainShader.SetShaderResources(0,
textureViews[texIndxOffset+2]);
context.DomainShader.SetSampler(0, samplerState);
}
...
// Update material buffer
context.UpdateSubresource(ref material, PerMaterialBuffer);
Now, we will update
D3DApp.cs
to bind the per material constant buffer to the domain
shader stage, and use our new mesh renderer and properties in the render loop.
1.
First, add the
perMaterialBuffer
constant buffer to the domain shader stage
within
D3DApp.CreateDeviceDependentResources
(or the applicable location
where the pipeline state was initialized).
context.DomainShader.SetConstantBuffer(0, perObjectBuffer);
context.DomainShader.SetConstantBuffer(1, perFrameBuffer);
context.DomainShader.SetConstantBuffer(2,
perMaterialBuffer);
context.DomainShader.Set(tessellateTriDomainShader);
2.
Within
D3DApp.Run
, change the creation of the mesh renderers to use the new
DisplacedMeshRenderer
.
List<DisplacedMeshRenderer> meshes = new
List<DisplacedMeshRenderer>();
meshes.AddRange((from mesh in loadedMesh
select ToDispose(new DisplacedMeshRenderer(mesh))));
3.
And lastly, we will change the mesh rendering within the render loop so that we are
setting the mesh properties with our desired values.
var m = meshes[meshIndex]; // show one mesh at a time
m.EnableNormalMap =
enableNormalMap;
m.DisplacementScale =
displacementScale;
m.PerMaterialBuffer = perMaterialBuffer;
m.PerArmatureBuffer = perArmatureBuffer;
m.Render();
The completed sample maps
Shift
+
/
-
to increase and decrease the
displacement scale and
Shift
+
N
to toggle the normal map on/off.