-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexShader.hlsl
58 lines (49 loc) · 1.39 KB
/
VertexShader.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
cbuffer CB2 : register(b1)
{
float4x4 m_view;
float4x4 m_projection;
}
cbuffer CB3 : register(b2)
{
float4x4 m_world;
float4x4 m_normals;
}
/* Vertex Shader Input */
struct VS_IN
{
float3 position_local : POSITION; // POSITION Semantic
float2 tex : TEXTURE;
float3 normal : NORMAL;
};
/* Vertex Shader Output (Pixel Shader Input) */
struct VS_OUT
{
float4 position_clip : SV_POSITION;
float3 world_position : POSITION;
float3 normal : NORMAL;
};
// Vertex Shader Entry Point - Takes VS_IN and outputs a VS_OUT
// Takes a position in local coordinates, and translates them to clipping
// coordinates
//
// Vertex Shaders MUST output a float4 XYZW setting a vertex's position in homogeneous clip space
// Must be between -1 and 1 on X and Y axes, and 0 and 1 on Z (positive into the screen).
// Homogeneous coordiantes are identified by the SV_POSITION semantic
VS_OUT vs_main(VS_IN input)
{
// Zero the Memory
VS_OUT output = (VS_OUT) 0;
float4 pos = float4(input.position_local, 1.0f);
float4 norm = float4(input.normal, 1.0f);
// Find World Position
pos = mul(m_world, pos);
output.world_position = pos.xyz;
// Find Clipping Position
pos = mul(m_view, pos);
pos = mul(m_projection, pos);
output.position_clip = pos;
// Find normal
norm = mul(m_normals, norm);
output.normal = norm.xyz;
return output;
}