forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertexShader.hlsl
64 lines (58 loc) · 2.58 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
62
63
64
// Struct representing a single vertex worth of data
// - This should match the vertex definition in our C++ code
// - By "match", I mean the size, order and number of members
// - The name of the struct itself is unimportant, but should be descriptive
// - Each variable must have a semantic, which defines its usage
struct VertexShaderInput
{
// Data type
// |
// | Name Semantic
// | | |
// v v v
float3 localPosition : POSITION; // XYZ position
float4 color : COLOR; // RGBA color
};
// Struct representing the data we're sending down the pipeline
// - Should match our pixel shader's input (hence the name: Vertex to Pixel)
// - At a minimum, we need a piece of data defined tagged as SV_POSITION
// - The name of the struct itself is unimportant, but should be descriptive
// - Each variable must have a semantic, which defines its usage
struct VertexToPixel
{
// Data type
// |
// | Name Semantic
// | | |
// v v v
float4 screenPosition : SV_POSITION; // XYZW position (System Value Position)
float4 color : COLOR; // RGBA color
};
// --------------------------------------------------------
// The entry point (main method) for our vertex shader
//
// - Input is exactly one vertex worth of data (defined by a struct)
// - Output is a single struct of data to pass down the pipeline
// - Named "main" because that's the default the shader compiler looks for
// --------------------------------------------------------
VertexToPixel main( VertexShaderInput input )
{
// Set up output struct
VertexToPixel output;
// Here we're essentially passing the input position directly through to the next
// stage (rasterizer), though it needs to be a 4-component vector now.
// - To be considered within the bounds of the screen, the X and Y components
// must be between -1 and 1.
// - The Z component must be between 0 and 1.
// - Each of these components is then automatically divided by the W component,
// which we're leaving at 1.0 for now (this is more useful when dealing with
// a perspective projection matrix, which we'll get to in the future).
output.screenPosition = float4(input.localPosition, 1.0f);
// Pass the color through
// - The values will be interpolated per-pixel by the rasterizer
// - We don't need to alter it here, but we do need to send it to the pixel shader
output.color = input.color;
// 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;
}