UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[RenderGraph] Stop Disabled Objects Draining Performance

Solution

optimizationperformance

Unity 2022.3.x - Unity 6.3.x

Published Sat, Mar 14

Issue

 When attempting to render a specific subset of game objects into a separate Render Graph buffer using DrawRendererList, a common issue arises. If the Renderer components for these objects are disabled to prevent their inclusion in the main camera render pass, DrawRendererList fails to process them entirely.

Conversely, if the renderers remain enabled, the objects are drawn twice: once by the regular camera and once into the custom buffer, despite efforts to filter them using renderingLayerMask and FilteringSettings.

Quick-Fix

Modify the cullingMask within ScriptableCullingParameters to exclude custom layers from the main camera pass while explicitly including them for Render Graph DrawRendererList operations. This ensures objects are culled correctly without being disabled.

Expand Analysis

Assign objects for custom passes to dedicated rendering layers to separate them from the default geometry.

  1. Access ScriptableCullingParameters from your script during the setup phase of your scriptable render pass.
  2. Modify the cullingMask by performing bitwise operations to remove the specific bits corresponding to your custom layers from the main camera’s view.
  3. Generate the CullingResults using the updated cullingMask via the ScriptableRenderContext before recording the graph.
  4. Create a pass in the RecordRenderGraph method that utilizes these filtered results for the DrawRendererList call.
  5. Define the RendererListDesc such that its filter settings match the layers defined in the cullingMask to ensure consistency between culling and drawing.

Additional Tips

  • Use bit shifting like ~(1 << layerIndex) to isolate and remove specific layers within the cullingMask bitmask.
  • Ensure that the GameObject layer matches the intended rendering layer, as the cullingMask operates on the standard layer system rather than the renderingLayerMask property.

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.