Graphics Reference
In-Depth Information
Getting ready
For this recipe, we need to render a plane along the x and z axis. The completed solution uses
an FBX scene with a simple subdivided mesh and UV coordinates for a normal map, however,
a quad passed to the tessellation pipeline will also work; or better yet, a mesh generated in
the vertex shader based on the SV_VertexID and SV_InstanceID input semantics.
A prerequisite is the mesh renderer and shaders that implement normal mapping as shown
in the Adding surface detail with normal mapping recipe of Chapter 6 , Adding Surface Detail
with Normal and Displacement Mapping .
How to do it…
As we will be generating sine waves over a period of time, we need to add a Time property
to our PerFrame constant buffer. Then we will implement the vertex displacement within
a vertex shader. Consider the following steps:
1.
Within Common.hlsl , update the PerFrame structure (as shown in the
highlighted section of the following code):
cbuffer PerFrame: register (b1)
{
DirectionalLight Light;
float3 CameraPosition;
float Time;
};
2.
Within your ConstantBuffers.cs file, update the matching PerFrame
structure to include the time component.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PerFrame
{
public DirectionalLight Light;
public SharpDX.Vector3 CameraPosition;
public float Time;
}
3.
Within the render loop, update the code for setting up the perFrame constant
buffer, by setting up the Time property.
perFrame.CameraPosition = cameraPosition;
// Provide simulation time to shader
perFrame.Time = (float)simTime.Elapsed.TotalSeconds;
context.UpdateSubresource(ref perFrame, perFrameBuffer);
 
Search WWH ::




Custom Search