Skip to content

Commit ba7e205

Browse files
Ported MaskVolumes and Dynamic GI to RenderGraph (#27)
* Ported MaskVolumes to RenderGraph * Made MaskVolume light lists work with RenderGraph * Made ProbeVolumes DynamicGI work with RenderGraph * Remove accidentially introduced extra space (to avoid merge conflicts in the future) Co-authored-by: Nicholas Brancaccio <pastasfuture@gmail.com>
1 parent 09203b5 commit ba7e205

File tree

7 files changed

+462
-155
lines changed

7 files changed

+462
-155
lines changed

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,16 +3936,23 @@ static void PushProbeVolumeLightListGlobalParams(in LightLoopGlobalParameters pa
39363936
{
39373937
Camera camera = param.hdCamera.camera;
39383938

3939-
if (param.hdCamera.frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass))
3940-
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, param.tileAndClusterData.bigTileLightList);
3941-
3942-
// int useDepthBuffer = 0;
3943-
// cmd.SetGlobalInt(HDShaderIDs.g_isLogBaseBufferEnabled, useDepthBuffer);
3944-
cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLayeredOffsetsBuffer, param.tileAndClusterData.perVoxelOffset);
3945-
cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLightListGlobal, param.tileAndClusterData.perVoxelLightLists);
3939+
DoPushProbeVolumeLightListGlobalParams(
3940+
cmd,
3941+
param.tileAndClusterData.perVoxelOffset,
3942+
param.tileAndClusterData.perVoxelLightLists,
3943+
param.hdCamera.frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass) ? param.tileAndClusterData.bigTileLightList : null);
39463944
}
39473945
}
39483946

3947+
static void DoPushProbeVolumeLightListGlobalParams(CommandBuffer cmd, ComputeBuffer perVoxelOffset, ComputeBuffer perVoxelLightLists, ComputeBuffer bigTileLightList)
3948+
{
3949+
cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLayeredOffsetsBuffer, perVoxelOffset);
3950+
cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLightListGlobal, perVoxelLightLists);
3951+
3952+
if (bigTileLightList != null)
3953+
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, bigTileLightList);
3954+
}
3955+
39493956
static void PushMaskVolumeLightListGlobalParams(in LightLoopGlobalParameters param, CommandBuffer cmd)
39503957
{
39513958
if (!param.hdCamera.frameSettings.IsEnabled(FrameSettingsField.MaskVolume))
@@ -3955,15 +3962,23 @@ static void PushMaskVolumeLightListGlobalParams(in LightLoopGlobalParameters par
39553962
{
39563963
Camera camera = param.hdCamera.camera;
39573964

3958-
if (param.hdCamera.frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass))
3959-
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, param.tileAndClusterData.bigTileLightList);
3960-
3961-
// int useDepthBuffer = 0;
3962-
// cmd.SetGlobalInt(HDShaderIDs.g_isLogBaseBufferEnabled, useDepthBuffer);
3963-
cmd.SetGlobalBuffer(HDShaderIDs.g_vMaskVolumesLayeredOffsetsBuffer, param.tileAndClusterData.perVoxelOffset);
3964-
cmd.SetGlobalBuffer(HDShaderIDs.g_vMaskVolumesLightListGlobal, param.tileAndClusterData.perVoxelLightLists);
3965+
DoPushMaskVolumeLightListGlobalParams(
3966+
cmd,
3967+
param.tileAndClusterData.perVoxelOffset,
3968+
param.tileAndClusterData.perVoxelLightLists,
3969+
param.hdCamera.frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass) ? param.tileAndClusterData.bigTileLightList : null);
39653970
}
39663971
}
3972+
3973+
static void DoPushMaskVolumeLightListGlobalParams(CommandBuffer cmd, ComputeBuffer perVoxelOffset, ComputeBuffer perVoxelLightLists, ComputeBuffer bigTileLightList)
3974+
{
3975+
cmd.SetGlobalBuffer(HDShaderIDs.g_vMaskVolumesLayeredOffsetsBuffer, perVoxelOffset);
3976+
cmd.SetGlobalBuffer(HDShaderIDs.g_vMaskVolumesLightListGlobal, perVoxelLightLists);
3977+
3978+
if (bigTileLightList != null)
3979+
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, bigTileLightList);
3980+
}
3981+
39673982
void BuildGPULightListProbeVolumesCommon(HDCamera hdCamera, CommandBuffer cmd)
39683983
{
39693984
// Custom probe volume only light list is only needed if we are evaluating probe volumes early, in the GBuffer phase.

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -305,41 +305,41 @@ public void ClearAllActive(bool clearAll)
305305
}
306306

307307

308-
internal void DispatchProbePropagation(ScriptableRenderContext renderContext, HDCamera hdCamera, CommandBuffer cmd, ProbeVolumeHandle probeVolume, ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RTHandle probeVolumeAtlasSHRTHandle)
308+
internal void DispatchProbePropagation(CommandBuffer cmd, ProbeVolumeHandle probeVolume, ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RenderTargetIdentifier probeVolumeAtlasSHRTHandle)
309309
{
310-
if (hdCamera.camera.cameraType == CameraType.Game || hdCamera.camera.cameraType == CameraType.SceneView)
310+
if (probeVolume.parameters.supportDynamicGI
311+
&& probeVolume.IsDataAssigned()
312+
&& probeVolume.HasNeighbors()
313+
&& probeVolume.GetProbeVolumeEngineDataIndex() >= 0)
311314
{
312-
if (probeVolume.parameters.supportDynamicGI
313-
&& probeVolume.IsDataAssigned()
314-
&& probeVolume.HasNeighbors()
315-
&& probeVolume.GetProbeVolumeEngineDataIndex() >= 0)
316-
{
317-
InitializePropagationBuffers(probeVolume);
315+
InitializePropagationBuffers(probeVolume);
318316

319-
if (giSettings.clear.value || _clearAllActive)
320-
{
321-
ClearRadianceCache(probeVolume);
322-
}
323-
324-
DispatchPropagationHits(cmd, probeVolume, in giSettings);
325-
DispatchPropagationAxes(cmd, probeVolume, in giSettings);
326-
DispatchPropagationCombine(cmd, probeVolume, in giSettings, in shaderGlobals, probeVolumeAtlasSHRTHandle);
327-
probeVolume.propagationBuffers.SwapRadianceCaches();
317+
if (giSettings.clear.value || _clearAllActive)
318+
{
319+
ClearRadianceCache(probeVolume);
328320
}
329-
else
321+
322+
DispatchPropagationHits(cmd, probeVolume, in giSettings);
323+
DispatchPropagationAxes(cmd, probeVolume, in giSettings);
324+
DispatchPropagationCombine(cmd, probeVolume, in giSettings, in shaderGlobals, probeVolumeAtlasSHRTHandle);
325+
probeVolume.propagationBuffers.SwapRadianceCaches();
326+
}
327+
else
328+
{
329+
if (CleanupPropagation(probeVolume))
330330
{
331-
if (CleanupPropagation(probeVolume))
332-
{
333-
// trigger an update so original bake data gets set since Dynamic GI was disabled
334-
probeVolume.SetDataUpdated(true);
335-
}
331+
// trigger an update so original bake data gets set since Dynamic GI was disabled
332+
probeVolume.SetDataUpdated(true);
336333
}
337334
}
338335
}
339336

340-
internal void ClearProbePropagation(ScriptableRenderContext renderContext, HDCamera hdCamera, CommandBuffer cmd, ProbeVolumeHandle probeVolume, ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RTHandle probeVolumeAtlasSHRTHandle)
337+
internal void ClearProbePropagation(CommandBuffer cmd, ProbeVolumeHandle probeVolume, ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RenderTargetIdentifier probeVolumeAtlasSHRTHandle)
341338
{
342-
if (hdCamera.camera.cameraType == CameraType.Game || hdCamera.camera.cameraType == CameraType.SceneView)
339+
if (probeVolume.parameters.supportDynamicGI
340+
&& probeVolume.IsDataAssigned()
341+
&& probeVolume.HasNeighbors()
342+
&& probeVolume.GetProbeVolumeEngineDataIndex() >= 0)
343343
{
344344
if (probeVolume.parameters.supportDynamicGI
345345
&& probeVolume.IsDataAssigned()
@@ -434,7 +434,7 @@ void DispatchPropagationAxes(CommandBuffer cmd, ProbeVolumeHandle probeVolume, i
434434
cmd.DispatchCompute(shader, kernel, dispatchX, 1, 1);
435435
}
436436

437-
void DispatchPropagationCombine(CommandBuffer cmd, ProbeVolumeHandle probeVolume, in ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RTHandle probeVolumeAtlasSHRTHandle)
437+
void DispatchPropagationCombine(CommandBuffer cmd, ProbeVolumeHandle probeVolume, in ProbeDynamicGI giSettings, in ShaderVariablesGlobal shaderGlobals, RenderTargetIdentifier probeVolumeAtlasSHRTHandle)
438438
{
439439
int numProbes = probeVolume.parameters.resolutionX * probeVolume.parameters.resolutionY * probeVolume.parameters.resolutionZ;
440440
ProbeVolume.ProbeVolumeAtlasKey key = probeVolume.ComputeProbeVolumeAtlasKey();

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

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,46 +1035,89 @@ ProbeVolumeList PrepareVisibleProbeVolumeList(HDCamera hdCamera, CommandBuffer i
10351035
return probeVolumes;
10361036
}
10371037

1038-
void DispatchProbeVolumeDynamicGI(ScriptableRenderContext renderContext, HDCamera hdCamera, CommandBuffer cmd)
1038+
enum ProbeVolumeDynamicGIMode
10391039
{
1040-
if (!m_SupportProbeVolume) { return; }
1040+
None,
1041+
Dispatch,
1042+
Clear
1043+
}
1044+
1045+
struct ProbeVolumeDynamicGICommonData
1046+
{
1047+
public ProbeVolumeDynamicGIMode mode;
1048+
public List<ProbeVolumeHandle> volumes;
1049+
public ProbeDynamicGI giSettings;
1050+
public ShaderVariablesGlobal globalCB;
1051+
}
1052+
1053+
class ProbeVolumeDynamicGIPassData
1054+
{
1055+
public ProbeVolumeDynamicGICommonData commonData;
1056+
public TextureHandle probeVolumesAtlas;
1057+
}
1058+
1059+
ProbeVolumeDynamicGICommonData PrepareProbeVolumeDynamicGIData(HDCamera hdCamera)
1060+
{
1061+
ProbeVolumeDynamicGICommonData data = new ProbeVolumeDynamicGICommonData() { mode = ProbeVolumeDynamicGIMode.None };
1062+
1063+
if (ShaderConfig.s_ProbeVolumesEvaluationMode == ProbeVolumesEvaluationModes.Disabled)
1064+
return data;
1065+
1066+
if (hdCamera.camera.cameraType != CameraType.Game && hdCamera.camera.cameraType != CameraType.SceneView)
1067+
return data;
1068+
1069+
if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume))
1070+
return data;
1071+
1072+
if (!m_SupportProbeVolume)
1073+
return data;
1074+
1075+
data.volumes = ProbeVolumeManager.manager.GetVolumesToRender();
1076+
data.giSettings = hdCamera.volumeStack.GetComponent<ProbeDynamicGI>();
1077+
data.globalCB = m_ShaderVariablesGlobalCB;
10411078

1042-
if(hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolume))
1079+
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolumeDynamicGI))
10431080
{
1044-
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ProbeVolumeDynamicGI)))
1081+
data.mode = ProbeVolumeDynamicGIMode.Dispatch;
1082+
m_WasProbeVolumeDynamicGIEnabled = true;
1083+
}
1084+
else if (m_WasProbeVolumeDynamicGIEnabled)
1085+
{
1086+
data.mode = ProbeVolumeDynamicGIMode.Clear;
1087+
m_WasProbeVolumeDynamicGIEnabled = false;
1088+
}
1089+
1090+
return data;
1091+
}
1092+
1093+
static void ExecuteProbeVolumeDynamicGI(CommandBuffer cmd, ProbeVolumeDynamicGICommonData data, RenderTargetIdentifier probeVolumeAtlas)
1094+
{
1095+
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ProbeVolumeDynamicGI)))
1096+
{
1097+
if (data.mode == ProbeVolumeDynamicGIMode.Dispatch)
10451098
{
1046-
// Collect all visible finite volume data, and upload it to the GPU.
1047-
List<ProbeVolumeHandle> volumes = ProbeVolumeManager.manager.GetVolumesToRender();
1048-
var giSettings = hdCamera.volumeStack.GetComponent<ProbeDynamicGI>();
1049-
float maxRange = Mathf.Max(giSettings.rangeBehindCamera.value, giSettings.rangeInFrontOfCamera.value);
1099+
float maxRange = Mathf.Max(data.giSettings.rangeBehindCamera.value, data.giSettings.rangeInFrontOfCamera.value);
10501100

1051-
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.ProbeVolumeDynamicGI))
1101+
// Update Probe Volume Data via Dynamic GI Propagation
1102+
for (int probeVolumeIndex = 0; probeVolumeIndex < data.volumes.Count; ++probeVolumeIndex)
10521103
{
1053-
m_WasProbeVolumeDynamicGIEnabled = true;
1104+
ProbeVolumeHandle volume = data.volumes[probeVolumeIndex];
10541105

1055-
// Update Probe Volume Data via Dynamic GI Propagation
1056-
for (int probeVolumeIndex = 0; probeVolumeIndex < volumes.Count; ++probeVolumeIndex)
1106+
// basic distance check
1107+
var obb = volume.GetProbeVolumeEngineDataBoundingBox();
1108+
float maxExtent = Mathf.Max(obb.extentX, Mathf.Max(obb.extentY, obb.extentZ));
1109+
if (obb.center.magnitude < (maxRange + maxExtent))
10571110
{
1058-
ProbeVolumeHandle volume = volumes[probeVolumeIndex];
1059-
1060-
// basic distance check
1061-
var obb = volume.GetProbeVolumeEngineDataBoundingBox();
1062-
float maxExtent = Mathf.Max(obb.extentX, Mathf.Max(obb.extentY, obb.extentZ));
1063-
if (obb.center.magnitude < (maxRange + maxExtent))
1064-
{
1065-
ProbeVolumeDynamicGI.instance.DispatchProbePropagation(renderContext, hdCamera, cmd, volume, giSettings, in m_ShaderVariablesGlobalCB, m_ProbeVolumeAtlasSHRTHandle);
1066-
}
1111+
ProbeVolumeDynamicGI.instance.DispatchProbePropagation(cmd, volume, data.giSettings, in data.globalCB, probeVolumeAtlas);
10671112
}
10681113
}
1069-
else if(m_WasProbeVolumeDynamicGIEnabled)
1114+
}
1115+
else if (data.mode == ProbeVolumeDynamicGIMode.Clear)
1116+
{
1117+
for (int probeVolumeIndex = 0; probeVolumeIndex < data.volumes.Count; ++probeVolumeIndex)
10701118
{
1071-
for (int probeVolumeIndex = 0; probeVolumeIndex < volumes.Count; ++probeVolumeIndex)
1072-
{
1073-
ProbeVolumeHandle volume = volumes[probeVolumeIndex];
1074-
ProbeVolumeDynamicGI.instance.ClearProbePropagation(renderContext, hdCamera, cmd, volume, giSettings, in m_ShaderVariablesGlobalCB, m_ProbeVolumeAtlasSHRTHandle);
1075-
}
1076-
1077-
m_WasProbeVolumeDynamicGIEnabled = false;
1119+
ProbeVolumeHandle volume = data.volumes[probeVolumeIndex];
1120+
ProbeVolumeDynamicGI.instance.ClearProbePropagation(cmd, volume, data.giSettings, in data.globalCB, probeVolumeAtlas);
10781121
}
10791122
}
10801123
}

0 commit comments

Comments
 (0)