Graphics Reference
In-Depth Information
Getting ready
We'll continue from where we left off the last recipe, Rendering a cube and sphere .
We will use the static class Common.HLSLCompiler from the sample rendering framework
that wraps the Direct3D HLSL compiler and supports the use of an HLSL include handler.
How to do it…
We will reimplement our shaders, adding support for the normal vector in the vertex buffer
and extend our constant buffers. We will then split our shader code across multiple files; this
will make it easier to create pixel shaders for different shading techniques.
1.
First right-click on the project in the Solution Explorer and select New Folder in Add
and name it Shaders . Now create four new text files in this folder named Common.
hlsl , VS.hlsl , SimplePS.hlsl , and DepthPS.hlsl . Remember to change
the text encoding to ANSI and to select Copy if newer as described in Chapter 2 ,
Rendering with Direct3D .
2.
With Common.hlsl opened, we will add our new vertex shader structure, adding the
new property TextureUV .
struct VertexShaderInput
{
float4 Position : SV_Position;// Position
float3 Normal : NORMAL ; // Normal - for lighting
float4 Color : COLOR0; // Vertex color
float2 TextureUV: TEXCOORD ; // Texture UV coordinate
};
3.
Also add the new pixel shader input structure along with a new property for the
UV coordinate:
struct PixelShaderInput
{
float4 Position : SV_Position;
// Interpolation of vertex * material diffuse
float4 Diffuse : COLOR;
// Interpolation of vertex UV texture coordinate
float2 TextureUV: TEXCOORD;
// We need the World Position and normal for lighting
float3 WorldNormal : NORMAL;
float3 WorldPosition : WORLDPOS;
};
 
Search WWH ::




Custom Search