-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathSkyVS.hlsl
57 lines (48 loc) · 1.8 KB
/
SkyVS.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
// 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)
{
matrix view;
matrix projection;
}
// Struct representing a single vertex worth of data
struct VertexShaderInput
{
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
{
float4 position : SV_POSITION; // XYZW position (System Value Position)
float3 sampleDir : DIRECTION;
};
// --------------------------------------------------------
// The entry point (main method) for our vertex shader
// --------------------------------------------------------
VertexToPixel main(VertexShaderInput input)
{
// Set up output struct
VertexToPixel output;
// Modify the view matrix and remove the translation portion
matrix viewNoTranslation = view;
viewNoTranslation._14 = 0;
viewNoTranslation._24 = 0;
viewNoTranslation._34 = 0;
// Multiply the view (without translation) and the projection
matrix vp = mul(projection, viewNoTranslation);
output.position = mul(vp, float4(input.position, 1.0f));
// For the sky vertex to be ON the far clip plane
// (a.k.a. as far away as possible but still visible),
// we can simply set the Z = W, since the xyz will
// automatically be divided by W in the rasterizer
output.position.z = output.position.w;
// Use the vert's position as the sample direction for the cube map!
output.sampleDir = input.position;
// 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;
}