From 96f2cc102c915308aa0c15221400ceeb6e54d31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Mon, 6 Sep 2021 11:53:56 +0200 Subject: [PATCH 1/4] Using the same color temperature picker in HDRP and in URP --- com.unity.render-pipelines.core/CHANGELOG.md | 1 + .../Editor/Lighting/LightUI.Drawers.cs | 61 +++++++++++++++++++ .../Editor/Lighting/LightUI.Drawers.cs.meta | 11 ++++ .../Editor/Lighting/HDLightUI.cs | 55 ++--------------- .../UniversalRenderPipelineLightUI.Drawers.cs | 31 +--------- ...alRenderPipelineLightUI.PresetInspector.cs | 9 ++- 6 files changed, 87 insertions(+), 81 deletions(-) create mode 100644 com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs create mode 100644 com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs.meta diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index a4ddc266923..3cf10c64a57 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -51,6 +51,7 @@ The version number for this package has increased due to a version update of a r - Added UNITY_PREV_MATRIX_M and UNITY_PREV_MATRIX_I_M shader macros to support instanced motion vector rendering - Added new API to customize the rtHandleProperties of a particular RTHandle. This is a temporary work around to assist with viewport setup of Custom post process when dealing with DLSS or TAAU - Added `IAdditionalData` interface to identify the additional datas on the core package. +- Added new API to draw color temperature for Lights. ### Fixed - Help boxes with fix buttons do not crop the label. diff --git a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs new file mode 100644 index 00000000000..81650c43b9e --- /dev/null +++ b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs @@ -0,0 +1,61 @@ +using System; +using UnityEngine; +using UnityEngine.Rendering; + +namespace UnityEditor.Rendering +{ + /// + /// Contains a set of methods to help render the inspectors of Lights across SRP's + /// + public partial class LightUI + { + public static void DrawColor(ISerializedLight serialized, Editor owner) + { + if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature) + { + // Use the color temperature bool to create a popup dropdown to choose between the two modes. + var colorTemperaturePopupValue = Convert.ToInt32(serialized.settings.useColorTemperature.boolValue); + colorTemperaturePopupValue = EditorGUILayout.Popup(Styles.lightAppearance, colorTemperaturePopupValue, Styles.lightAppearanceOptions); + serialized.settings.useColorTemperature.boolValue = Convert.ToBoolean(colorTemperaturePopupValue); + + if (serialized.settings.useColorTemperature.boolValue) + { + EditorGUI.indentLevel += 1; + EditorGUILayout.PropertyField(serialized.settings.color, Styles.colorFilter); + + // Light unit slider + const int k_ValueUnitSeparator = 2; + var lineRect = EditorGUILayout.GetControlRect(); + var labelRect = lineRect; + labelRect.width = EditorGUIUtility.labelWidth; + EditorGUI.LabelField(labelRect, Styles.colorTemperature); + + var temperatureSliderRect = lineRect; + temperatureSliderRect.x += EditorGUIUtility.labelWidth + k_ValueUnitSeparator; + temperatureSliderRect.width -= EditorGUIUtility.labelWidth + k_ValueUnitSeparator; + TemperatureSliderUIDrawer.Draw(serialized.settings, serialized.serializedObject, serialized.settings.colorTemperature, temperatureSliderRect); + + // Value and unit label + // Match const defined in EditorGUI.cs + const int k_IndentPerLevel = 15; + const int k_UnitWidth = 60 + k_IndentPerLevel; + int indent = k_IndentPerLevel * EditorGUI.indentLevel; + Rect valueRect = EditorGUILayout.GetControlRect(); + valueRect.width += indent - k_ValueUnitSeparator - k_UnitWidth; + Rect unitRect = valueRect; + unitRect.x += valueRect.width - indent + k_ValueUnitSeparator; + unitRect.width = k_UnitWidth + .5f; + + EditorGUI.PropertyField(valueRect, serialized.settings.colorTemperature, CoreEditorStyles.empty); + EditorGUI.LabelField(unitRect, Styles.lightAppearanceUnits[0]); + + EditorGUI.indentLevel -= 1; + } + else + EditorGUILayout.PropertyField(serialized.settings.color, Styles.color); + } + else + EditorGUILayout.PropertyField(serialized.settings.color, Styles.color); + } + } +} diff --git a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs.meta b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs.meta new file mode 100644 index 00000000000..32dec915f3e --- /dev/null +++ b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63524ac66f4f7c044bc3dc991c570e89 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs index 5cbe52ba27a..04eeffd107a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs @@ -94,7 +94,7 @@ static HDLightUI() CED.FoldoutGroup(s_Styles.celestialBodyHeader, Expandable.CelestialBody, k_ExpandedState, DrawCelestialBodyContent)), CED.AdditionalPropertiesFoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedState, AdditionalProperties.Emission, k_AdditionalPropertiesState, CED.Group( - DrawColor, + LightUI.DrawColor, DrawLightIntensityGUILayout, DrawEmissionContent), DrawEmissionAdditionalContent), @@ -137,7 +137,9 @@ static HDLightUI() EditorGUILayout.HelpBox(LightUI.Styles.unsupportedPresetPropertiesMessage, MessageType.Info)), CED.Group((serialized, owner) => EditorGUILayout.Space()), CED.FoldoutGroup(LightUI.Styles.generalHeader, Expandable.General, k_ExpandedStatePreset, CED.Group((serialized, owner) => DrawGeneralContent(serialized, owner, true))), - CED.FoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, CED.Group(DrawColor, DrawEmissionContent)), + CED.FoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, CED.Group( + LightUI.DrawColor, + DrawEmissionContent)), CED.FoldoutGroup(LightUI.Styles.shadowHeader, Expandable.Shadows, k_ExpandedStatePreset, DrawEnableShadowMapInternal) ); @@ -666,55 +668,6 @@ static void DrawLightIntensityGUILayout(SerializedHDLight serialized, Editor own } } - static void DrawColor(SerializedHDLight serialized, Editor owner) - { - if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature) - { - // Use the color temperature bool to create a popup dropdown to choose between the two modes. - var colorTemperaturePopupValue = Convert.ToInt32(serialized.settings.useColorTemperature.boolValue); - colorTemperaturePopupValue = EditorGUILayout.Popup(LightUI.Styles.lightAppearance, colorTemperaturePopupValue, LightUI.Styles.lightAppearanceOptions); - serialized.settings.useColorTemperature.boolValue = Convert.ToBoolean(colorTemperaturePopupValue); - - if (serialized.settings.useColorTemperature.boolValue) - { - EditorGUI.indentLevel += 1; - EditorGUILayout.PropertyField(serialized.settings.color, LightUI.Styles.colorFilter); - - // Light unit slider - const int k_ValueUnitSeparator = 2; - var lineRect = EditorGUILayout.GetControlRect(); - var labelRect = lineRect; - labelRect.width = EditorGUIUtility.labelWidth; - EditorGUI.LabelField(labelRect, LightUI.Styles.colorTemperature); - - var temperatureSliderRect = lineRect; - temperatureSliderRect.x += EditorGUIUtility.labelWidth + k_ValueUnitSeparator; - temperatureSliderRect.width -= EditorGUIUtility.labelWidth + k_ValueUnitSeparator; - TemperatureSliderUIDrawer.Draw(serialized.settings, serialized.serializedObject, serialized.settings.colorTemperature, temperatureSliderRect); - - // Value and unit label - // Match const defined in EditorGUI.cs - const int k_IndentPerLevel = 15; - const int k_UnitWidth = 100 + k_IndentPerLevel; - int indent = k_IndentPerLevel * EditorGUI.indentLevel; - Rect valueRect = EditorGUILayout.GetControlRect(); - valueRect.width += indent - k_ValueUnitSeparator - k_UnitWidth; - Rect unitRect = valueRect; - unitRect.x += valueRect.width - indent + k_ValueUnitSeparator; - unitRect.width = k_UnitWidth + .5f; - - EditorGUI.PropertyField(valueRect, serialized.settings.colorTemperature, CoreEditorStyles.empty); - EditorGUI.Popup(unitRect, 0, new[] { "Kelvin" }); - - EditorGUI.indentLevel -= 1; - } - else - EditorGUILayout.PropertyField(serialized.settings.color, LightUI.Styles.color); - } - else - EditorGUILayout.PropertyField(serialized.settings.color, LightUI.Styles.color); - } - static void DrawEmissionContent(SerializedHDLight serialized, Editor owner) { HDLightType lightType = serialized.type; diff --git a/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Drawers.cs b/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Drawers.cs index 174a6835dbd..753075edfc5 100644 --- a/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Drawers.cs +++ b/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.Drawers.cs @@ -59,7 +59,9 @@ enum Expandable CED.FoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedState, - CED.Group(DrawerColor, DrawEmissionContent)), + CED.Group( + LightUI.DrawColor, + DrawEmissionContent)), CED.FoldoutGroup(LightUI.Styles.renderingHeader, Expandable.Rendering, k_ExpandedState, @@ -241,33 +243,6 @@ static void DrawAreaShapeContent(UniversalRenderPipelineSerializedLight serializ serializedLight.settings.DrawArea(); } - static void DrawerColor(UniversalRenderPipelineSerializedLight serializedLight, Editor owner) - { - using (var changes = new EditorGUI.ChangeCheckScope()) - { - if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature) - { - // Use the color temperature bool to create a popup dropdown to choose between the two modes. - var colorTemperaturePopupValue = Convert.ToInt32(serializedLight.settings.useColorTemperature.boolValue); - colorTemperaturePopupValue = EditorGUILayout.Popup(LightUI.Styles.lightAppearance, colorTemperaturePopupValue, LightUI.Styles.lightAppearanceOptions); - serializedLight.settings.useColorTemperature.boolValue = Convert.ToBoolean(colorTemperaturePopupValue); - - using (new EditorGUI.IndentLevelScope()) - { - if (serializedLight.settings.useColorTemperature.boolValue) - { - EditorGUILayout.PropertyField(serializedLight.settings.color, LightUI.Styles.colorFilter); - k_SliderWithTexture(LightUI.Styles.colorTemperature, serializedLight.settings.colorTemperature, serializedLight.settings); - } - else - EditorGUILayout.PropertyField(serializedLight.settings.color, LightUI.Styles.color); - } - } - else - EditorGUILayout.PropertyField(serializedLight.settings.color, LightUI.Styles.color); - } - } - static void DrawEmissionContent(UniversalRenderPipelineSerializedLight serializedLight, Editor owner) { serializedLight.settings.DrawIntensity(); diff --git a/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.PresetInspector.cs b/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.PresetInspector.cs index 3145fbc1311..64c7993c9bc 100644 --- a/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.PresetInspector.cs +++ b/com.unity.render-pipelines.universal/Editor/Lighting/UniversalRenderPipelineLightUI.PresetInspector.cs @@ -22,8 +22,13 @@ partial class UniversalRenderPipelineLightUI CED.FoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, - CED.Group(DrawerColor, - DrawEmissionContent)) + CED.Group( + LightUI.DrawColor, + DrawEmissionContent)), + CED.FoldoutGroup(Styles.lightCookieHeader, + Expandable.LightCookie, + k_ExpandedState, + DrawLightCookieContent) ); } } From ca07992f43ebf8719e2f1319bebac13e62e95946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Mon, 6 Sep 2021 11:59:34 +0200 Subject: [PATCH 2/4] Docs --- .../Editor/Lighting/LightUI.Drawers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs index 81650c43b9e..a95e579f4e5 100644 --- a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs +++ b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs @@ -9,6 +9,11 @@ namespace UnityEditor.Rendering /// public partial class LightUI { + /// + /// Draws the color temperature for a serialized light + /// + /// The serizalized light + /// The editor public static void DrawColor(ISerializedLight serialized, Editor owner) { if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature) From 5b2bfb434fe5b5945dd8df9e55e45ad592f130a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Mon, 6 Sep 2021 16:39:19 +0200 Subject: [PATCH 3/4] Fix from code review --- .../Editor/Lighting/LightUI.Drawers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs index a95e579f4e5..3ab9553165d 100644 --- a/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs +++ b/com.unity.render-pipelines.core/Editor/Lighting/LightUI.Drawers.cs @@ -49,7 +49,7 @@ public static void DrawColor(ISerializedLight serialized, Editor owner) valueRect.width += indent - k_ValueUnitSeparator - k_UnitWidth; Rect unitRect = valueRect; unitRect.x += valueRect.width - indent + k_ValueUnitSeparator; - unitRect.width = k_UnitWidth + .5f; + unitRect.width = k_UnitWidth + k_ValueUnitSeparator; EditorGUI.PropertyField(valueRect, serialized.settings.colorTemperature, CoreEditorStyles.empty); EditorGUI.LabelField(unitRect, Styles.lightAppearanceUnits[0]); From 22e21c712d99e37c1766bace52ea0a7fc8a36e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Fri, 17 Sep 2021 09:35:21 +0200 Subject: [PATCH 4/4] format --- .../Editor/Lighting/HDLightUI.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs index 04eeffd107a..872b3da020a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs @@ -1136,9 +1136,9 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner) if (serialized.settings.isMixed) { - bool enabled = HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.supportShadowMask; - if (Lightmapping.TryGetLightingSettings(out var settings)) - enabled &= settings.mixedBakeMode == MixedLightingMode.Shadowmask; + bool enabled = HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.supportShadowMask; + if (Lightmapping.TryGetLightingSettings(out var settings)) + enabled &= settings.mixedBakeMode == MixedLightingMode.Shadowmask; using (new EditorGUI.DisabledScope(!enabled)) { Rect nonLightmappedOnlyRect = EditorGUILayout.GetControlRect();