-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadowEnvironment_VS.hlsl
64 lines (47 loc) · 1.11 KB
/
shadowEnvironment_VS.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
cbuffer EnvironmentBufferType
{
float3 cameraPosition;
matrix worldMatrix;
matrix MVP;
};
struct vertexInput
{
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
struct pixelInput
{
float4 position : SV_POSITION;
float4 positionNDC : TEXCOOR0;
float2 tex : TEXCOORD1;
float4 RVector : TEXCOOR2;
float3 normal : NORMAL;
};
float4 RVector(float4 normal, float4 v) {
float cos;
float4 s, r;
cos = dot(normal, v);
s = normal * cos;
r = (s * 2) - v;
return r;
}
pixelInput main(vertexInput input)
{
float4 v, e, wrdNormal, wrdVertex;
pixelInput output;
wrdVertex = float4(input.position, 1.f);
wrdVertex = mul(wrdVertex, worldMatrix);
output.position = float4(input.position, 1.f);
output.position = mul(output.position, MVP);
output.positionNDC = output.position;
output.tex = input.tex;
wrdNormal = float4(input.normal, 1.f);
wrdNormal = mul(wrdNormal, worldMatrix);
wrdNormal = normalize(wrdNormal);
output.normal = wrdNormal.xyz;
e = float4(cameraPosition, 1.f);
v = normalize(e - wrdVertex);
output.RVector = RVector(wrdNormal, v);
return output;
}