-
Notifications
You must be signed in to change notification settings - Fork 774
/
GlobalIllumination.cs
332 lines (304 loc) · 12.8 KB
/
GlobalIllumination.cs
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
using System;
using UnityEngine.Serialization;
namespace UnityEngine.Rendering.HighDefinition
{
/// <summary>
/// A volume component that holds settings for the global illumination (screen space and ray traced).
/// </summary>
[Serializable, VolumeComponentMenuForRenderPipeline("Lighting/Screen Space Global Illumination", typeof(HDRenderPipeline))]
[HDRPHelpURLAttribute("Ray-Traced-Global-Illumination")]
public sealed class GlobalIllumination : VolumeComponentWithQuality
{
bool UsesQualityMode()
{
// The default value is set to quality. So we should be in quality if not overriden or we have an override set to quality
return (tracing.overrideState && tracing == RayCastingMode.RayTracing && (!mode.overrideState || (mode.overrideState && mode == RayTracingMode.Quality)));
}
#region General
/// <summary>
/// Enable screen space global illumination.
/// </summary>
[Tooltip("Enable screen space global illumination.")]
public BoolParameter enable = new BoolParameter(false);
/// <summary>
/// </summary>
[Tooltip("Controls the casting technique used to evaluate the effect. Ray marching uses a ray-marched screen-space solution, Ray tracing uses a hardware accelerated world-space solution. Mixed uses first Ray marching, then Ray tracing if it fails to intersect on-screen geometry.")]
public RayCastingModeParameter tracing = new RayCastingModeParameter(RayCastingMode.RayMarching);
#endregion
#region RayMarching
/// <summary>
/// Controls the fallback hierarchy for SSGI.
/// </summary>
public RayMarchingFallbackHierarchyParameter fallbackHierarchy = new RayMarchingFallbackHierarchyParameter(RayMarchingFallbackHierarchy.ReflectionProbesAndSky);
/// <summary>
/// The thickness of the depth buffer value used for the ray marching step
/// </summary>
[Tooltip("Controls the thickness of the depth buffer used for ray marching.")]
public ClampedFloatParameter depthBufferThickness = new ClampedFloatParameter(0.1f, 0.0f, 0.5f);
GlobalIllumination()
{
displayName = "Screen Space Global Illumination";
}
/// <summary>
/// The number of steps that should be used during the ray marching pass.
/// </summary>
public int maxRaySteps
{
get
{
if (!UsesQualitySettings())
return m_MaxRaySteps.value;
else
return GetLightingQualitySettings().SSGIRaySteps[(int)quality.value];
}
set { m_MaxRaySteps.value = value; }
}
[SerializeField]
[Tooltip("Controls the number of steps used for ray marching.")]
private MinIntParameter m_MaxRaySteps = new MinIntParameter(32, 0);
// Filtering
/// <summary>
/// Defines if the screen space global illumination should be denoised.
/// </summary>
public bool denoiseSS
{
get
{
if (!UsesQualitySettings())
return m_DenoiseSS.value;
else
return GetLightingQualitySettings().SSGIDenoise[(int)quality.value];
}
set { m_DenoiseSS.value = value; }
}
[SerializeField, FormerlySerializedAs("denoise")]
private BoolParameter m_DenoiseSS = new BoolParameter(true);
/// <summary>
/// Defines if the denoiser should be evaluated at half resolution.
/// </summary>
public bool halfResolutionDenoiserSS
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_HalfResolutionDenoiserSS.value;
else
return GetLightingQualitySettings().SSGIHalfResDenoise[(int)quality.value];
}
set { m_HalfResolutionDenoiserSS.value = value; }
}
[SerializeField]
[Tooltip("Use a half resolution denoiser.")]
private BoolParameter m_HalfResolutionDenoiserSS = new BoolParameter(false);
/// <summary>
/// Controls the radius of the global illumination denoiser (First Pass).
/// </summary>
public float denoiserRadiusSS
{
get
{
if (!UsesQualitySettings())
return m_DenoiserRadiusSS.value;
else
return GetLightingQualitySettings().SSGIDenoiserRadius[(int)quality.value];
}
set { m_DenoiserRadiusSS.value = value; }
}
[SerializeField]
[Tooltip("Controls the radius of the GI denoiser (First Pass).")]
private ClampedFloatParameter m_DenoiserRadiusSS = new ClampedFloatParameter(0.6f, 0.001f, 1.0f);
/// <summary>
/// Defines if the second denoising pass should be enabled.
/// </summary>
public bool secondDenoiserPassSS
{
get
{
if (!UsesQualitySettings())
return m_SecondDenoiserPassSS.value;
else
return GetLightingQualitySettings().SSGISecondDenoise[(int)quality.value];
}
set { m_SecondDenoiserPassSS.value = value; }
}
[SerializeField]
[Tooltip("Enable second denoising pass.")]
private BoolParameter m_SecondDenoiserPassSS = new BoolParameter(true);
#endregion
#region RayTracing
/// <summary>
/// Defines the layers that GI should include.
/// </summary>
[Tooltip("Defines the layers that GI should include.")]
public LayerMaskParameter layerMask = new LayerMaskParameter(-1);
/// <summary>
/// The LOD Bias HDRP applies to textures in the global illumination.
/// </summary>
[Tooltip("The LOD Bias HDRP applies to textures in the global illumination. A higher value increases performance and makes denoising easier, but it might reduce visual fidelity.")]
public ClampedIntParameter textureLodBias = new ClampedIntParameter(7, 0, 7);
/// <summary>
/// Controls the length of GI rays.
/// </summary>
public float rayLength
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_RayLength.value;
else
return GetLightingQualitySettings().RTGIRayLength[(int)quality.value];
}
set { m_RayLength.value = value; }
}
[SerializeField, FormerlySerializedAs("rayLength")]
private MinFloatParameter m_RayLength = new MinFloatParameter(50.0f, 0.01f);
/// <summary>
/// Controls the clamp of intensity.
/// </summary>
public float clampValue
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_ClampValue.value;
else
return GetLightingQualitySettings().RTGIClampValue[(int)quality.value];
}
set { m_ClampValue.value = value; }
}
[SerializeField, FormerlySerializedAs("clampValue")]
[Tooltip("Controls the clamp of intensity.")]
private ClampedFloatParameter m_ClampValue = new ClampedFloatParameter(1.0f, 0.001f, 10.0f);
/// <summary>
/// Controls which version of the effect should be used.
/// </summary>
[Tooltip("Controls which version of the effect should be used.")]
public RayTracingModeParameter mode = new RayTracingModeParameter(RayTracingMode.Quality);
// Performance
/// <summary>
/// Defines if the effect should be evaluated at full resolution.
/// </summary>
public bool fullResolution
{
get
{
if (!UsesQualitySettings())
return m_FullResolution.value;
else
return GetLightingQualitySettings().RTGIFullResolution[(int)quality.value];
}
set { m_FullResolution.value = value; }
}
[SerializeField, FormerlySerializedAs("fullResolution")]
[Tooltip("Full Resolution")]
private BoolParameter m_FullResolution = new BoolParameter(false);
// Quality
/// <summary>
/// Number of samples for evaluating the effect.
/// </summary>
[Tooltip("Number of samples for GI.")]
public ClampedIntParameter sampleCount = new ClampedIntParameter(2, 1, 32);
/// <summary>
/// Number of bounces for evaluating the effect.
/// </summary>
[Tooltip("Number of bounces for GI.")]
public ClampedIntParameter bounceCount = new ClampedIntParameter(1, 1, 8);
// Filtering
/// <summary>
/// Defines if the ray traced global illumination should be denoised.
/// </summary>
public bool denoise
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_Denoise.value;
else
return GetLightingQualitySettings().RTGIDenoise[(int)quality.value];
}
set { m_Denoise.value = value; }
}
[SerializeField, FormerlySerializedAs("denoise")]
[Tooltip("Denoise the ray-traced GI.")]
private BoolParameter m_Denoise = new BoolParameter(true);
/// <summary>
/// Defines if the denoiser should be evaluated at half resolution.
/// </summary>
public bool halfResolutionDenoiser
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_HalfResolutionDenoiser.value;
else
return GetLightingQualitySettings().RTGIHalfResDenoise[(int)quality.value];
}
set { m_HalfResolutionDenoiser.value = value; }
}
[SerializeField, FormerlySerializedAs("halfResolutionDenoiser")]
[Tooltip("Use a half resolution denoiser.")]
private BoolParameter m_HalfResolutionDenoiser = new BoolParameter(false);
/// <summary>
/// Controls the radius of the global illumination denoiser (First Pass).
/// </summary>
public float denoiserRadius
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_DenoiserRadius.value;
else
return GetLightingQualitySettings().RTGIDenoiserRadius[(int)quality.value];
}
set { m_DenoiserRadius.value = value; }
}
[SerializeField, FormerlySerializedAs("denoiserRadius")]
[Tooltip("Controls the radius of the GI denoiser (First Pass).")]
private ClampedFloatParameter m_DenoiserRadius = new ClampedFloatParameter(0.6f, 0.001f, 1.0f);
/// <summary>
/// Defines if the second denoising pass should be enabled.
/// </summary>
public bool secondDenoiserPass
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_SecondDenoiserPass.value;
else
return GetLightingQualitySettings().RTGISecondDenoise[(int)quality.value];
}
set { m_SecondDenoiserPass.value = value; }
}
[SerializeField, FormerlySerializedAs("secondDenoiserPass")]
[Tooltip("Enable second denoising pass.")]
private BoolParameter m_SecondDenoiserPass = new BoolParameter(true);
/// <summary>
/// Controls the number of steps used for the mixed tracing
/// </summary>
public int maxMixedRaySteps
{
get
{
if (!UsesQualitySettings() || UsesQualityMode())
return m_MaxMixedRaySteps.value;
else
return GetLightingQualitySettings().RTGIRaySteps[(int)quality.value];
}
set { m_MaxMixedRaySteps.value = value; }
}
[SerializeField]
[Tooltip("Controls the number of steps HDRP uses for mixed tracing.")]
private MinIntParameter m_MaxMixedRaySteps = new MinIntParameter(48, 0);
/// <summary>
/// When enabled, the receiver's movement should be considered a valid rejection condition.
/// </summary>
[AdditionalProperty]
[Tooltip("When enabled, the receiver's movement should be considered a valid rejection condition.")]
public BoolParameter receiverMotionRejection = new BoolParameter(true);
#endregion
internal static bool RayTracingActive(GlobalIllumination volume)
{
return volume.tracing.value != RayCastingMode.RayMarching;
}
}
}