Graphics Reference
In-Depth Information
result.WorldNormal = mul(vertex.Normal,
(float3x3)WorldInverseTranspose);
// transform input position to world
result.WorldPosition = mul(vertex.Position, World).xyz;
return result;
}
As we are now making use of the World matrix, it makes more sense to
split the WorldViewProjection matrix and place the ViewProjection
part into the PerFrame constant buffer, saving on bandwidth. We would then
calculate the value of result.WorldPosition first and then multiply
this by the ViewProjection matrix to calculate the final result.
Position matrix.
For simplicity, our recipes will continue to keep the matrices grouped together.
8.
Next, we add our simple pixel shader, as derived earlier, in SimplePS.hlsl with the
following code:
#include "Common.hlsl"
// A simple Pixel Shader that simply passes through the
// interpolated color
float4 PSMain(PixelShaderInput pixel) : SV_Target
{
return pixel.Diffuse;
}
9.
To demonstrate the reuse of existing structures, we will implement a second pixel
shader for visualizing the depth information in DepthPS.hlsl .
#include "Common.hlsl"
float4 PSMain(PixelShaderInput pixel) : SV_Target {
// Take the (Z / W) and use as color, this gives the depth.
// Items close to the near clip-plane will be darker than
// those near the far clip-plane. Note depth is non-linear
float4 output = float4(pixel.Position.z, 0, 0, 1);
return output;
}
Play with different values for the near clip plane in the projection matrix
in D3DApp to see how this impacts the depth buffer.
We now need to define the new C# structures in our application in order to update
the constant buffers.
 
Search WWH ::




Custom Search