forked from vixorien/AdvancedDX11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexShader.hlsl
61 lines (51 loc) · 1.55 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
59
60
61
cbuffer perFrame : register(b0)
{
matrix view;
matrix projection;
}
cbuffer perMaterial : register(b1)
{
float2 uvScale;
}
cbuffer perObject : register(b2)
{
matrix world;
matrix worldInverseTranspose;
}
// 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 normal is in WORLD space, not "local" space
output.normal = normalize(mul((float3x3)worldInverseTranspose, input.normal));
output.tangent = normalize(mul((float3x3)worldInverseTranspose, input.tangent));
// Pass through the uv
output.uv = input.uv * uvScale;
return output;
}