forked from vixorien/AdvancedDX11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerrainVS.hlsl
73 lines (63 loc) · 2.14 KB
/
TerrainVS.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
62
63
64
65
66
67
68
69
70
71
72
73
// The variables defined in this cbuffer will pull their data from the
// constant buffer (ID3D11Buffer) bound to "vertex shader constant buffer slot 0"
// It was bound using context->VSSetConstantBuffers() over in C++.
cbuffer ExternalData : register(b0)
{
float4 colorTint;
matrix world;
matrix view;
matrix proj;
}
// Struct representing a single vertex worth of data
struct VertexShaderInput
{
// Data type
// |
// | Name Semantic
// | | |
// v v v
float3 position : POSITION; // XYZ position
float2 uv : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
};
// Struct representing the data we're sending down the pipeline
struct VertexToPixel
{
// Data type
// |
// | Name Semantic
// | | |
// v v v
float4 position : SV_POSITION; // XYZW position (System Value Position)
float4 color : COLOR; // RGBA color
float2 uv : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 worldPos : POSITION;
};
// --------------------------------------------------------
// The entry point (main method) for our vertex shader
// --------------------------------------------------------
VertexToPixel main(VertexShaderInput input)
{
// Set up output struct
VertexToPixel output;
// Modifying the position using the provided transformation (world) matrix
matrix wvp = mul(proj, mul(view, world));
output.position = mul(wvp, float4(input.position, 1.0f));
// Calculate the final world position of the vertex
output.worldPos = mul(world, float4(input.position, 1.0f)).xyz;
// Modify the normal so its also in world space
output.normal = mul((float3x3)world, input.normal);
output.normal = normalize(output.normal);
// Modify the tangent much like the normal
output.tangent = mul((float3x3)world, input.tangent);
output.tangent = normalize(output.tangent);
// Tints the color before passing it through
output.color = colorTint;
output.uv = input.uv;
// Whatever we return will make its way through the pipeline to the
// next programmable stage we're using (the pixel shader for now)
return output;
}