Skip to content

Commit 0f8ecd8

Browse files
FrancescoC-unitynoreply@unity3d.com
andauthored
Touchup volume debug and gizmo color modification (#7119)
* Tunable color * Add debug mode * Updating test data. * Remove leftover that fails build * Apply formatting changes Co-authored-by: noreply@unity3d.com <noreply@unity3d.com>
1 parent 4f78740 commit 0f8ecd8

File tree

13 files changed

+71
-11
lines changed

13 files changed

+71
-11
lines changed
Binary file not shown.
Binary file not shown.

com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ struct BakingCell
2525
public Vector3[] probePositions;
2626
public SphericalHarmonicsL2[] sh;
2727
public uint[] validity;
28+
2829
public Vector3[] offsetVectors;
30+
public float[] touchupVolumeInteraction;
2931

3032
public int minSubdiv;
3133
public int indexChunkCount;
@@ -602,6 +604,7 @@ static void OnAdditionalProbesBakeCompleted()
602604
cell.sh = new SphericalHarmonicsL2[numProbes];
603605
cell.validity = new uint[numProbes];
604606
cell.offsetVectors = new Vector3[virtualOffsets != null ? numProbes : 0];
607+
cell.touchupVolumeInteraction = new float[numProbes];
605608
cell.minSubdiv = probeRefVolume.GetMaxSubdivision();
606609

607610
// Find the subset of touchup volumes that will be considered for this cell.
@@ -636,13 +639,19 @@ static void OnAdditionalProbesBakeCompleted()
636639
if (touchupVolume.invalidateProbes)
637640
{
638641
invalidatedProbe = true;
642+
// We check as below 1 but bigger than 0 in the debug shader, so any value <1 will do to signify touched up.
643+
cell.touchupVolumeInteraction[i] = 0.5f;
644+
639645
if (validity[j] < 0.05f) // We just want to add probes that were not already invalid or close to.
640646
{
641647
s_ForceInvalidatedProbesAndTouchupVols[cell.probePositions[i]] = touchupBound;
642648
}
643649
}
644650
else if (touchupVolume.overrideDilationThreshold)
645651
{
652+
// The 1 + is used to determine the action (debug shader tests above 1), then we add the threshold to be able to retrieve it in debug phase.
653+
cell.touchupVolumeInteraction[i] = 1.0f + touchupVolume.overriddenDilationThreshold;
654+
646655
s_CustomDilationThresh.Add(i, touchupVolume.overriddenDilationThreshold);
647656
}
648657
break;
@@ -880,6 +889,7 @@ static BakingCell ConvertCellToBakingCell(ProbeReferenceVolume.Cell cell)
880889
probePositions = cell.probePositions.ToArray(),
881890
validity = cell.validity.ToArray(),
882891
offsetVectors = cell.offsetVectors.ToArray(),
892+
touchupVolumeInteraction = cell.touchupVolumeInteraction.ToArray(),
883893
minSubdiv = cell.minSubdiv,
884894
indexChunkCount = cell.indexChunkCount,
885895
shChunkCount = cell.shChunkCount,
@@ -1064,6 +1074,7 @@ static void WriteBakingCells(ProbeVolumePerSceneData data, List<BakingCell> baki
10641074

10651075
// CellSupportData
10661076
using var positions = new NativeArray<Vector3>(asset.totalCellCounts.probesCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
1077+
using var touchupVolumeInteraction = new NativeArray<float>(asset.totalCellCounts.probesCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
10671078
using var offsets = new NativeArray<Vector3>(asset.totalCellCounts.offsetsCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
10681079

10691080
var sceneStateHash = asset.GetBakingHashCode();
@@ -1096,6 +1107,7 @@ static void WriteBakingCells(ProbeVolumePerSceneData data, List<BakingCell> baki
10961107
validity.GetSubArray(startCounts.probesCount, cellCounts.probesCount).CopyFrom(bakingCell.validity);
10971108

10981109
positions.GetSubArray(startCounts.probesCount, cellCounts.probesCount).CopyFrom(bakingCell.probePositions);
1110+
touchupVolumeInteraction.GetSubArray(startCounts.probesCount, cellCounts.probesCount).CopyFrom(bakingCell.touchupVolumeInteraction);
10991111
offsets.GetSubArray(startCounts.offsetsCount, cellCounts.offsetsCount).CopyFrom(bakingCell.offsetVectors);
11001112

11011113
startCounts.Add(cellCounts);
@@ -1126,6 +1138,8 @@ static void WriteBakingCells(ProbeVolumePerSceneData data, List<BakingCell> baki
11261138
{
11271139
fs.Write(new ReadOnlySpan<byte>(positions.GetUnsafeReadOnlyPtr(), positions.Length * UnsafeUtility.SizeOf<Vector3>()));
11281140
fs.Write(new byte[AlignRemainder16(fs.Position)]);
1141+
fs.Write(new ReadOnlySpan<byte>(touchupVolumeInteraction.GetUnsafeReadOnlyPtr(), touchupVolumeInteraction.Length * UnsafeUtility.SizeOf<float>()));
1142+
fs.Write(new byte[AlignRemainder16(fs.Position)]);
11291143
fs.Write(new ReadOnlySpan<byte>(offsets.GetUnsafeReadOnlyPtr(), offsets.Length * UnsafeUtility.SizeOf<Vector3>()));
11301144
}
11311145
}

com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeTouchupVolumeEditor.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,23 @@
44
using UnityEditor.Rendering;
55
using UnityEngine.Rendering;
66
using UnityEditorInternal;
7+
using System;
8+
using RuntimeSRPPreferences = UnityEngine.Rendering.CoreRenderPipelinePreferences;
79

810
namespace UnityEditor.Rendering
911
{
12+
internal class ProbeTouchupColorPreferences
13+
{
14+
internal static Func<Color> GetColorPrefProbeVolumeGizmoColor;
15+
internal static Color s_ProbeTouchupVolumeGizmoColorDefault = new Color32(222, 132, 144, 45);
16+
17+
static ProbeTouchupColorPreferences()
18+
{
19+
GetColorPrefProbeVolumeGizmoColor = RuntimeSRPPreferences.RegisterPreferenceColor("Scene/Probe Touchup Volume Gizmo", s_ProbeTouchupVolumeGizmoColorDefault);
20+
}
21+
22+
}
23+
1024
[CanEditMultipleObjects]
1125
[CustomEditor(typeof(ProbeTouchupVolume))]
1226
internal class ProbeTouchupVolumeEditor : Editor
@@ -19,17 +33,19 @@ internal static class Styles
1933
internal static readonly GUIContent s_OverrideDilationThreshold = new GUIContent("Override Dilation Threshold", "Whether to override the dilation threshold used for probes falling within this probe touch-up volume.");
2034
internal static readonly GUIContent s_OverriddenDilationThreshold = new GUIContent("Dilation Threshold", "The dilation threshold to use for this probe volume.");
2135

22-
internal static readonly Color k_GizmoColorBase = new Color32(222, 132, 144, 255);
36+
internal static readonly Color k_GizmoColorBase = ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault;
2337

2438
internal static readonly Color[] k_BaseHandlesColor = new Color[]
2539
{
26-
k_GizmoColorBase,
27-
k_GizmoColorBase,
28-
k_GizmoColorBase,
29-
k_GizmoColorBase,
30-
k_GizmoColorBase,
31-
k_GizmoColorBase
40+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault,
41+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault,
42+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault,
43+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault,
44+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault,
45+
ProbeTouchupColorPreferences.s_ProbeTouchupVolumeGizmoColorDefault
3246
};
47+
48+
3349
}
3450

3551

@@ -106,7 +122,7 @@ static void DrawGizmosSelected(ProbeTouchupVolume touchupVolume, GizmoType gizmo
106122
// Bounding box.
107123
s_ShapeBox.center = Vector3.zero;
108124
s_ShapeBox.size = touchupVolume.size;
109-
s_ShapeBox.baseColor = new Color(0.75f, 0.2f, 0.18f);
125+
s_ShapeBox.SetBaseColor(ProbeTouchupColorPreferences.GetColorPrefProbeVolumeGizmoColor());
110126
s_ShapeBox.DrawHull(true);
111127
}
112128
}
@@ -128,7 +144,7 @@ protected void OnSceneGUI()
128144
s_ShapeBox.DrawHandle();
129145
if (EditorGUI.EndChangeCheck())
130146
{
131-
Undo.RecordObjects(new Object[] { touchupVolume, touchupVolume.transform }, "Change Probe Touchup Volume Bounding Box");
147+
Undo.RecordObjects(new UnityEngine.Object[] { touchupVolume, touchupVolume.transform }, "Change Probe Touchup Volume Bounding Box");
132148

133149
touchupVolume.size = s_ShapeBox.size;
134150
Vector3 delta = touchupVolume.transform.rotation * s_ShapeBox.center - touchupVolume.transform.position;

com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public enum DebugProbeShadingMode
2929
/// </summary>
3030
ValidityOverDilationThreshold,
3131
/// <summary>
32+
/// Show in red probes that have been made invalid by touchup volumes. Important to note that this debug view will only show result for volumes still present in the scene.
33+
/// </summary>
34+
InvalidatedByTouchupVolumes,
35+
/// <summary>
3236
/// Based on size
3337
/// </summary>
3438
Size
@@ -357,6 +361,7 @@ CellInstancedDebugProbes CreateInstancedProbes(CellInfo cellInfo)
357361
Vector4[] texels = new Vector4[kProbesPerBatch];
358362
float[] validity = new float[kProbesPerBatch];
359363
float[] relativeSize = new float[kProbesPerBatch];
364+
float[] touchupUpVolumeAction = cell.touchupVolumeInteraction.Length > 0 ? new float[kProbesPerBatch] : null;
360365
Vector4[] offsets = cell.offsetVectors.Length > 0 ? new Vector4[kProbesPerBatch] : null;
361366

362367
List<Matrix4x4> probeBuffer = new List<Matrix4x4>();
@@ -386,6 +391,13 @@ CellInstancedDebugProbes CreateInstancedProbes(CellInfo cellInfo)
386391
validity[idxInBatch] = cell.GetValidity(i);
387392
texels[idxInBatch] = new Vector4(texelLoc.x, texelLoc.y, texelLoc.z, brickSize);
388393
relativeSize[idxInBatch] = (float)brickSize / (float)maxSubdiv;
394+
395+
if (touchupUpVolumeAction != null)
396+
{
397+
touchupUpVolumeAction[idxInBatch] = cell.touchupVolumeInteraction[i];
398+
}
399+
400+
389401
if (offsets != null)
390402
{
391403
const float kOffsetThresholdSqr = 1e-6f;
@@ -413,6 +425,7 @@ CellInstancedDebugProbes CreateInstancedProbes(CellInfo cellInfo)
413425
MaterialPropertyBlock prop = new MaterialPropertyBlock();
414426

415427
prop.SetFloatArray("_Validity", validity);
428+
prop.SetFloatArray("_TouchupedByVolume", touchupUpVolumeAction);
416429
prop.SetFloatArray("_RelativeSize", relativeSize);
417430
prop.SetVectorArray("_IndexInAtlas", texels);
418431

com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs.hlsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#define DEBUGPROBESHADINGMODE_SHL0L1 (2)
1313
#define DEBUGPROBESHADINGMODE_VALIDITY (3)
1414
#define DEBUGPROBESHADINGMODE_VALIDITY_OVER_DILATION_THRESHOLD (4)
15-
#define DEBUGPROBESHADINGMODE_SIZE (5)
15+
#define DEBUGPROBESHADINGMODE_INVALIDATED_BY_TOUCHUP_VOLUMES (5)
16+
#define DEBUGPROBESHADINGMODE_SIZE (6)
1617

1718

1819
#endif

com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ internal class Cell
394394
public NativeArray<Brick> bricks { get; internal set; }
395395
public NativeArray<uint> validity { get; internal set; }
396396
public NativeArray<Vector3> probePositions { get; internal set; }
397+
public NativeArray<float> touchupVolumeInteraction { get; internal set; } // Only used by a specific debug view.
397398
public NativeArray<Vector3> offsetVectors { get; internal set; }
398399

399400
// Per state data

com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeAsset.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,14 @@ internal bool ResolveSharedCellData(TextAsset cellSharedDataAsset, TextAsset cel
9898
var cellSupportData = cellSupportDataAsset ? cellSupportDataAsset.GetData<byte>() : default;
9999
var hasSupportData = cellSupportData.IsCreated;
100100
var positionsByteCount = totalCellCounts.probesCount * UnsafeUtility.SizeOf<Vector3>();
101-
var offsetByteStart = AlignUp16(positionsByteCount);
101+
var touchupInteractionStart = AlignUp16(positionsByteCount);
102+
var touchupInteractionByteCount = totalCellCounts.probesCount * UnsafeUtility.SizeOf<float>();
103+
var offsetByteStart = AlignUp16(positionsByteCount) + AlignUp16(touchupInteractionByteCount);
102104
var offsetByteCount = totalCellCounts.offsetsCount * UnsafeUtility.SizeOf<Vector3>();
103105
if (hasSupportData && offsetByteStart + offsetByteCount != cellSupportData.Length)
104106
return false;
105107
var positionsData = hasSupportData ? cellSupportData.GetSubArray(0, positionsByteCount).Reinterpret<Vector3>(1) : default;
108+
var touchupInteractionData = hasSupportData ? cellSupportData.GetSubArray(touchupInteractionStart, touchupInteractionByteCount).Reinterpret<float>(1) : default;
106109
var offsetsData = hasSupportData ? cellSupportData.GetSubArray(offsetByteStart, offsetByteCount).Reinterpret<Vector3>(1) : default;
107110

108111
var startCounts = new CellCounts();
@@ -118,6 +121,7 @@ internal bool ResolveSharedCellData(TextAsset cellSharedDataAsset, TextAsset cel
118121
{
119122
cell.probePositions = positionsData.GetSubArray(startCounts.probesCount, counts.probesCount);
120123
cell.offsetVectors = offsetsData.GetSubArray(startCounts.offsetsCount, counts.offsetsCount);
124+
cell.touchupVolumeInteraction = touchupInteractionData.GetSubArray(startCounts.probesCount, counts.probesCount);
121125
}
122126

123127
startCounts.Add(counts);

com.unity.render-pipelines.high-definition/Runtime/Debug/ProbeVolumeDebug.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ uniform float _OffsetSize;
2222

2323
UNITY_INSTANCING_BUFFER_START(Props)
2424
UNITY_DEFINE_INSTANCED_PROP(float, _Validity)
25+
UNITY_DEFINE_INSTANCED_PROP(float, _TouchupedByVolume)
2526
UNITY_DEFINE_INSTANCED_PROP(float4, _IndexInAtlas)
2627
UNITY_DEFINE_INSTANCED_PROP(float4, _Offset)
2728
UNITY_DEFINE_INSTANCED_PROP(float, _RelativeSize)

com.unity.render-pipelines.high-definition/Runtime/Debug/ProbeVolumeDebug.shader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Shader "Hidden/HDRP/ProbeVolumeDebug"
3838
{
3939
return float4(CalculateDiffuseLighting(i) * exp2(_ExposureCompensation) * GetCurrentExposureMultiplier(), 1);
4040
}
41+
else if (_ShadingMode == DEBUGPROBESHADINGMODE_INVALIDATED_BY_TOUCHUP_VOLUMES)
42+
{
43+
float4 defaultCol = float4(CalculateDiffuseLighting(i) * exp2(_ExposureCompensation) * GetCurrentExposureMultiplier(), 1);
44+
float touchupAction = UNITY_ACCESS_INSTANCED_PROP(Props, _TouchupedByVolume);
45+
if (touchupAction > 0 && touchupAction < 1)
46+
{
47+
return float4(1, 0, 0, 1);
48+
}
49+
return defaultCol;
50+
}
4151
else if (_ShadingMode == DEBUGPROBESHADINGMODE_VALIDITY)
4252
{
4353
float validity = UNITY_ACCESS_INSTANCED_PROP(Props, _Validity);

0 commit comments

Comments
 (0)