-
Notifications
You must be signed in to change notification settings - Fork 13
/
VertexShader.hlsl
54 lines (45 loc) · 1.53 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
// Constant Buffer for external (C++) data
cbuffer externalData : register(b0)
{
matrix world;
matrix worldInverseTranspose;
matrix view;
matrix projection;
};
// Struct representing a single vertex worth of data
struct VertexShaderInput
{
float3 position : POSITION;
float2 uv : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
};
// Out of the vertex shader (and eventually input to the PS)
struct VertexToPixel
{
float4 screenPosition : SV_POSITION;
float2 uv : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 worldPos : POSITION; // The world position of this vertex
};
// --------------------------------------------------------
// The entry point (main method) for our vertex shader
// --------------------------------------------------------
VertexToPixel main(VertexShaderInput input)
{
// Set up output
VertexToPixel output;
// Calculate output position
matrix worldViewProj = mul(projection, mul(view, world));
output.screenPosition = mul(worldViewProj, float4(input.position, 1.0f));
// Calculate the world position of this vertex (to be used
// in the pixel shader when we do point/spot lights)
output.worldPos = mul(world, float4(input.position, 1.0f)).xyz;
// Make sure the other vectors are in WORLD space, not "local" space
output.normal = normalize(mul((float3x3)worldInverseTranspose, input.normal));
output.tangent = normalize(mul((float3x3)world, input.tangent)); // Tangent doesn't need inverse transpose!
// Pass the UV through
output.uv = input.uv;
return output;
}