Skip to content

Commit 9ff2bb4

Browse files
ApoorvaJEvergreen
authored andcommitted
Improve URP light masking UI
Our light masking is too complicated at the moment. Users, our own QA folks and our own engineers are confused by it. Here's quite a [highly voted feature request](https://issuetracker-mig.prd.it.unity3d.com/issues/urp-light-culling-mask-does-not-work-when-using-forward-plus-rendering-path) that asks for support in Forward+. The twist: This is already well-supported! See below the pseudocode of how this actually works. All the complexity goes away when you ignore culling mask, which is more of a legacy concept, and always rely on the rendering layer mask, which is a newer and better feature. ```c // Rendering the mesh // ------------------ if (camera.cullingMask & meshRenderer.layer) { // Draw the mesh renderer in the game view } else { // Skip drawing the mesh renderer in the game view } // Lighting the mesh // ----------------- if (pipeline == Forward) { if (light.cullingMask & meshRenderer.layer) { if (light.renderingLayers && meshRenderer.renderingLayerMask) { // Light the mesh renderer with this light } else { // Skip lighting the mesh renderer with this light } } else { // Skip lighting the mesh renderer with this light } } else { // pipeline == Deferred or pipeline == ForwardPlus if (light.renderingLayers && meshRenderer.renderingLayerMask) { // Light the mesh renderer with this light } else { // Skip lighting the mesh renderer with this light } } ``` This PR makes the following changes: 1. It moves the Rendering Layers inspector field on top of the Culling Mask field. They used to be under completely different headers. ![image](https://media.github.cds.internal.unity3d.com/user/2726/files/23348727-2576-472d-ad9e-908790d97cbb) 2. It shows a greyed out Rendering Layers field even when the "Use Rendering Layers" setting is off on the URP asset. In this condition, the field was totally invsible. My change improves visibility of this feature substantially. ![image](https://media.github.cds.internal.unity3d.com/user/2726/files/bca528ae-91b8-4b68-ba05-ce62fd90c8a3) 3. If the culling mask is set to anything other than the default value of Everything, we now show a warning box advising the use of Rendering Layers instead. ![image](https://media.github.cds.internal.unity3d.com/user/2726/files/a80c0275-5864-4a2d-a30a-87dc8bb9f8ea)
1 parent 8279bf2 commit 9ff2bb4

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

Packages/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Drawers.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,6 @@ static void DrawGeneralContentInternal(UniversalRenderPipelineSerializedLight se
191191
serializedLight.settings.lightmapping.intValue = (int)LightmapBakeType.Baked;
192192
serializedLight.Apply();
193193
}
194-
195-
if (lightType != LightType.Rectangle && !serializedLight.settings.isCompletelyBaked && UniversalRenderPipeline.asset.useRenderingLayers && !isInPreset)
196-
{
197-
EditorGUI.BeginChangeCheck();
198-
EditorUtils.DrawRenderingLayerMask(serializedLight.renderingLayers, Styles.RenderingLayers);
199-
if (EditorGUI.EndChangeCheck())
200-
{
201-
if (!serializedLight.customShadowLayers.boolValue)
202-
SyncLightAndShadowLayers(serializedLight, serializedLight.renderingLayers);
203-
}
204-
}
205194
}
206195
}
207196

@@ -279,6 +268,24 @@ static void DrawEmissionContent(UniversalRenderPipelineSerializedLight serialize
279268
static void DrawRenderingContent(UniversalRenderPipelineSerializedLight serializedLight, Editor owner)
280269
{
281270
serializedLight.settings.DrawRenderMode();
271+
272+
if (serializedLight.settings.light.type != LightType.Rectangle &&
273+
!serializedLight.settings.isCompletelyBaked)
274+
{
275+
EditorGUI.BeginChangeCheck();
276+
GUI.enabled = UniversalRenderPipeline.asset.useRenderingLayers;
277+
EditorUtils.DrawRenderingLayerMask(
278+
serializedLight.renderingLayers,
279+
UniversalRenderPipeline.asset.useRenderingLayers ? Styles.RenderingLayers : Styles.RenderingLayersDisabled
280+
);
281+
GUI.enabled = true;
282+
if (EditorGUI.EndChangeCheck())
283+
{
284+
if (!serializedLight.customShadowLayers.boolValue)
285+
SyncLightAndShadowLayers(serializedLight, serializedLight.renderingLayers);
286+
}
287+
}
288+
282289
var rendererList = UniversalRenderPipeline.asset.rendererDataList;
283290
bool hasNonForwardPlusRenderer = false;
284291
foreach (var r in rendererList)
@@ -301,6 +308,10 @@ static void DrawRenderingContent(UniversalRenderPipelineSerializedLight serializ
301308
GUI.enabled = hasNonForwardPlusRenderer;
302309
EditorGUILayout.PropertyField(serializedLight.settings.cullingMask, hasNonForwardPlusRenderer ? Styles.CullingMask : Styles.CullingMaskDisabled);
303310
GUI.enabled = true;
311+
if (serializedLight.settings.cullingMask.intValue != -1)
312+
{
313+
EditorGUILayout.HelpBox(Styles.CullingMaskWarning.text, MessageType.Warning);
314+
}
304315
}
305316

306317
static void DrawShadowsContent(UniversalRenderPipelineSerializedLight serializedLight, Editor owner)

Packages/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Skin.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ private static class Styles
2121
public static readonly GUIContent BakingWarning = EditorGUIUtility.TrTextContent("Light mode is currently overridden to Realtime mode. Enable Baked Global Illumination to use Mixed or Baked light modes.");
2222
public static readonly GUIContent DisabledLightWarning = EditorGUIUtility.TrTextContent("Lighting has been disabled in at least one Scene view. Any changes applied to lights in the Scene will not be updated in these views until Lighting has been enabled again.");
2323
public static readonly GUIContent SunSourceWarning = EditorGUIUtility.TrTextContent("This light is set as the current Sun Source, which requires a directional light. Go to the Lighting Window's Environment settings to edit the Sun Source.");
24-
public static readonly GUIContent CullingMask = EditorGUIUtility.TrTextContent("Culling Mask", "Specifies which layers will be affected or excluded from the light's effect on objects in the scene. This only applies to objects rendered using the Forward rendering path, and transparent objects rendered using the Deferred rendering path. This setting is ignored in the Forward+ rendering path.");
25-
public static readonly GUIContent CullingMaskDisabled = EditorGUIUtility.TrTextContent("Culling Mask", "Culling Mask is disabled. This is because all active renderers use the Forward+ rendering path, which doesn't support Culling Mask. To enable this setting, change the rendering path to Forward or Deferred in the active Universal Render Pipeline Asset.");
24+
public static readonly GUIContent CullingMask = EditorGUIUtility.TrTextContent("Culling Mask", "Specifies which layers will be affected or excluded from the light's effect on objects in the scene. This only applies to objects rendered using the Forward rendering path, and transparent objects rendered using the Deferred rendering path.\n\nUse Rendering Layers instead, which is supported across all rendering paths.");
25+
public static readonly GUIContent CullingMaskDisabled = EditorGUIUtility.TrTextContent("Culling Mask", "Culling Mask is disabled. This is because all active renderers use the Forward+ rendering path, which doesn't support Culling Mask. Use Rendering Layers instead, which is supported across all rendering paths.");
26+
public static readonly GUIContent CullingMaskWarning = EditorGUIUtility.TrTextContent("Culling Mask only works with Forward rendering. Instead, use Rendering Layers on the Light, and Rendering Layer Mask on the Mesh Renderer, which will work across Deferred, Forward, and Forward+ rendering.");
2627

2728
public static readonly GUIContent ShadowRealtimeSettings = EditorGUIUtility.TrTextContent("Realtime Shadows", "Settings for realtime direct shadows.");
2829
public static readonly GUIContent ShadowStrength = EditorGUIUtility.TrTextContent("Strength", "Controls how dark the shadows cast by the light will be.");
@@ -66,6 +67,7 @@ private static class Styles
6667
public static readonly GUIContent LightCookieOffset = EditorGUIUtility.TrTextContent("Cookie Offset", "Controls the offset of the cookie mask currently assigned to the light.");
6768
/// <summary>Title with "Rendering Layer"</summary>
6869
public static readonly GUIContent RenderingLayers = EditorGUIUtility.TrTextContent("Rendering Layers", "Select the Rendering Layers that the Light affects. This Light affects objects where at least one Rendering Layer value matches.");
70+
public static readonly GUIContent RenderingLayersDisabled = EditorGUIUtility.TrTextContent("Rendering Layers", "Rendering Layers are disabled because they have a small GPU performance cost. To enable this setting, go to the active Universal Render Pipeline Asset, and enable Lighting -> Use Rendering Layers.");
6971
}
7072
}
7173
}

0 commit comments

Comments
 (0)