diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs index b789acdbc97..7819af246fb 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs @@ -95,7 +95,6 @@ sealed class Styles public readonly GUIContent distance = EditorGUIUtility.TrTextContent("Distance", "Distance from the camera (in meters) to the emissive celestial body represented by the light. Primarily used for sorting."); public readonly GUIContent shape = EditorGUIUtility.TrTextContent("Type", "Specifies the current type of Light. Possible Light types are Directional, Spot, Point, and Area."); - public readonly GUIContent[] shapeNames; public readonly GUIContent enableSpotReflector = EditorGUIUtility.TrTextContent("Reflector", "When enabled, HDRP simulates a physically correct Spot Light using a reflector. This means the narrower the Outer Angle, the more intense the Spot Light. When disabled, the intensity of the Light matches the one of a Point Light and thus remains constant regardless of the Outer Angle."); public readonly GUIContent luxAtDistance = EditorGUIUtility.TrTextContent("At", "Sets the distance, in meters, where a surface receives the amount of light equivalent to the provided number of Lux."); @@ -161,13 +160,6 @@ sealed class Styles // Warnings public readonly string unsupportedLightShapeWarning = L10n.Tr("This light shape is not supported by Realtime Global Illumination."); public readonly string unsupportedPresetPropertiesMessage = L10n.Tr("When using Preset of Light Component, only a subset of properties are supported. Unsupported properties are hidden."); - - public Styles() - { - shapeNames = Enum.GetNames(typeof(UnityEngine.Rendering.HighDefinition.HDLightType)) - .Select(x => new GUIContent(x)) - .ToArray(); - } } static Styles s_Styles = new Styles(); 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 8084689fe14..016fc589288 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs @@ -87,11 +87,17 @@ internal static void SetAdditionalPropertiesVisibility(bool value) static HDLightUI() { Inspector = CED.Group( - CED.AdditionalPropertiesFoldoutGroup(s_Styles.generalHeader, Expandable.General, k_ExpandedState, AdditionalProperties.General, k_AdditionalPropertiesState, DrawGeneralContent, DrawGeneralAdditionalContent), + CED.AdditionalPropertiesFoldoutGroup(s_Styles.generalHeader, Expandable.General, k_ExpandedState, AdditionalProperties.General, k_AdditionalPropertiesState, + CED.Group((serialized, owner) => DrawGeneralContent(serialized, owner)), DrawGeneralAdditionalContent), CED.FoldoutGroup(s_Styles.shapeHeader, Expandable.Shape, k_ExpandedState, DrawShapeContent), CED.Conditional((serialized, owner) => serialized.type == HDLightType.Directional && !serialized.settings.isCompletelyBaked, CED.FoldoutGroup(s_Styles.celestialBodyHeader, Expandable.CelestialBody, k_ExpandedState, DrawCelestialBodyContent)), - CED.AdditionalPropertiesFoldoutGroup(s_Styles.emissionHeader, Expandable.Emission, k_ExpandedState, AdditionalProperties.Emission, k_AdditionalPropertiesState, DrawEmissionContent, DrawEmissionAdditionalContent), + CED.AdditionalPropertiesFoldoutGroup(s_Styles.emissionHeader, Expandable.Emission, k_ExpandedState, AdditionalProperties.Emission, k_AdditionalPropertiesState, + CED.Group( + DrawColor, + DrawLightIntensityGUILayout, + DrawEmissionContent), + DrawEmissionAdditionalContent), CED.Conditional((serialized, owner) => serialized.type != HDLightType.Area && !serialized.settings.isCompletelyBaked, CED.FoldoutGroup(s_Styles.volumetricHeader, Expandable.Volumetric, k_ExpandedState, DrawVolumetric)), CED.Conditional((serialized, owner) => @@ -126,22 +132,44 @@ static HDLightUI() ) ); - Type lightMappingType = typeof(Lightmapping); - var getLightingSettingsOrDefaultsFallbackInfo = lightMappingType.GetMethod("GetLightingSettingsOrDefaultsFallback", BindingFlags.Static | BindingFlags.NonPublic); - var getLightingSettingsOrDefaultsFallbackLambda = Expression.Lambda>(Expression.Call(null, getLightingSettingsOrDefaultsFallbackInfo)); - GetLightingSettingsOrDefaultsFallback = getLightingSettingsOrDefaultsFallbackLambda.Compile(); - PresetInspector = CED.Group( CED.Group((serialized, owner) => EditorGUILayout.HelpBox(s_Styles.unsupportedPresetPropertiesMessage, MessageType.Info)), CED.Group((serialized, owner) => EditorGUILayout.Space()), - CED.FoldoutGroup(s_Styles.generalHeader, Expandable.General, k_ExpandedStatePreset, DrawGeneralContent), - CED.FoldoutGroup(s_Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, DrawEmissionContentForPreset), + CED.FoldoutGroup(s_Styles.generalHeader, Expandable.General, k_ExpandedStatePreset, CED.Group((serialized, owner) => DrawGeneralContent(serialized, owner, true))), + CED.FoldoutGroup(s_Styles.emissionHeader, Expandable.Emission, k_ExpandedStatePreset, CED.Group(DrawColor, DrawEmissionContent)), CED.FoldoutGroup(s_Styles.shadowHeader, Expandable.Shadows, k_ExpandedStatePreset, DrawEnableShadowMapInternal) ); + + Type lightMappingType = typeof(Lightmapping); + var getLightingSettingsOrDefaultsFallbackInfo = lightMappingType.GetMethod("GetLightingSettingsOrDefaultsFallback", BindingFlags.Static | BindingFlags.NonPublic); + var getLightingSettingsOrDefaultsFallbackLambda = Expression.Lambda>(Expression.Call(null, getLightingSettingsOrDefaultsFallbackInfo)); + GetLightingSettingsOrDefaultsFallback = getLightingSettingsOrDefaultsFallbackLambda.Compile(); + } + + // This scope is here mainly to keep pointLightHDType isolated + public struct LightTypeEditionScope : IDisposable + { + EditorGUI.PropertyScope lightTypeScope; + EditorGUI.PropertyScope pointLightScope; + + public LightTypeEditionScope(Rect rect, GUIContent label, SerializedHDLight serialized, bool isPreset) + { + // When editing a Light Preset, the HDAdditionalData, is not editable as is not shown on the inspector, therefore, all the properties + // That come from the HDAdditionalData are not editable, if we use the PropertyScope for those, as they are not editable this will block + // the edition of any property that came afterwards. So make sure that we do not use the PropertyScope if the editor is for a preset + pointLightScope = isPreset ? null : new EditorGUI.PropertyScope(rect, label, serialized.pointLightHDType); + lightTypeScope = new EditorGUI.PropertyScope(rect, label, serialized.settings.lightType); + } + + void IDisposable.Dispose() + { + lightTypeScope.Dispose(); + pointLightScope?.Dispose(); + } } - static void DrawGeneralContent(SerializedHDLight serialized, Editor owner) + static void DrawGeneralContent(SerializedHDLight serialized, Editor owner, bool isPreset = false) { EditorGUI.BeginChangeCheck(); Rect lineRect = EditorGUILayout.GetControlRect(); @@ -151,11 +179,15 @@ static void DrawGeneralContent(SerializedHDLight serialized, Editor owner) //Partial support for prefab. There is no way to fully support it at the moment. //Missing support on the Apply and Revert contextual menu on Label for Prefab overrides. They need to be done two times. //(This will continue unless we remove AdditionalDatas) - using (new SerializedHDLight.LightTypeEditionScope(lineRect, s_Styles.shape, serialized)) + using (new LightTypeEditionScope(lineRect, s_Styles.shape, serialized, isPreset)) { EditorGUI.showMixedValue = lightType == (HDLightType)(-1); - int index = Array.FindIndex((HDLightType[])Enum.GetValues(typeof(HDLightType)), x => x == lightType); - updatedLightType = (HDLightType)EditorGUI.Popup(lineRect, s_Styles.shape, index, s_Styles.shapeNames); + updatedLightType = (HDLightType)EditorGUI.EnumPopup( + lineRect, + s_Styles.shape, + lightType, + e => !isPreset || (HDLightType)e != HDLightType.Area, + false); } if (EditorGUI.EndChangeCheck()) @@ -634,71 +666,58 @@ static void DrawLightIntensityGUILayout(SerializedHDLight serialized, Editor own } } - static void DrawEmissionContent(SerializedHDLight serialized, Editor owner) - { - DrawEmissionContentFiltered(serialized, owner, isInPreset: false); - } - - static void DrawEmissionContentForPreset(SerializedHDLight serialized, Editor owner) + static void DrawColor(SerializedHDLight serialized, Editor owner) { - DrawEmissionContentFiltered(serialized, owner, isInPreset: true); - } - - static void DrawEmissionContentFiltered(SerializedHDLight serialized, Editor owner, bool isInPreset) - { - using (var changes = new EditorGUI.ChangeCheckScope()) + if (GraphicsSettings.lightsUseLinearIntensity && GraphicsSettings.lightsUseColorTemperature) { - 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); - var lightAppearanceOptions = new[] { "Color", "Filter and Temperature" }; - colorTemperaturePopupValue = EditorGUILayout.Popup(s_Styles.lightAppearance, colorTemperaturePopupValue, lightAppearanceOptions); - serialized.settings.useColorTemperature.boolValue = Convert.ToBoolean(colorTemperaturePopupValue); + // Use the color temperature bool to create a popup dropdown to choose between the two modes. + var colorTemperaturePopupValue = Convert.ToInt32(serialized.settings.useColorTemperature.boolValue); + var lightAppearanceOptions = new[] { "Color", "Filter and Temperature" }; + colorTemperaturePopupValue = EditorGUILayout.Popup(s_Styles.lightAppearance, colorTemperaturePopupValue, lightAppearanceOptions); + serialized.settings.useColorTemperature.boolValue = Convert.ToBoolean(colorTemperaturePopupValue); - if (serialized.settings.useColorTemperature.boolValue) - { - EditorGUI.indentLevel += 1; - EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.colorFilter); - - // Light unit slider - const int k_ValueUnitSeparator = 2; - var lineRect = EditorGUILayout.GetControlRect(); - var labelRect = lineRect; - labelRect.width = EditorGUIUtility.labelWidth; - EditorGUI.LabelField(labelRect, s_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, s_Styles.empty); - EditorGUI.Popup(unitRect, 0, new[] { "Kelvin" }); - - EditorGUI.indentLevel -= 1; - } - else - EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color); + if (serialized.settings.useColorTemperature.boolValue) + { + EditorGUI.indentLevel += 1; + EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.colorFilter); + + // Light unit slider + const int k_ValueUnitSeparator = 2; + var lineRect = EditorGUILayout.GetControlRect(); + var labelRect = lineRect; + labelRect.width = EditorGUIUtility.labelWidth; + EditorGUI.LabelField(labelRect, s_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, s_Styles.empty); + EditorGUI.Popup(unitRect, 0, new[] { "Kelvin" }); + + EditorGUI.indentLevel -= 1; } else EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color); } + else + EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color); + } - if (!isInPreset) - DrawLightIntensityGUILayout(serialized, owner); - + static void DrawEmissionContent(SerializedHDLight serialized, Editor owner) + { HDLightType lightType = serialized.type; SpotLightShape spotLightShape = serialized.spotLightShape.GetEnumValue(); LightUnit lightUnit = serialized.lightUnit.GetEnumValue(); diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs index 4fce274d7a4..cd9bb8cf907 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs @@ -106,7 +106,7 @@ internal class SerializedHDLight : ISerializedLight public SerializedProperty slopeBias; public SerializedProperty normalBias; - private SerializedProperty pointLightHDType; + internal SerializedProperty pointLightHDType; private SerializedProperty areaLightShapeProperty; private GameObject[] emissiveMeshes; @@ -153,22 +153,6 @@ bool haveMultipleTypeValue } } - // This scope is here mainly to keep pointLightHDType isolated - public struct LightTypeEditionScope : System.IDisposable - { - public LightTypeEditionScope(Rect rect, GUIContent label, SerializedHDLight serialized) - { - EditorGUI.BeginProperty(rect, label, serialized.pointLightHDType); - EditorGUI.BeginProperty(rect, label, serialized.settings.lightType); - } - - void System.IDisposable.Dispose() - { - EditorGUI.EndProperty(); - EditorGUI.EndProperty(); - } - } - //areaLightShape need to be accessed by its property to always report modification in the right way public AreaLightShape areaLightShape {