Graphics Reference
In-Depth Information
4.
We will extend upon our previous per object constant buffer, adding the World and
WorldInverseTranspose matrices.
// Constant buffer to be updated by application per object
cbuffer PerObject : register(b0)
{
// WorldViewProjection matrix
float4x4 WorldViewProjection;
// We need the world matrix so that we can
// calculate the lighting in world space
float4x4 World;
// Inverse transpose of world, used for
// bringing normals into world space, especially
// necessary where non-uniform scaling has been applied
float4x4 WorldInverseTranspose;
};
5. And finally, we will add a new per frame constant buffer. This will be updated to
include additional per frame information, such as lighting; however, for now this
will contain the camera position only. Note that this uses the constant buffer slot b1 .
cbuffer PerFrame: register (b1)
{
float3 CameraPosition;
};
6.
We will now code our new vertex shader in VS.hlsl . To reference the Common.hlsl
class, add the HLSL include directive.
#include "Common.hlsl"
7.
Then insert our new VSMain implementation.
PixelShaderInput VSMain(VertexShaderInput vertex)
{
PixelShaderInput result = (PixelShaderInput)0;
// Apply WVP matrix transformation
result.Position = mul(vertex.Position,
WorldViewProjection);
result.Diffuse = vertex.Color;
result.TextureUV = vertex.TextureUV;
// transform normal to world space
 
Search WWH ::




Custom Search