forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkyVertexShader.hlsl
More file actions
41 lines (34 loc) · 1.44 KB
/
SkyVertexShader.hlsl
File metadata and controls
41 lines (34 loc) · 1.44 KB
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
#include "structs.hlsli"
cbuffer ExternalData : register(b0) // b0 means the first buffer register
{
matrix view;
matrix projection;
}
// --------------------------------------------------------
// 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
// --------------------------------------------------------
SkyVertexToPixel main(VertexShaderInput input)
{
// Set up output struct
SkyVertexToPixel output;
// Create a copy of the view matrix and set the translation of it to all zeroes
matrix viewNoTrans = view;
viewNoTrans._14 = 0;
viewNoTrans._24 = 0;
viewNoTrans._34 = 0;
// Apply projection and updated view to the input position
matrix vp = mul(projection, viewNoTrans);
output.screenPosition = mul(vp, float4(input.localPosition, 1.0f));
// Ensure that the output depth will be 1.0 after the shader
// After automatic persp. divide, which divides w/z, z will be 1.0 if z & w are equal
output.screenPosition.z = output.screenPosition.w;
// The sample direction is from 0,0,0 to the vertex's position, so sample dir is an easy answer!
output.sampleDir = input.localPosition;
// 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;
}