-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicTransform_vs.hlsl
33 lines (25 loc) · 1.81 KB
/
BasicTransform_vs.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//--------------------------------------------------------------------------------------
// Light Model Vertex Shader
//--------------------------------------------------------------------------------------
// Basic matrix transformations only
#include "Common.hlsli" // Shaders can also use include files - note the extension
//--------------------------------------------------------------------------------------
// Shader code
//--------------------------------------------------------------------------------------
// Vertex shader gets vertices from the mesh one at a time. It transforms their positions
// from 3D into 2D (see lectures) and passes that position down the pipeline so pixels can be rendered.
SimplePixelShaderInput main(BasicVertex modelVertex)
{
SimplePixelShaderInput output; // This is the data the pixel shader requires from this vertex shader
// Input position is x,y,z only - need a 4th element to multiply by a 4x4 matrix. Use 1 for a point (0 for a vector) - recall lectures
float4 modelPosition = float4(modelVertex.position, 1);
// Multiply by the world matrix passed from C++ to transform the model vertex position into world space.
// In a similar way use the view matrix to transform the vertex from world space into view space (camera's point of view)
// and then use the projection matrix to transform the vertex to 2D projection space (project onto the 2D screen)
float4 worldPosition = mul(gWorldMatrix, modelPosition);
float4 viewPosition = mul(gViewMatrix, worldPosition);
output.projectedPosition = mul(gProjectionMatrix, viewPosition);
// Pass texture coordinates (UVs) on to the pixel shader, the vertex shader doesn't need them
output.uv = modelVertex.uv;
return output; // Ouput data sent down the pipeline (to the pixel shader)
}