Skip to content

Commit d2fc1a8

Browse files
committed
Probe Volume: Add View Bias support - exposed on the ProbeVolume component next to Normal Bias (#25)
Co-authored-by: pastasfuture <[email protected]>
1 parent a92311e commit d2fc1a8

File tree

11 files changed

+45
-11
lines changed

11 files changed

+45
-11
lines changed

com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Drawer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ static void Drawer_VolumeContent(SerializedProbeVolume serialized, Editor owner)
301301
{
302302
serialized.normalBiasWS.floatValue = Mathf.Max(0, normalBiasWS);
303303
}
304+
305+
EditorGUI.BeginChangeCheck();
306+
float viewBiasWS = EditorGUILayout.FloatField(Styles.s_ViewBiasWSLabel, serialized.viewBiasWS.floatValue);
307+
if (EditorGUI.EndChangeCheck())
308+
{
309+
serialized.viewBiasWS.floatValue = Mathf.Max(0, viewBiasWS);
310+
}
304311
}
305312
EditorGUILayout.PropertyField(serialized.debugColor, Styles.s_DebugColorLabel);
306313

com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Skin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ internal static class Styles
4747

4848
internal static readonly GUIContent s_VolumeBlendModeLabel = new GUIContent("Volume Blend Mode", "A blending mode for the entire volume when overlapping others.");
4949
internal static readonly GUIContent s_WeightLabel = new GUIContent("Weight", "Weigh the probe contribution for the entire volume.");
50-
internal static readonly GUIContent s_NormalBiasWSLabel = new GUIContent("Normal Bias", "Controls the distance in world space units to bias along the surface normal to mitigate light leaking and self-shadowing artifacts.\nA value of 0.0 is physically accurate, but can result in self shadowing artifacts on surfaces that contribute to GI.\nIncrease value to mitigate self shadowing artifacts.\nSignificantly large values can have performance implications, as normal bias will dilate a probe volumes bounding box, causing it to be sampled in additional neighboring tiles / clusters.");
50+
internal static readonly GUIContent s_NormalBiasWSLabel = new GUIContent("Normal Bias", "Controls the distance in world space units to bias along the surface normal to mitigate light leaking and self-shadowing artifacts.\nA value of 0.0 is physically accurate, but can result in self shadowing artifacts on surfaces that contribute to GI.\nIncrease value to mitigate self shadowing and light leak artifacts.\nSignificantly large values can have performance implications, as normal bias will dilate a probe volumes bounding box, causing it to be sampled in additional neighboring tiles / clusters.");
51+
internal static readonly GUIContent s_ViewBiasWSLabel = new GUIContent("View Bias", "Controls the distance in world space units to bias toward the camera position to mitigate light leaking and self-shadowing artifacts.\nA value of 0.0 is physically accurate, but can result in self shadowing artifacts on surfaces that contribute to GI.\nIncrease value to mitigate self shadowing and light leak artifacts.\nSignificantly large values can have performance implications, as view bias will dilate a probe volumes bounding box, causing it to be sampled in additional neighboring tiles / clusters.");
52+
5153

5254
internal static readonly GUIContent s_BackfaceToleranceLabel = new GUIContent("Backface Tolerance", "The percentage of backfaces sampled per probe is acceptable before probe will receive dilated data.");
5355
internal static readonly GUIContent s_DilationIterationLabel = new GUIContent("Dilation Iterations", "The number of iterations Dilation copies over data from each probe to its neighbors.");

com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/SerializedProbeVolume.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class SerializedProbeVolume
2424
internal SerializedProperty volumeBlendMode;
2525
internal SerializedProperty weight;
2626
internal SerializedProperty normalBiasWS;
27+
internal SerializedProperty viewBiasWS;
2728

2829
internal SerializedProperty size;
2930

@@ -70,6 +71,7 @@ internal SerializedProbeVolume(SerializedObject serializedObject)
7071
volumeBlendMode = probeVolumeParams.FindPropertyRelative("volumeBlendMode");
7172
weight = probeVolumeParams.FindPropertyRelative("weight");
7273
normalBiasWS = probeVolumeParams.FindPropertyRelative("normalBiasWS");
74+
viewBiasWS = probeVolumeParams.FindPropertyRelative("viewBiasWS");
7375

7476
size = probeVolumeParams.FindPropertyRelative("size");
7577

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,10 @@ bool PrepareLightsForGPU(CommandBuffer cmd, HDCamera hdCamera, CullingResults cu
28702870
if (ShaderConfig.s_ProbeVolumesEvaluationMode != ProbeVolumesEvaluationModes.Disabled)
28712871
{
28722872
var settings = hdCamera.volumeStack.GetComponent<ProbeVolumeController>();
2873-
probeVolumeNormalBiasEnabled = !(settings == null || (settings.leakMitigationMode.value != LeakMitigationMode.NormalBias && settings.leakMitigationMode.value != LeakMitigationMode.OctahedralDepthOcclusionFilter));
2873+
probeVolumeNormalBiasEnabled = !(settings == null ||
2874+
(settings.leakMitigationMode.value != LeakMitigationMode.NormalBias
2875+
&& settings.leakMitigationMode.value != LeakMitigationMode.ProbeValidityFilter
2876+
&& settings.leakMitigationMode.value != LeakMitigationMode.OctahedralDepthOcclusionFilter));
28742877
}
28752878

28762879
for (int viewIndex = 0; viewIndex < hdCamera.viewCount; ++viewIndex)
@@ -2896,8 +2899,8 @@ bool PrepareLightsForGPU(CommandBuffer cmd, HDCamera hdCamera, CullingResults cu
28962899
{
28972900
// Probe volumes are not lights and therefore should not affect light classification.
28982901
LightFeatureFlags featureFlags = 0;
2899-
float probeVolumeNormalBiasWS = probeVolumeNormalBiasEnabled ? probeVolumes.data[i].normalBiasWS : 0.0f;
2900-
CreateBoxVolumeDataAndBound(probeVolumes.bounds[i], LightCategory.ProbeVolume, featureFlags, worldToViewCR, probeVolumeNormalBiasWS, out LightVolumeData volumeData, out SFiniteLightBound bound);
2902+
float probeVolumeMaxBiasWS = probeVolumeNormalBiasEnabled ? (probeVolumes.data[i].normalBiasWS + probeVolumes.data[i].viewBiasWS) : 0.0f;
2903+
CreateBoxVolumeDataAndBound(probeVolumes.bounds[i], LightCategory.ProbeVolume, featureFlags, worldToViewCR, probeVolumeMaxBiasWS, out LightVolumeData volumeData, out SFiniteLightBound bound);
29012904
if (ShaderConfig.s_ProbeVolumesEvaluationMode == ProbeVolumesEvaluationModes.MaterialPass)
29022905
{
29032906
// Only probe volume evaluation in the material pass use these custom probe volume specific lists.

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
567567
posInput,
568568
bsdfData.normalWS,
569569
-bsdfData.normalWS,
570+
V,
570571
builtinData.renderingLayers,
571572
probeVolumeHierarchyWeight,
572573
builtinDataProbeVolumes.bakeDiffuseLighting,

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ internal struct ProbeVolumeArtistParameters
432432
public VolumeBlendMode volumeBlendMode;
433433
public float weight;
434434
public float normalBiasWS;
435+
public float viewBiasWS;
435436

436437
public float backfaceTolerance;
437438
public int dilationIterations;
@@ -505,6 +506,7 @@ public ProbeVolumeArtistParameters(Color debugColor)
505506
this.volumeBlendMode = VolumeBlendMode.Normal;
506507
this.weight = 1;
507508
this.normalBiasWS = 0.0f;
509+
this.viewBiasWS = 0.0f;
508510
this.dilationIterations = 2;
509511
this.backfaceTolerance = 0.25f;
510512
this.lightLayers = LightLayerEnum.LightLayerDefault;
@@ -557,6 +559,7 @@ internal ProbeVolumeEngineData ConvertToEngineData()
557559

558560
data.weight = this.weight;
559561
data.normalBiasWS = this.normalBiasWS;
562+
data.viewBiasWS = this.viewBiasWS;
560563

561564
data.debugColor.x = this.debugColor.r;
562565
data.debugColor.y = this.debugColor.g;

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,23 @@ float3 ProbeVolumeEvaluateAmbientProbeFallback(float3 normalWS, float weightHier
184184
#define PROBE_VOLUMES_SAMPLING_MODE SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE
185185
#endif
186186

187-
void ProbeVolumeEvaluateSphericalHarmonics(PositionInputs posInput, float3 normalWS, float3 backNormalWS, uint renderingLayers, float weightHierarchy, inout float3 bakeDiffuseLighting, inout float3 backBakeDiffuseLighting)
187+
void ProbeVolumeEvaluateSphericalHarmonics(PositionInputs posInput, float3 normalWS, float3 backNormalWS, float3 viewDirectionWS, uint renderingLayers, float weightHierarchy, inout float3 bakeDiffuseLighting, inout float3 backBakeDiffuseLighting)
188188
{
189189
#if PROBE_VOLUMES_SAMPLING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L0
190190
ProbeVolumeSphericalHarmonicsL0 coefficients;
191-
ProbeVolumeAccumulateSphericalHarmonicsL0(posInput, normalWS, renderingLayers, coefficients, weightHierarchy);
191+
ProbeVolumeAccumulateSphericalHarmonicsL0(posInput, normalWS, viewDirectionWS, renderingLayers, coefficients, weightHierarchy);
192192
bakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL0(normalWS, coefficients);
193193
backBakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL0(backNormalWS, coefficients);
194194

195195
#elif PROBE_VOLUMES_SAMPLING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
196196
ProbeVolumeSphericalHarmonicsL1 coefficients;
197-
ProbeVolumeAccumulateSphericalHarmonicsL1(posInput, normalWS, renderingLayers, coefficients, weightHierarchy);
197+
ProbeVolumeAccumulateSphericalHarmonicsL1(posInput, normalWS, viewDirectionWS, renderingLayers, coefficients, weightHierarchy);
198198
bakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL1(normalWS, coefficients);
199199
backBakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL1(backNormalWS, coefficients);
200200

201201
#elif PROBE_VOLUMES_SAMPLING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
202202
ProbeVolumeSphericalHarmonicsL2 coefficients;
203-
ProbeVolumeAccumulateSphericalHarmonicsL2(posInput, normalWS, renderingLayers, coefficients, weightHierarchy);
203+
ProbeVolumeAccumulateSphericalHarmonicsL2(posInput, normalWS, viewDirectionWS, renderingLayers, coefficients, weightHierarchy);
204204
bakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL2(normalWS, coefficients);
205205
backBakeDiffuseLighting += ProbeVolumeEvaluateSphericalHarmonicsL2(backNormalWS, coefficients);
206206

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeAccumulate.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#elif PROBE_VOLUMES_ACCUMULATE_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
2424
void ProbeVolumeAccumulateSphericalHarmonicsL2(
2525
#endif
26-
PositionInputs posInput, float3 normalWS, uint renderingLayers,
26+
PositionInputs posInput, float3 normalWS, float3 viewDirectionWS, uint renderingLayers,
2727
#if PROBE_VOLUMES_ACCUMULATE_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L0
2828
out ProbeVolumeSphericalHarmonicsL0 coefficients,
2929
#elif PROBE_VOLUMES_ACCUMULATE_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
@@ -109,7 +109,7 @@
109109
ProbeVolumeComputeOBBBoundsToFrame(s_probeVolumeBounds, obbFrame, obbExtents, obbCenter);
110110

111111
// Note: When normal bias is > 0, bounds using in tile / cluster assignment are conservatively dilated CPU side to handle worst case normal bias.
112-
float3 samplePositionWS = normalWS * s_probeVolumeData.normalBiasWS + posInput.positionWS;
112+
float3 samplePositionWS = normalWS * s_probeVolumeData.normalBiasWS + viewDirectionWS * s_probeVolumeData.viewBiasWS + posInput.positionWS;
113113

114114
float3 probeVolumeTexel3D;
115115
ProbeVolumeComputeTexel3DAndWeight(

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace UnityEngine.Rendering.HighDefinition
77
{
88
// Optimized version of 'ProbeVolumeArtistParameters'.
9-
// Currently 128-bytes.
9+
// Currently 144-bytes.
1010
// TODO: pack better. This data structure contains a bunch of UNORMs.
1111
[GenerateHLSL]
1212
internal struct ProbeVolumeEngineData
@@ -26,6 +26,8 @@ internal struct ProbeVolumeEngineData
2626
public uint lightLayers;
2727
public Vector3 resolutionInverse;
2828
public float normalBiasWS;
29+
public float viewBiasWS;
30+
public Vector3 padding;
2931

3032
public static ProbeVolumeEngineData GetNeutralValues()
3133
{
@@ -46,6 +48,8 @@ public static ProbeVolumeEngineData GetNeutralValues()
4648
data.lightLayers = 0;
4749
data.resolutionInverse = Vector3.zero;
4850
data.normalBiasWS = 0.0f;
51+
data.viewBiasWS = 0.0f;
52+
data.padding = Vector3.zero;
4953

5054
return data;
5155
}

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct ProbeVolumeEngineData
3131
uint lightLayers;
3232
float3 resolutionInverse;
3333
float normalBiasWS;
34+
float viewBiasWS;
35+
float3 padding;
3436
};
3537

3638
//
@@ -96,5 +98,13 @@ float GetNormalBiasWS(ProbeVolumeEngineData value)
9698
{
9799
return value.normalBiasWS;
98100
}
101+
float GetViewBiasWS(ProbeVolumeEngineData value)
102+
{
103+
return value.viewBiasWS;
104+
}
105+
float3 GetPadding(ProbeVolumeEngineData value)
106+
{
107+
return value.padding;
108+
}
99109

100110
#endif

0 commit comments

Comments
 (0)