Skip to content

Commit 3121550

Browse files
Probe Volume Dynamic GI V1 (#7)
Large feature addition to Probe Volumes to support Dynamic GI at runtime & in editor via compute jobs. Huge coordination across game team, Spotlight & HDRP team to refine the algorithm and feature set. Key Features - New toggle on a light "Affects Dynamic GI" - New toggle on a probe Volume "Support Dynamic GI" - New debug draw mode on a probe volume "Draw Neighbors" to visualize the neighbor the dynamic GI light will bounce around in - All light types are supported Missing features - During albedo baking step, mask volumes are not being sampled correctly - Off screen lights are missing their shadows when being sampled by the Hit pass of the Dynamic GI compute shader - Directional light GI seems off, maybe its the offscreen shadow issues - Sky lighting is not supported at the moment in the dynamic GI - Currently does not encode emissive in the neighborhood bake data, only albedo, surface distance & normal - Currently does require a re-bake when geometry changes, the only thing it relies on getting from the lightmapper is the probe validity value Commit notes: * Added dynamic GI options onto HDLight and ProbeVolume inspectors * work in progress dynamic gi * lots more refactoring on the data model and packing for hits vs misses * Cleanup dynamic GI code into separate file * Working axis baking code with visualization * small fixes * validity scale fix * neighbor draw quad scale control * small fix * scale fix * First pass at albedo extraction code for DynamicGI * bake bug fix * Albedo baking via Shader Graph works now, and more tweaks to neighbor debug draw * bug fix * Dynamic GI neighbor cleanup to use real probe volume data for positioning * bug fix for non uniform density volumes * cleanup * Cleanup and setup of Propagation Buffers * more work in progress dynamic GI, have a test read modify write of SH data working * cleanup dynamic GI values when its disabled * more cleanup * bug fix * New improved Albedo sampling code from Francesco * cache debug shader not material, works better for some reason * Lots of shader code and setup for real-time GI propagation. Still a work in progress but most code written on GPU side * All the compute data hooked up first pass * Kinda of working * Slightly better, still not there * Fixes plus re-write of SH data in dynamic GI * First kinda working version of new RTGI, needs lots of tuning and improvements * Move VolumeComponent to seperate file so it is preserved when assets are saved * More improvements, anti alias punctual lights and add a secondary bounce to hits * Tweaks, added FCC's SH logic for testing / comps * Cleanup and addition of 3D texture for Irradiance sampling to smooth out history * Cleanup & and added back bounce boost control for hit pass * Tuning defaults * more filddleing with defaults * temp code for testing * Intended L1 * Adding Affect Dynamic GI to light explorer UI Fixing hit lighting logic to work with multiple lights * Adding de-ringing to SH Exposing class outside of HDRP for play mode testing * Move probe volume update code around so worked better with needing state set before dispatches * Integration of SG logic for Irradiance Cache, way cleaner and better results. Removed old Irradiance cache logic using L1 SH * More cleanup and refinements of SG algorithm * Bias punctual lights near surfaces to fix strobing * Cleanup * name cleanup * Support volume rotation in neighbor debug view mode * Fixed contribution normalization. Changed the direction for infinite bounces evaluation from reflection to surface normal. * changing default sharpness to 3.5 to reduce dark banding a tad * Hacked prototype of an alternative propagation algorithm. * Smoothed radiance gathering from hits. * Cleanup and temp NaN propagation workaround. * Changed History Contribution min limit to 0 to be able to test propagation without it. * Removed old algorithm, cleaned up data format and volume parameters to make new directional version the default one * Fixed Probe Volume dynamic GI data access after merging with the DOTS Probe Volume feature. Signed-off-by: Andrew Saraev <[email protected]> * Fixed up popping issues with Dynamic GI and other probe volumes in view, plus made it so the light list is global, not camera view culled so all lights stay active in the list for GI to propagate more accurately and shadows to update even for lights behind the camera. Merged with latest * Build compile fixes * Player build fixes, real-time GI now works in player builds * HDRP settings and toggles for probe volume dynamic GI * missed files for previous checkin * small optimizations * turn on optimizations in key dynamic gi shaders for perf * Custom dynamic GI light list that also includes off screen lights * Explicitly set dataUpdated when data is uploaded to the atlas instead of setting it in GetPayload() of the volume. To simplify communication with the DOTS version. * use shadows for dynamic GI lights. This still has a bug where off screen lights get their shadow indexes reset to -1 * Better disposing of propagation buffers Cleaned up global compute buffers for SH L012 and validity buffers, and reusing those per probe volume for propagation to reduce memory usage * possible mem leak fix & piping light bounce intensity through to dynamic GI * Some PR feedback and distance checks to probe hit & propagation phases * Added basic distance checks to entire probe volume to dispatch dynamic GI jobs or not * directional lights are weird, maybe the shadows, we should avoid them * PR feedback * Refactored ProbeVolumeBuffers cleanup to keep GameObject and DOTS logic similar. * Attempt to reduce white space conflicts * Profiler marker for Dynamic GI Slight optimization in light loop * Optimized C# by not doing SetData calls on Buffers unnecessarily Co-authored-by: Andrew Saraev <[email protected]>
1 parent 2fc7310 commit 3121550

File tree

81 files changed

+5966
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5966
-114
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ protected static class HDStyles
7676
public static readonly GUIContent ColorTemperatureMode = EditorGUIUtility.TrTextContent("Use Color Temperature");
7777
public static readonly GUIContent AffectDiffuse = EditorGUIUtility.TrTextContent("Affect Diffuse");
7878
public static readonly GUIContent AffectSpecular = EditorGUIUtility.TrTextContent("Affect Specular");
79+
public static readonly GUIContent AffectDynamicGI = EditorGUIUtility.TrTextContent("Affect Dynamic GI");
7980
public static readonly GUIContent FadeDistance = EditorGUIUtility.TrTextContent("Fade Distance");
8081
public static readonly GUIContent ShadowFadeDistance = EditorGUIUtility.TrTextContent("Shadow Fade Distance");
8182
public static readonly GUIContent LightLayer = EditorGUIUtility.TrTextContent("Light Layer");
@@ -610,6 +611,40 @@ protected virtual LightingExplorerTableColumn[] GetHDLightColumns()
610611
Undo.RecordObject(tLightData, "Changed affects specular");
611612
tLightData.affectSpecular = sLightData.affectSpecular;
612613
}),
614+
new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Checkbox, HDStyles.AffectDynamicGI, "m_Intensity", 100, (r, prop, dep) => // 17: Affect Specular
615+
{
616+
if(!TryGetAdditionalLightData(prop, out var lightData))
617+
{
618+
EditorGUI.LabelField(r, "--");
619+
return;
620+
}
621+
622+
bool affectDynamicGI = lightData.affectDynamicGI;
623+
624+
EditorGUI.BeginChangeCheck();
625+
affectDynamicGI = EditorGUI.Toggle(r, affectDynamicGI);
626+
if (EditorGUI.EndChangeCheck())
627+
{
628+
Undo.RecordObject(lightData, "Changed affects dynamic GI");
629+
lightData.affectDynamicGI = affectDynamicGI;
630+
}
631+
}, (lprop, rprop) =>
632+
{
633+
TryGetAdditionalLightData(lprop, out var lLightData);
634+
TryGetAdditionalLightData(rprop, out var rLightData);
635+
636+
if (IsNullComparison(lLightData, rLightData, out var order))
637+
return order;
638+
639+
return lLightData.affectDynamicGI.CompareTo(rLightData.affectDynamicGI);
640+
}, (target, source) =>
641+
{
642+
if (!TryGetAdditionalLightData(target, out var tLightData) || !TryGetAdditionalLightData(source, out var sLightData))
643+
return;
644+
645+
Undo.RecordObject(tLightData, "Changed affects dynamic GI");
646+
tLightData.affectDynamicGI = sLightData.affectDynamicGI;
647+
}),
613648
new LightingExplorerTableColumn(LightingExplorerTableColumn.DataType.Float, HDStyles.FadeDistance, "m_Intensity", 95, (r, prop, dep) => // 18: Fade Distance
614649
{
615650
if(!TryGetAdditionalLightData(prop, out var lightData))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ sealed class Styles
8686
public readonly GUIContent areaLightEmissiveMeshSameLayer = new GUIContent("Same Layer", "If checked, use the same Layer than the Light one.");
8787
public readonly GUIContent areaLightEmissiveMeshCustomLayer = new GUIContent("Custom Layer", "Specify on which layer the generated Mesh live.");
8888
public readonly GUIContent lightLayer = new GUIContent("Light Layer", "Specifies the current Light Layers that the Light affects. This Light illuminates corresponding Renderers with the same Light Layer flags.");
89+
public readonly GUIContent affectDynamicGI = new GUIContent("Affect Dynamic GI", "If checked, the light contributes to dynamic GI from probe volumes.");
8990

9091
public readonly GUIContent interactsWithSky = new GUIContent("Affect Physically Based Sky", "Check this option to make the light and the Physically Based sky affect one another.");
9192
public readonly GUIContent angularDiameter = new GUIContent("Angular Diameter", "Angular diameter of the emissive celestial body represented by the light as seen from the camera (in degrees). Used to render the sun/moon disk.");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ static void DrawEmissionAdvancedContent(SerializedHDLight serialized, Editor own
877877
{
878878
EditorGUILayout.PropertyField(serialized.affectDiffuse, s_Styles.affectDiffuse);
879879
EditorGUILayout.PropertyField(serialized.affectSpecular, s_Styles.affectSpecular);
880+
EditorGUILayout.PropertyField(serialized.affectDynamicGI, s_Styles.affectDynamicGI);
881+
880882
if (lightType != HDLightType.Directional)
881883
{
882884
EditorGUILayout.PropertyField(serialized.applyRangeAttenuation, s_Styles.applyRangeAttenuation);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ static void Drawer_PrimarySettings(SerializedProbeVolume serialized, Editor owne
144144
serialized.drawOctahedralDepthRayIndexZ.intValue = Mathf.Clamp(serialized.drawOctahedralDepthRayIndexZ.intValue, 0, serialized.resolutionZ.intValue - 1);
145145
}
146146
}
147+
148+
if (serialized.supportDynamicGI.boolValue)
149+
{
150+
EditorGUILayout.PropertyField(serialized.drawNeighbors, Styles.s_DrawNeighborsLabel);
151+
if (serialized.drawNeighbors.boolValue && serialized.advancedFade.boolValue)
152+
{
153+
EditorGUILayout.PropertyField(serialized.neighborsQuadScale, Styles.s_NeighborsQuadScaleLabel);
154+
}
155+
}
156+
147157
EditorGUILayout.PropertyField(serialized.probeSpacingMode, Styles.s_ProbeSpacingModeLabel);
148158
switch ((ProbeSpacingMode)serialized.probeSpacingMode.enumValueIndex)
149159
{
@@ -309,6 +319,7 @@ static void Drawer_VolumeContent(SerializedProbeVolume serialized, Editor owner)
309319
serialized.viewBiasWS.floatValue = Mathf.Max(0, viewBiasWS);
310320
}
311321
}
322+
EditorGUILayout.PropertyField(serialized.supportDynamicGI);
312323
EditorGUILayout.PropertyField(serialized.debugColor, Styles.s_DebugColorLabel);
313324

314325
if (ShaderConfig.s_ProbeVolumesAdditiveBlending == 0 && serialized.volumeBlendMode.intValue != (int)VolumeBlendMode.Normal)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ internal static class Styles
2525
internal static readonly GUIContent s_Size = new GUIContent("Size", "Modify the size of this Probe Volume. This is independent of the Transform's Scale.");
2626
internal static readonly GUIContent s_DebugColorLabel = new GUIContent("Debug Color", "This color is used to visualize per-pixel probe volume weights in the render pipeline debugger.");
2727
internal static readonly GUIContent s_DrawProbesLabel = new GUIContent("Draw Probes", "Enable or disable drawing probes.");
28+
internal static readonly GUIContent s_DrawNeighborsLabel = new GUIContent("Draw Neighbors", "Enable or disable drawing probe neighborhood to debug dynamic gi.");
29+
internal static readonly GUIContent s_NeighborsQuadScaleLabel = new GUIContent("Draw Neighbors Scale", "The size of the debug quads when viewing draw neighbors mode");
2830
internal static readonly GUIContent s_DrawOctahedralDepthRays = new GUIContent("Draw Octahedral Depth Rays", "Enable or disable drawing rays to visualize to the octahedral depth data.");
2931
internal static readonly GUIContent s_DrawOctahedralDepthRayIndexX = new GUIContent("Octahedral Depth Rays Probe X", "Specifies the x index of the probe to visualize octahedral depth rays for.");
3032
internal static readonly GUIContent s_DrawOctahedralDepthRayIndexY = new GUIContent("Octahedral Depth Rays Probe Y", "Specifies the y index of the probe to visualize octahedral depth rays for.");

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ class SerializedProbeVolume
55
internal SerializedProperty probeVolumeParams;
66
internal SerializedProperty probeVolumeAsset;
77
internal SerializedProperty debugColor;
8+
internal SerializedProperty supportDynamicGI;
89
internal SerializedProperty drawProbes;
10+
internal SerializedProperty drawNeighbors;
11+
internal SerializedProperty neighborsQuadScale;
912
internal SerializedProperty drawOctahedralDepthRays;
1013
internal SerializedProperty drawOctahedralDepthRayIndexX;
1114
internal SerializedProperty drawOctahedralDepthRayIndexY;
@@ -51,7 +54,10 @@ internal SerializedProbeVolume(SerializedObject serializedObject)
5154
probeVolumeAsset = m_SerializedObject.FindProperty("probeVolumeAsset");
5255

5356
debugColor = probeVolumeParams.FindPropertyRelative("debugColor");
57+
supportDynamicGI = probeVolumeParams.FindPropertyRelative("supportDynamicGI");
5458
drawProbes = probeVolumeParams.FindPropertyRelative("drawProbes");
59+
drawNeighbors = probeVolumeParams.FindPropertyRelative("drawNeighbors");
60+
neighborsQuadScale = probeVolumeParams.FindPropertyRelative("neighborsQuadScale");
5561

5662
drawOctahedralDepthRays = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRays");
5763
drawOctahedralDepthRayIndexX = probeVolumeParams.FindPropertyRelative("drawOctahedralDepthRayIndexX");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ internal class SerializedHDLight
7171
public SerializedProperty evsmLightLeakBias;
7272
public SerializedProperty evsmVarianceBias;
7373
public SerializedProperty evsmBlurPasses;
74+
public SerializedProperty affectDynamicGI;
7475

7576
// Improved moment shadows data
7677
public SerializedProperty lightAngle;
@@ -388,6 +389,7 @@ public SerializedHDLight(HDAdditionalLightData[] lightDatas, LightEditor.Setting
388389
evsmVarianceBias = o.Find("m_EvsmVarianceBias");
389390
evsmLightLeakBias = o.Find("m_EvsmLightLeakBias");
390391
evsmBlurPasses = o.Find("m_EvsmBlurPasses");
392+
affectDynamicGI = o.Find("m_AffectDynamicGI");
391393

392394
// Moment light
393395
lightAngle = o.Find("m_LightAngle");

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,46 @@ IncludeCollection GenerateIncludes()
249249

250250
#endregion
251251

252+
#region DynamicGIExtraDataGen
253+
public static PassDescriptor GenerateDynamicGIExtraDataGen(bool supportLighting)
254+
{
255+
return new PassDescriptor
256+
{
257+
// Definition
258+
displayName = "DynamicGIDataSample",
259+
referenceName = "SHADERPASS_DYNAMIC_GIDATA_SAMPLE",
260+
lightMode = "DynamicGIDataSample",
261+
useInPreview = false,
262+
263+
// We don't need any vertex inputs on meta pass:
264+
validVertexBlocks = new BlockFieldDescriptor[0],
265+
266+
// Collections
267+
requiredFields = CoreRequiredFields.DynamicGIDataSample,
268+
renderStates = CoreRenderStates.Meta,
269+
pragmas = CorePragmas.Basic,
270+
defines = CoreDefines.ShaderGraphRaytracingDefault,
271+
includes = GenerateIncludes(),
272+
};
273+
274+
IncludeCollection GenerateIncludes()
275+
{
276+
var includes = new IncludeCollection();
277+
278+
includes.Add(CoreIncludes.CorePregraph);
279+
if (supportLighting)
280+
includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph);
281+
includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph);
282+
includes.Add(CoreIncludes.CoreUtility);
283+
includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph);
284+
includes.Add(CoreIncludes.kPassDynamicGIExtraDataSample, IncludeLocation.Postgraph);
285+
286+
return includes;
287+
}
288+
}
289+
290+
#endregion
291+
252292
#region Depth Forward Only
253293

254294
public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting)

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ static class CoreRequiredFields
511511
HDStructFields.AttributesMesh.uv2,
512512
};
513513

514+
public static FieldCollection DynamicGIDataSample = new FieldCollection()
515+
{
516+
HDStructFields.FragInputs.tangentToWorld,
517+
HDStructFields.AttributesMesh.uv0,
518+
HDStructFields.AttributesMesh.color,
519+
};
520+
514521
public static FieldCollection PositionRWS = new FieldCollection()
515522
{
516523
HDStructFields.VaryingsMeshToPS.positionRWS,
@@ -942,6 +949,7 @@ static class CoreIncludes
942949

943950
// Public Postgraph Pass
944951
public const string kPassLightTransport = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl";
952+
public const string kPassDynamicGIExtraDataSample = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDynamicGIDataSample.hlsl";
945953
public const string kPassDepthOnly = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl";
946954
public const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl";
947955
public const string kPassMotionVectors = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl";

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ PassCollection GetPasses()
7979
// Common "surface" passes
8080
HDShaderPasses.GenerateShadowCaster(supportLighting),
8181
HDShaderPasses.GenerateMETA(supportLighting),
82+
HDShaderPasses.GenerateDynamicGIExtraDataGen(supportLighting),
8283
HDShaderPasses.GenerateScenePicking(),
8384
HDShaderPasses.GenerateSceneSelection(supportLighting),
8485
HDShaderPasses.GenerateMotionVectors(supportLighting, supportForward),

0 commit comments

Comments
 (0)