From d807ed04107fb5b302298cd40fa3e0fa0afc9c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20V=C3=A1zquez?= Date: Mon, 20 Sep 2021 12:28:15 +0200 Subject: [PATCH 1/2] 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 | 3 +- 6 files changed, 82 insertions(+), 80 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 0df56ba9184..2a9a9509da3 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - 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 9472e3830ff..872b3da020a 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 8ebb1173053..2b2b364c2d5 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, @@ -245,33 +247,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 82bf5d0ae4a..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,7 +22,8 @@ partial class UniversalRenderPipelineLightUI CED.FoldoutGroup(LightUI.Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, - CED.Group(DrawerColor, + CED.Group( + LightUI.DrawColor, DrawEmissionContent)), CED.FoldoutGroup(Styles.lightCookieHeader, Expandable.LightCookie, From 6bdd99094db98a1543bd717660d439197e023f0c Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Mon, 20 Sep 2021 12:37:41 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- com.unity.render-pipelines.core/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/CHANGELOG.md b/com.unity.render-pipelines.core/CHANGELOG.md index 2a9a9509da3..5452c4d9445 100644 --- a/com.unity.render-pipelines.core/CHANGELOG.md +++ b/com.unity.render-pipelines.core/CHANGELOG.md @@ -46,7 +46,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - 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. @@ -82,6 +81,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed potentially conflicting runtime Rendering Debugger UI command by adding an option to disable runtime UI altogether (1345783). - Fixed Lens Flare position for celestial at very far camera distances. It now locks correctly into the celestial position regardless of camera distance (1363291) - Fixed issues caused by automatically added EventSystem component, required to support Rendering Debugger Runtime UI input. (1361901) +- Fixed API to draw color temperature for Lights. ### Changed - Improved the warning messages for Volumes and their Colliders.