forked from doodlum/skyrim-community-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sky.hlsl
221 lines (173 loc) · 5.58 KB
/
Sky.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#if defined(DEFERRED)
# undef CLOUD_SHADOWS
#endif
struct VS_INPUT
{
float4 Position : POSITION0;
#if defined(TEX) || defined(HORIZFADE)
float2 TexCoord : TEXCOORD0;
#endif
float4 Color : COLOR0;
};
struct VS_OUTPUT
{
float4 Position : SV_POSITION0;
#if defined(DITHER) && defined(TEX)
float4 TexCoord0 : TEXCOORD0;
#elif defined(DITHER)
float2 TexCoord0 : TEXCOORD3;
#elif defined(TEX) || defined(HORIZFADE)
float2 TexCoord0 : TEXCOORD0;
#endif
#if defined(TEXLERP)
float2 TexCoord1 : TEXCOORD1;
#endif
#if defined(HORIZFADE)
float TexCoord2 : TEXCOORD2;
#endif
#if defined(TEX) || defined(DITHER) || defined(HORIZFADE)
float4 Color : COLOR0;
#endif
float4 WorldPosition : POSITION1;
float4 PreviousWorldPosition : POSITION2;
};
#ifdef VSHADER
cbuffer PerGeometry : register(b2)
{
row_major float4x4 WorldViewProj : packoffset(c0);
row_major float4x4 World : packoffset(c4);
row_major float4x4 PreviousWorld : packoffset(c8);
float3 EyePosition : packoffset(c12);
float VParams : packoffset(c12.w);
float4 BlendColor[3] : packoffset(c13);
float2 TexCoordOff : packoffset(c16);
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT vsout;
float4 inputPosition = float4(input.Position.xyz, 1.0);
# if defined(OCCLUSION)
// Intentionally left blank
# elif defined(MOONMASK)
vsout.TexCoord0 = input.TexCoord;
vsout.Color = float4(VParams.xxx, 1.0);
# elif defined(HORIZFADE)
float worldHeight = mul(World, inputPosition).z;
float eyeHeightDelta = -EyePosition.z + worldHeight;
vsout.TexCoord0.xy = input.TexCoord;
vsout.TexCoord2.x = saturate((1.0 / 17.0) * eyeHeightDelta);
vsout.Color.xyz = BlendColor[0].xyz * VParams;
vsout.Color.w = BlendColor[0].w;
# else // MOONMASK HORIZFADE
# if defined(DITHER)
# if defined(TEX)
vsout.TexCoord0.xyzw = input.TexCoord.xyxy * float4(1.0, 1.0, 501.0, 501.0);
# else
float3 inputDirection = normalize(input.Position.xyz);
inputDirection.y += inputDirection.z;
vsout.TexCoord0.x = 501 * acos(inputDirection.x);
vsout.TexCoord0.y = 501 * asin(inputDirection.y);
# endif // TEX
# elif defined(CLOUDS)
vsout.TexCoord0.xy = TexCoordOff + input.TexCoord;
# else
vsout.TexCoord0.xy = input.TexCoord;
# endif // DITHER CLOUDS
# ifdef TEXLERP
vsout.TexCoord1.xy = TexCoordOff + input.TexCoord;
# endif // TEXLERP
float3 skyColor = BlendColor[0].xyz * input.Color.xxx + BlendColor[1].xyz * input.Color.yyy +
BlendColor[2].xyz * input.Color.zzz;
vsout.Color.xyz = VParams * skyColor;
vsout.Color.w = BlendColor[0].w * input.Color.w;
# endif // OCCLUSION MOONMASK HORIZFADE
vsout.Position = mul(WorldViewProj, inputPosition).xyww;
vsout.WorldPosition = mul(World, inputPosition);
vsout.PreviousWorldPosition = mul(PreviousWorld, inputPosition);
return vsout;
}
#endif
typedef VS_OUTPUT PS_INPUT;
struct PS_OUTPUT
{
float4 Color : SV_Target0;
float2 MotionVectors : SV_Target1;
float4 Normal : SV_Target2;
#if defined(CLOUD_SHADOWS) && defined(CLOUDS)
float4 CloudShadows : SV_Target3;
#endif
};
#ifdef PSHADER
SamplerState SampBaseSampler : register(s0);
SamplerState SampBlendSampler : register(s1);
SamplerState SampNoiseGradSampler : register(s2);
Texture2D<float4> TexBaseSampler : register(t0);
Texture2D<float4> TexBlendSampler : register(t1);
Texture2D<float4> TexNoiseGradSampler : register(t2);
cbuffer PerFrame : register(b12)
{
float4 UnknownPerFrame1[12] : packoffset(c0);
row_major float4x4 ScreenProj : packoffset(c12);
row_major float4x4 PreviousScreenProj : packoffset(c16);
}
cbuffer PerGeometry : register(b2)
{
float2 PParams : packoffset(c0);
};
cbuffer AlphaTestRefCB : register(b11)
{
float AlphaTestRefRS : packoffset(c0);
}
PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;
# ifndef OCCLUSION
# ifndef TEXLERP
float4 baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord0.xy);
# ifdef TEXFADE
baseColor.w *= PParams.x;
# endif
# else
float4 blendColor = TexBlendSampler.Sample(SampBlendSampler, input.TexCoord1.xy);
float4 baseColor = TexBaseSampler.Sample(SampBaseSampler, input.TexCoord0.xy);
baseColor = PParams.xxxx * (-baseColor + blendColor) + baseColor;
# endif
# if defined(DITHER)
float2 noiseGradUv = float2(0.125, 0.125) * input.Position.xy;
float noiseGrad =
TexNoiseGradSampler.Sample(SampNoiseGradSampler, noiseGradUv).x * 0.03125 + -0.0078125;
# ifdef TEX
psout.Color.xyz = (input.Color.xyz * baseColor.xyz + PParams.yyy) + noiseGrad;
psout.Color.w = baseColor.w * input.Color.w;
# else
psout.Color.xyz = (PParams.yyy + input.Color.xyz) + noiseGrad;
psout.Color.w = input.Color.w;
# endif // TEX
# elif defined(MOONMASK)
psout.Color.xyzw = baseColor;
if (baseColor.w - AlphaTestRefRS.x < 0) {
discard;
}
# elif defined(HORIZFADE)
psout.Color.xyz = float3(1.5, 1.5, 1.5) * (input.Color.xyz * baseColor.xyz + PParams.yyy);
psout.Color.w = input.TexCoord2.x * (baseColor.w * input.Color.w);
# else
psout.Color.w = input.Color.w * baseColor.w;
psout.Color.xyz = input.Color.xyz * baseColor.xyz + PParams.yyy;
# endif
# else
psout.Color = float4(0, 0, 0, 1.0);
# endif // OCCLUSION
float4 screenPosition = mul(ScreenProj, input.WorldPosition);
screenPosition.xy = screenPosition.xy / screenPosition.ww;
float4 previousScreenPosition = mul(PreviousScreenProj, input.PreviousWorldPosition);
previousScreenPosition.xy = previousScreenPosition.xy / previousScreenPosition.ww;
float2 screenMotionVector = float2(-0.5, 0.5) * (screenPosition.xy - previousScreenPosition.xy);
psout.MotionVectors = screenMotionVector;
psout.Normal = float4(0.5, 0.5, 0, 0);
# if defined(CLOUD_SHADOWS) && defined(CLOUDS)
psout.CloudShadows = psout.Color;
# endif
return psout;
}
#endif