Skip to content

Instantly share code, notes, and snippets.

@Dessix
Last active January 8, 2022 20:19
Show Gist options
  • Save Dessix/14e6b3c8c0b73e1454d54db06e908c98 to your computer and use it in GitHub Desktop.
Save Dessix/14e6b3c8c0b73e1454d54db06e908c98 to your computer and use it in GitHub Desktop.
HDRP RenderingLayerMask Setting - Per-camera runtime overrides for `renderingLayerMask`
using System;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
public class Test : MonoBehaviour {
[SerializeReference] public Camera Camera;
[SerializeReference] public GameObject SubScene;
public void Start() {
var hdc = HDCamera.GetOrCreate(this.Camera);
var hdcs = hdc.camera.GetComponent<HDAdditionalCameraData>();
var mask = hdcs.renderingPathCustomFrameSettingsOverrideMask;
var vals = hdcs.renderingPathCustomFrameSettings;
uint ultracull = 1 << 16; // Where to hide SubScene geometry
mask.mask[(uint)FrameSettingsField.OverrideRenderingLayerMask] = true; // Enable the override
vals.overrideRenderingLayerMask = ultracull | 1 << 17; // Allow the camera to see anything in only RLs 16 and 17
hdcs.renderingPathCustomFrameSettings = vals; // Apply the modified settings to the camera
hdcs.renderingPathCustomFrameSettingsOverrideMask = mask; // Apply the modified overrides
hdcs.customRenderingSettings = true; // Indicate that we've overridden the frame settings at all
// Adjust all renderers in the SubScene to target the ultracull submask
foreach (var r in SubScene.GetComponentsInChildren<Renderer>(true)) {
r.renderingLayerMask = ultracull;
}
// Lighting still doesn't work; also, Unity stores light RLM inconsistently (int) from renderer RLM (uint)
foreach (var r in SubScene.GetComponentsInChildren<Light>(true)) {
r.renderingLayerMask = BitConverter.ToInt32(BitConverter.GetBytes(ultracull));
}
}
}
Left base folder: ./Library/PackageCache/[email protected]
Right base folder: ./com.unity.render-pipelines.high-definition
--- Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs 2021-12-27 23:45:26.000000000
+++ Editor/RenderPipeline/Settings/FrameSettingsUI.Drawers.cs 2022-01-07 12:46:34.000000000
@@ -237,12 +237,21 @@
overridedDefaultValue: defaultFrameSettings?.materialQuality.Into() ?? MaterialQualityMode.Medium,
customGetter: () => ((MaterialQuality)serialized.materialQuality.intValue).Into(),
customSetter: v => serialized.materialQuality.intValue = (int)((MaterialQualityMode)v).Into(),
hasMixedValues: serialized.materialQuality.hasMultipleDifferentValues
);
+ area.AmmendInfo(FrameSettingsField.OverrideRenderingLayerMask,
+ overridedDefaultValue: (long)0,
+ customGetter: () => serialized.overrideRenderingLayerMask.longValue,
+ customSetter: v => serialized.overrideRenderingLayerMask.uintValue = v is null || (long)v < 0 ? 0 : (uint)(long)v,
+ overrideable: () => (serialized.IsEnabled(FrameSettingsField.OverrideRenderingLayerMask) ?? false),
+ ignoreDependencies: true,
+ hasMixedValues: serialized.overrideRenderingLayerMask.hasMultipleDifferentValues
+ );
+
area.Draw(withOverride);
GUI.enabled = isGUIenabled;
}
// Use an enum to have appropriate UI enum field in the frame setting api
// Do not use anywhere else
--- Editor/RenderPipeline/Settings/OverridableFrameSettingsArea.cs 2021-12-27 23:45:26.000000000
+++ Editor/RenderPipeline/Settings/OverridableFrameSettingsArea.cs 2022-01-07 12:53:21.000000000
@@ -343,12 +343,16 @@
else if (field is string)
return EditorGUI.TextField(rect, (string)field);
else if (field is bool)
return EditorGUI.Toggle(rect, (bool)field);
else if (field is int)
return EditorGUI.IntField(rect, (int)field);
+ else if (field is uint)
+ return EditorGUI.LongField(rect, (uint)field);
+ else if (field is long)
+ return EditorGUI.LongField(rect, (long)field);
else if (field is float)
return EditorGUI.FloatField(rect, (float)field);
else if (field is Color)
return EditorGUI.ColorField(rect, (Color)field);
else if (field is Enum)
return EditorGUI.EnumPopup(rect, (Enum)field);
--- Editor/RenderPipeline/Settings/SerializedFrameSettings.cs 2021-12-27 23:45:26.000000000
+++ Editor/RenderPipeline/Settings/SerializedFrameSettings.cs 2022-01-07 12:35:33.000000000
@@ -19,12 +19,13 @@
public SerializedProperty lodBiasQualityLevel;
public SerializedProperty maximumLODLevel;
public SerializedProperty maximumLODLevelMode;
public SerializedProperty maximumLODLevelQualityLevel;
public SerializedProperty materialQuality;
public SerializedProperty msaaMode;
+ public SerializedProperty overrideRenderingLayerMask;
public SerializedObject serializedObject => m_RootData.serializedObject;
public LitShaderMode? litShaderMode
{
get
@@ -91,12 +92,13 @@
lodBiasQualityLevel = rootData.FindPropertyRelative("lodBiasQualityLevel");
maximumLODLevel = rootData.FindPropertyRelative("maximumLODLevel");
maximumLODLevelMode = rootData.FindPropertyRelative("maximumLODLevelMode");
maximumLODLevelQualityLevel = rootData.FindPropertyRelative("maximumLODLevelQualityLevel");
materialQuality = rootData.Find((FrameSettings s) => s.materialQuality);
msaaMode = rootData.FindPropertyRelative("msaaMode");
+ overrideRenderingLayerMask = rootData.FindPropertyRelative("overrideRenderingLayerMask");
}
public struct TitleDrawingScope : IDisposable
{
bool hasOverride;
--- Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs 2021-12-27 23:45:27.000000000
+++ Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs 2022-01-06 20:52:43.000000000
@@ -6,13 +6,13 @@
namespace UnityEngine.Rendering.HighDefinition
{
/// <summary>
/// Class that holds data and logic for the pass to be executed
/// </summary>
[System.Serializable]
- public abstract class CustomPass : IVersionable<DrawRenderersCustomPass.Version>
+ public abstract class CustomPass : IVersionable<CustomPass.Version>
{
/// <summary>
/// Name of the custom pass
/// </summary>
public string name
{
--- Runtime/RenderPipeline/HDRenderPipeline.cs 2021-12-27 23:45:27.000000000
+++ Runtime/RenderPipeline/HDRenderPipeline.cs 2022-01-07 11:41:58.000000000
@@ -2458,99 +2458,114 @@
#endif
}
}
static RendererListDesc CreateOpaqueRendererListDesc(
CullingResults cull,
- Camera camera,
+ HDCamera hdCamera,
ShaderTagId passName,
PerObjectData rendererConfiguration = 0,
RenderQueueRange? renderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null,
bool excludeObjectMotionVectors = false
)
{
- var result = new RendererListDesc(passName, cull, camera)
+ var result = new RendererListDesc(passName, cull, hdCamera.camera)
{
rendererConfiguration = rendererConfiguration,
renderQueueRange = renderQueueRange != null ? renderQueueRange.Value : HDRenderQueue.k_RenderQueue_AllOpaque,
sortingCriteria = SortingCriteria.CommonOpaque,
stateBlock = stateBlock,
overrideMaterial = overrideMaterial,
- excludeObjectMotionVectors = excludeObjectMotionVectors
+ excludeObjectMotionVectors = excludeObjectMotionVectors,
};
+ var overrideRenderingLayerMask = hdCamera.frameSettings.overrideRenderingLayerMask;
+ if (overrideRenderingLayerMask != 0) {
+ result.renderingLayerMask = overrideRenderingLayerMask;
+ }
return result;
}
static RendererListDesc CreateOpaqueRendererListDesc(
CullingResults cull,
- Camera camera,
+ HDCamera hdCamera,
ShaderTagId[] passNames,
PerObjectData rendererConfiguration = 0,
RenderQueueRange? renderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null,
bool excludeObjectMotionVectors = false
)
{
- var result = new RendererListDesc(passNames, cull, camera)
+ var result = new RendererListDesc(passNames, cull, hdCamera.camera)
{
rendererConfiguration = rendererConfiguration,
renderQueueRange = renderQueueRange != null ? renderQueueRange.Value : HDRenderQueue.k_RenderQueue_AllOpaque,
sortingCriteria = SortingCriteria.CommonOpaque,
stateBlock = stateBlock,
overrideMaterial = overrideMaterial,
excludeObjectMotionVectors = excludeObjectMotionVectors
};
+ var overrideRenderingLayerMask = hdCamera.frameSettings.overrideRenderingLayerMask;
+ if (overrideRenderingLayerMask != 0) {
+ result.renderingLayerMask = overrideRenderingLayerMask;
+ }
return result;
}
static RendererListDesc CreateTransparentRendererListDesc(
CullingResults cull,
- Camera camera,
+ HDCamera hdCamera,
ShaderTagId passName,
PerObjectData rendererConfiguration = 0,
RenderQueueRange? renderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null,
bool excludeObjectMotionVectors = false
)
{
- var result = new RendererListDesc(passName, cull, camera)
+ var result = new RendererListDesc(passName, cull, hdCamera.camera)
{
rendererConfiguration = rendererConfiguration,
renderQueueRange = renderQueueRange != null ? renderQueueRange.Value : HDRenderQueue.k_RenderQueue_AllTransparent,
sortingCriteria = SortingCriteria.CommonTransparent | SortingCriteria.RendererPriority,
stateBlock = stateBlock,
overrideMaterial = overrideMaterial,
excludeObjectMotionVectors = excludeObjectMotionVectors
};
+ var overrideRenderingLayerMask = hdCamera.frameSettings.overrideRenderingLayerMask;
+ if (overrideRenderingLayerMask != 0) {
+ result.renderingLayerMask = overrideRenderingLayerMask;
+ }
return result;
}
static RendererListDesc CreateTransparentRendererListDesc(
CullingResults cull,
- Camera camera,
+ HDCamera hdCamera,
ShaderTagId[] passNames,
PerObjectData rendererConfiguration = 0,
RenderQueueRange? renderQueueRange = null,
RenderStateBlock? stateBlock = null,
Material overrideMaterial = null,
bool excludeObjectMotionVectors = false
- )
- {
- var result = new RendererListDesc(passNames, cull, camera)
+ ) {
+ var result = new RendererListDesc(passNames, cull, hdCamera.camera)
{
rendererConfiguration = rendererConfiguration,
renderQueueRange = renderQueueRange != null ? renderQueueRange.Value : HDRenderQueue.k_RenderQueue_AllTransparent,
sortingCriteria = SortingCriteria.CommonTransparent | SortingCriteria.RendererPriority,
stateBlock = stateBlock,
overrideMaterial = overrideMaterial,
excludeObjectMotionVectors = excludeObjectMotionVectors
};
+ var overrideRenderingLayerMask = hdCamera.frameSettings.overrideRenderingLayerMask;
+ if (overrideRenderingLayerMask != 0) {
+ result.renderingLayerMask = overrideRenderingLayerMask;
+ }
return result;
}
static void DrawOpaqueRendererList(in ScriptableRenderContext renderContext, CommandBuffer cmd, in FrameSettings frameSettings, RendererList rendererList)
{
if (!frameSettings.IsEnabled(FrameSettingsField.OpaqueObjects))
@@ -2583,17 +2598,17 @@
void RenderWireFrame(CullingResults cull, HDCamera hdCamera, RenderTargetIdentifier backbuffer, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RenderWireFrame)))
{
CoreUtils.SetRenderTarget(cmd, backbuffer, ClearFlag.Color, GetColorBufferClearColor(hdCamera));
- var rendererListOpaque = renderContext.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_AllForwardOpaquePassNames));
+ var rendererListOpaque = renderContext.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, m_AllForwardOpaquePassNames));
DrawOpaqueRendererList(renderContext, cmd, hdCamera.frameSettings, rendererListOpaque);
// Render forward transparent
- var rendererListTransparent = renderContext.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera.camera, m_AllTransparentPassNames));
+ var rendererListTransparent = renderContext.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera, m_AllTransparentPassNames));
DrawTransparentRendererList(renderContext, cmd, hdCamera.frameSettings, rendererListTransparent);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
renderContext.DrawGizmos(hdCamera.camera, GizmoSubset.PreImageEffects);
renderContext.DrawGizmos(hdCamera.camera, GizmoSubset.PostImageEffects);
--- Runtime/RenderPipeline/HDRenderPipeline.Debug.cs 2021-12-27 23:45:27.000000000
+++ Runtime/RenderPipeline/HDRenderPipeline.Debug.cs 2022-01-07 11:21:52.000000000
@@ -258,17 +258,17 @@
};
passData.frameSettings = hdCamera.frameSettings;
passData.constantBuffer = m_ShaderVariablesDebugDisplayCB;
builder.UseDepthBuffer(depthBuffer, DepthAccess.Read);
passData.transparencyRL = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cull, hdCamera.camera, passNames, stateBlock: stateBlock)));
+ CreateTransparentRendererListDesc(cull, hdCamera, passNames, stateBlock: stateBlock)));
passData.transparencyAfterPostRL = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera.camera, passNames, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent, stateBlock: stateBlock)));
+ renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera, passNames, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent, stateBlock: stateBlock)));
passData.transparencyLowResRL = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera.camera, passNames, renderQueueRange: HDRenderQueue.k_RenderQueue_LowTransparent, stateBlock: stateBlock)));
+ renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera, passNames, renderQueueRange: HDRenderQueue.k_RenderQueue_LowTransparent, stateBlock: stateBlock)));
transparencyOverdrawOutput = builder.UseColorBuffer(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { name = "Transparency Overdraw", colorFormat = GetColorBufferFormat(), clearBuffer = true, clearColor = Color.black }), 0);
builder.SetRenderFunc(
(TransparencyOverdrawPassData data, RenderGraphContext ctx) =>
{
@@ -308,13 +308,13 @@
{
fullscreenDebugOutput = builder.UseColorBuffer(colorBuffer, 0);
builder.UseDepthBuffer(depthBuffer, DepthAccess.Read);
passData.frameSettings = hdCamera.frameSettings;
passData.debugBuffer = builder.WriteComputeBuffer(renderGraph.CreateComputeBuffer(new ComputeBufferDesc(hdCamera.actualWidth * hdCamera.actualHeight * hdCamera.viewCount, sizeof(uint))));
- passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_FullScreenDebugPassNames, renderQueueRange: RenderQueueRange.all)));
+ passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, m_FullScreenDebugPassNames, renderQueueRange: RenderQueueRange.all)));
passData.clearBufferCS = m_ClearFullScreenBufferCS;
passData.clearBufferCSKernel = m_ClearFullScreenBufferKernel;
passData.numPixels = (int)hdCamera.screenSize.x * (int)hdCamera.screenSize.y;
passData.numViews = hdCamera.viewCount;
builder.SetRenderFunc(
@@ -1261,17 +1261,17 @@
passData.outputColor = builder.UseColorBuffer(output, 0);
passData.outputDepth = builder.UseDepthBuffer(CreateDepthBuffer(renderGraph, true, hdCamera.msaaSamples), DepthAccess.ReadWrite);
// When rendering debug material we shouldn't rely on a depth prepass for optimizing the alpha clip test. As it is control on the material inspector side
// we must override the state here.
passData.opaqueRendererList = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_AllForwardOpaquePassNames,
+ renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, m_AllForwardOpaquePassNames,
rendererConfiguration: m_CurrentRendererConfigurationBakedLighting,
stateBlock: m_DepthStateOpaque)));
passData.transparentRendererList = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera.camera, m_AllTransparentPassNames,
+ renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera, m_AllTransparentPassNames,
rendererConfiguration: m_CurrentRendererConfigurationBakedLighting,
stateBlock: m_DepthStateNoWrite)));
passData.decalsEnabled = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Decals)) && (DecalSystem.m_DecalDatasCount > 0);
passData.perVoxelOffset = builder.ReadComputeBuffer(lightLists.perVoxelOffset);
passData.dbuffer = ReadDBuffer(dbuffer, builder);
--- Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs 2021-12-27 23:45:27.000000000
+++ Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs 2022-01-07 11:21:52.000000000
@@ -308,14 +308,14 @@
// This will save performance because we reduce overdraw of non recursive rendering objects.
// This is also required to avoid marking the pixels for various effects like motion blur and such.
using (var builder = renderGraph.AddRenderPass<RayTracingDepthPrepassData>("RayTracing Depth Prepass", out var passData, ProfilingSampler.Get(HDProfileId.RayTracingDepthPrepass)))
{
passData.frameSettings = hdCamera.frameSettings;
passData.depthBuffer = builder.UseDepthBuffer(depthBuffer, DepthAccess.ReadWrite);
- passData.opaqueRenderList = builder.UseRendererList(renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_RayTracingPrepassNames)));
- passData.transparentRenderList = builder.UseRendererList(renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera.camera, m_RayTracingPrepassNames)));
+ passData.opaqueRenderList = builder.UseRendererList(renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, m_RayTracingPrepassNames)));
+ passData.transparentRenderList = builder.UseRendererList(renderGraph.CreateRendererList(CreateTransparentRendererListDesc(cull, hdCamera, m_RayTracingPrepassNames)));
builder.SetRenderFunc(
(RayTracingDepthPrepassData data, RenderGraphContext context) =>
{
DrawOpaqueRendererList(context.renderContext, context.cmd, data.frameSettings, data.opaqueRenderList);
DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.transparentRenderList);
@@ -436,13 +436,13 @@
using (var builder = renderGraph.AddRenderPass<DrawRendererListPassData>(deferredPassName, out var passData, ProfilingSampler.Get(HDProfileId.DeferredDepthPrepass)))
{
builder.AllowRendererListCulling(false);
passData.frameSettings = hdCamera.frameSettings;
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(
- cull, hdCamera.camera, m_DepthOnlyPassNames,
+ cull, hdCamera, m_DepthOnlyPassNames,
renderQueueRange: fullDeferredPrepass ? HDRenderQueue.k_RenderQueue_AllOpaque :
(decalsEnabled ? HDRenderQueue.k_RenderQueue_OpaqueDecalAndAlphaTest : HDRenderQueue.k_RenderQueue_OpaqueAlphaTest),
stateBlock: m_AlphaToMaskBlock,
excludeObjectMotionVectors: excludeMotion)));
output.depthBuffer = builder.UseDepthBuffer(output.depthBuffer, DepthAccess.ReadWrite);
@@ -476,19 +476,19 @@
{
RenderStateBlock? stateBlock = null;
if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.AlphaToMask))
stateBlock = m_AlphaToMaskBlock;
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_DepthOnlyAndDepthForwardOnlyPassNames, stateBlock: stateBlock, excludeObjectMotionVectors: objectMotionEnabled)));
+ CreateOpaqueRendererListDesc(cull, hdCamera, m_DepthOnlyAndDepthForwardOnlyPassNames, stateBlock: stateBlock, excludeObjectMotionVectors: objectMotionEnabled)));
}
else if (hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred)
{
// Forward only material that output normal buffer
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_DepthForwardOnlyPassNames, stateBlock: m_AlphaToMaskBlock, excludeObjectMotionVectors: excludeMotion)));
+ CreateOpaqueRendererListDesc(cull, hdCamera, m_DepthForwardOnlyPassNames, stateBlock: m_AlphaToMaskBlock, excludeObjectMotionVectors: excludeMotion)));
}
builder.SetRenderFunc(
(DrawRendererListPassData data, RenderGraphContext context) =>
{
DrawOpaqueRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList);
@@ -542,13 +542,13 @@
BindMotionVectorPassColorBuffers(builder, output, decalBuffer, hdCamera);
RenderStateBlock? stateBlock = null;
if (hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred || !hdCamera.frameSettings.IsEnabled(FrameSettingsField.AlphaToMask))
stateBlock = m_AlphaToMaskBlock;
passData.rendererList = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, HDShaderPassNames.s_MotionVectorsName, PerObjectData.MotionVectors, stateBlock: stateBlock)));
+ renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, HDShaderPassNames.s_MotionVectorsName, PerObjectData.MotionVectors, stateBlock: stateBlock)));
builder.SetRenderFunc(
(DrawRendererListPassData data, RenderGraphContext context) =>
{
DrawOpaqueRendererList(context, data.frameSettings, data.rendererList);
});
@@ -669,13 +669,13 @@
FrameSettings frameSettings = hdCamera.frameSettings;
passData.frameSettings = frameSettings;
SetupGBufferTargets(renderGraph, hdCamera, sssBuffer, vtFeedbackBuffer, ref prepassOutput, frameSettings, builder);
passData.rendererList = builder.UseRendererList(
- renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera.camera, HDShaderPassNames.s_GBufferName, m_CurrentRendererConfigurationBakedLighting)));
+ renderGraph.CreateRendererList(CreateOpaqueRendererListDesc(cull, hdCamera, HDShaderPassNames.s_GBufferName, m_CurrentRendererConfigurationBakedLighting)));
passData.dBuffer = ReadDBuffer(prepassOutput.dbuffer, builder);
builder.SetRenderFunc(
(GBufferPassData data, RenderGraphContext context) =>
{
--- Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs 2021-12-27 23:45:27.000000000
+++ Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs 2022-01-07 11:21:52.000000000
@@ -209,13 +209,13 @@
{
aovRequest.PushCameraTexture(m_RenderGraph, AOVBuffers.DepthStencil, hdCamera, prepassOutput.resolvedDepthBuffer, aovBuffers);
if (m_Asset.currentPlatformRenderPipelineSettings.supportMotionVectors)
aovRequest.PushCameraTexture(m_RenderGraph, AOVBuffers.MotionVectors, hdCamera, prepassOutput.resolvedMotionVectorsBuffer, aovBuffers);
}
- var distortionRendererList = m_RenderGraph.CreateRendererList(CreateTransparentRendererListDesc(cullingResults, hdCamera.camera, HDShaderPassNames.s_DistortionVectorsName));
+ var distortionRendererList = m_RenderGraph.CreateRendererList(CreateTransparentRendererListDesc(cullingResults, hdCamera, HDShaderPassNames.s_DistortionVectorsName));
// This final Gaussian pyramid can be reused by SSR, so disable it only if there is no distortion
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Distortion) && hdCamera.frameSettings.IsEnabled(FrameSettingsField.RoughDistortion))
{
TextureHandle distortionColorPyramid = m_RenderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true)
@@ -341,12 +341,13 @@
AOVRequestData aovRequest,
List<RTHandle> aovBuffers,
List<RTHandle> aovCustomPassBuffers,
ScriptableRenderContext renderContext,
CommandBuffer commandBuffer)
{
+ // if (renderRequest.cameraSettings.culling.sceneCullingMaskOverride == 1337 && renderRequest.)
using (m_RenderGraph.RecordAndExecute(new RenderGraphParameters
{
executionName = renderRequest.hdCamera.name,
currentFrameIndex = m_FrameCount,
rendererListCulling = m_GlobalSettings.rendererListCulling,
scriptableRenderContext = renderContext,
@@ -728,13 +729,13 @@
RendererListDesc PrepareForwardOpaqueRendererList(CullingResults cullResults, HDCamera hdCamera)
{
var passNames = hdCamera.frameSettings.litShaderMode == LitShaderMode.Forward
? m_ForwardAndForwardOnlyPassNames
: m_ForwardOnlyPassNames;
- return CreateOpaqueRendererListDesc(cullResults, hdCamera.camera, passNames, m_CurrentRendererConfigurationBakedLighting);
+ return CreateOpaqueRendererListDesc(cullResults, hdCamera, passNames, m_CurrentRendererConfigurationBakedLighting);
}
RendererListDesc PrepareForwardTransparentRendererList(CullingResults cullResults, HDCamera hdCamera, bool preRefraction)
{
RenderQueueRange transparentRange;
if (preRefraction)
@@ -761,13 +762,13 @@
if (NeedMotionVectorForTransparent(hdCamera.frameSettings))
{
m_CurrentRendererConfigurationBakedLighting |= PerObjectData.MotionVectors; // This will enable the flag for low res transparent as well
}
var passNames = m_Asset.currentPlatformRenderPipelineSettings.supportTransparentBackface ? m_AllTransparentPassNames : m_TransparentNoBackfaceNames;
- return CreateTransparentRendererListDesc(cullResults, hdCamera.camera, passNames, m_CurrentRendererConfigurationBakedLighting, transparentRange);
+ return CreateTransparentRendererListDesc(cullResults, hdCamera, passNames, m_CurrentRendererConfigurationBakedLighting, transparentRange);
}
static void RenderForwardRendererList(FrameSettings frameSettings,
RendererList rendererList,
bool opaque,
ScriptableRenderContext renderContext,
@@ -865,13 +866,13 @@
using (var builder = renderGraph.AddRenderPass<ForwardPassData>("Forward Error", out var passData, ProfilingSampler.Get(HDProfileId.RenderForwardError)))
{
builder.UseColorBuffer(colorBuffer, 0);
builder.UseDepthBuffer(depthStencilBuffer, DepthAccess.ReadWrite);
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateOpaqueRendererListDesc(cullResults, hdCamera.camera, m_ForwardErrorPassNames, renderQueueRange: RenderQueueRange.all, overrideMaterial: m_ErrorMaterial)));
+ CreateOpaqueRendererListDesc(cullResults, hdCamera, m_ForwardErrorPassNames, renderQueueRange: RenderQueueRange.all, overrideMaterial: m_ErrorMaterial)));
builder.SetRenderFunc(
(ForwardPassData data, RenderGraphContext context) =>
{
CoreUtils.DrawRendererList(context.renderContext, context.cmd, data.rendererList);
});
@@ -935,15 +936,15 @@
{
bool useDepthBuffer = !hdCamera.RequiresCameraJitter() && hdCamera.frameSettings.IsEnabled(FrameSettingsField.ZTestAfterPostProcessTAA);
passData.globalCB = m_ShaderVariablesGlobalCB;
passData.hdCamera = hdCamera;
passData.opaqueAfterPostprocessRL = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateOpaqueRendererListDesc(cullResults, hdCamera.camera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessOpaque)));
+ CreateOpaqueRendererListDesc(cullResults, hdCamera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessOpaque)));
passData.transparentAfterPostprocessRL = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cullResults, hdCamera.camera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent)));
+ CreateTransparentRendererListDesc(cullResults, hdCamera, HDShaderPassNames.s_ForwardOnlyName, renderQueueRange: HDRenderQueue.k_RenderQueue_AfterPostProcessTransparent)));
var output = builder.UseColorBuffer(renderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_SRGB, clearBuffer = true, clearColor = Color.black, name = "OffScreen AfterPostProcess" }), 0);
if (useDepthBuffer)
builder.UseDepthBuffer(prepassOutput.resolvedDepthBuffer, DepthAccess.ReadWrite);
@@ -1098,13 +1099,13 @@
if (hdCamera.msaaEnabled)
builder.UseColorBuffer(prepassOutput.depthAsColor, index++);
builder.UseColorBuffer(prepassOutput.normalBuffer, index++);
}
builder.UseDepthBuffer(prepassOutput.depthBuffer, DepthAccess.ReadWrite);
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cull, hdCamera.camera, m_TransparentDepthPrepassNames)));
+ CreateTransparentRendererListDesc(cull, hdCamera, m_TransparentDepthPrepassNames)));
builder.SetRenderFunc(
(ForwardPassData data, RenderGraphContext context) =>
{
DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList);
});
@@ -1118,13 +1119,13 @@
using (var builder = renderGraph.AddRenderPass<ForwardPassData>("Transparent Depth Postpass", out var passData, ProfilingSampler.Get(HDProfileId.TransparentDepthPostpass)))
{
passData.frameSettings = hdCamera.frameSettings;
builder.UseDepthBuffer(depthStencilBuffer, DepthAccess.ReadWrite);
passData.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cull, hdCamera.camera, m_TransparentDepthPostpassNames)));
+ CreateTransparentRendererListDesc(cull, hdCamera, m_TransparentDepthPostpassNames)));
builder.SetRenderFunc(
(ForwardPassData data, RenderGraphContext context) =>
{
DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList);
});
@@ -1253,15 +1254,15 @@
using (var builder = renderGraph.AddRenderPass<RayTracingFlagMaskPassData>("RayTracing Flag Mask", out var passData, ProfilingSampler.Get(HDProfileId.RayTracingFlagMask)))
{
passData.frameSettings = hdCamera.frameSettings;
passData.depthBuffer = builder.UseDepthBuffer(depthBuffer, DepthAccess.Read);
passData.flagMask = builder.UseColorBuffer(CreateFlagMaskTexture(renderGraph), 0);
passData.opaqueRenderList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateOpaqueRendererListDesc(cull, hdCamera.camera, m_RayTracingPrepassNames, stateBlock: m_DepthStateNoWrite)));
+ CreateOpaqueRendererListDesc(cull, hdCamera, m_RayTracingPrepassNames, stateBlock: m_DepthStateNoWrite)));
passData.transparentRenderList = builder.UseRendererList(renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cull, hdCamera.camera, m_RayTracingPrepassNames, renderQueueRange: HDRenderQueue.k_RenderQueue_AllTransparentWithLowRes, stateBlock: m_DepthStateNoWrite)));
+ CreateTransparentRendererListDesc(cull, hdCamera, m_RayTracingPrepassNames, renderQueueRange: HDRenderQueue.k_RenderQueue_AllTransparentWithLowRes, stateBlock: m_DepthStateNoWrite)));
builder.SetRenderFunc(
(RayTracingFlagMaskPassData data, RenderGraphContext context) =>
{
DrawOpaqueRendererList(context.renderContext, context.cmd, data.frameSettings, data.opaqueRenderList);
DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.transparentRenderList);
@@ -1331,13 +1332,13 @@
RenderForwardError(renderGraph, hdCamera, colorBuffer, prepassOutput.resolvedDepthBuffer, cullingResults);
if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.LowResTransparent))
{
var passNames = m_Asset.currentPlatformRenderPipelineSettings.supportTransparentBackface ? m_AllTransparentPassNames : m_TransparentNoBackfaceNames;
var lowResTranspRendererList = renderGraph.CreateRendererList(
- CreateTransparentRendererListDesc(cullingResults, hdCamera.camera, passNames, m_CurrentRendererConfigurationBakedLighting, HDRenderQueue.k_RenderQueue_LowTransparent));
+ CreateTransparentRendererListDesc(cullingResults, hdCamera, passNames, m_CurrentRendererConfigurationBakedLighting, HDRenderQueue.k_RenderQueue_LowTransparent));
ApplyCameraMipBias(hdCamera);
var lowResTransparentBuffer = RenderLowResTransparent(renderGraph, hdCamera, prepassOutput.downsampledDepthBuffer, cullingResults, lowResTranspRendererList);
ResetCameraMipBias(hdCamera);
UpsampleTransparent(renderGraph, hdCamera, colorBuffer, lowResTransparentBuffer, prepassOutput.downsampledDepthBuffer, lowResTranspRendererList);
}
@Dessix
Copy link
Author

Dessix commented Jan 8, 2022

This patch (when applied to a LocalPackage copy of HDRP 13.1.3) adds RenderingLayerMask to the FrameSettings, letting you render a subset of geometry more dynamically than with Unity's standard Layers.

Caveat / Request for assistance:

I haven't been able to get lights and shadows to not "cross the gap" between RLMs. If you thoroughly understands the lighting system, I'd love some help making this possible, as the default layer system is rather limited.

An example of the lighting issue, wherein geometry is split into two renderlayers, one with some geometry and a light, and another with the plane below the camera; the camera is set to only see the latter:
image
Note that the camera should only see the un-masked world-light and the plane, but it is also receiving and reflecting the masked light in the hidden world:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment