Skip to content

Commit ccae666

Browse files
Clean up shader ui (#3462)
* Clean up shader ui * Fix toggle switching * Move to interal * Move the intensity unit out of the disabled scope
1 parent e75af7d commit ccae666

8 files changed

Lines changed: 219 additions & 284 deletions

File tree

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4040
- Fixed an issue where first frame of SSAO could exhibit ghosting artefacts.
4141
- Fixed an issue with the mipmap generation internal format after rendering format change.
4242
- Fixed multiple any hit occuring on transparent objects (case 1294927).
43+
- Cleanup Shader UI.
4344

4445
- Fixed sub-shadow rendering for cached shadow maps.
4546
- Fixed PCSS filtering issues with cached shadow maps.

com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceInputsUIBlock.cs

Lines changed: 24 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
32
using UnityEngine;
43
using UnityEngine.Rendering.HighDefinition;
54
using System.Linq;
6-
using UnityEngine.Rendering;
75

86
// Include material common properties names
97
using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties;
10-
// We share the name of the properties in the UI to avoid duplication
11-
using static UnityEditor.Rendering.HighDefinition.DecalSurfaceOptionsUIBlock.Styles;
128

139
namespace UnityEditor.Rendering.HighDefinition
1410
{
@@ -224,13 +220,7 @@ void DrawDecalGUI()
224220
if (materials.All(m => m.GetTexture(kNormalMap)))
225221
{
226222
EditorGUI.indentLevel++;
227-
228-
EditorGUI.BeginChangeCheck();
229-
var normalBlendSrcValue = (int)normalBlendSrc.floatValue;
230-
normalBlendSrcValue = EditorGUILayout.Popup(Styles.normalOpacityChannelText, normalBlendSrcValue, allMaskMap ? blendSourceNames : blendSourceNamesNoMap);
231-
if (EditorGUI.EndChangeCheck())
232-
normalBlendSrc.floatValue = normalBlendSrcValue;
233-
223+
PopupShaderProperty(normalBlendSrc, Styles.normalOpacityChannelText, allMaskMap ? blendSourceNames : blendSourceNamesNoMap);
234224
EditorGUI.indentLevel--;
235225
}
236226

@@ -240,36 +230,11 @@ void DrawDecalGUI()
240230
{
241231
if (perChannelMask)
242232
{
243-
float MetalRemapMinValue = metallicRemapMin.floatValue;
244-
float MetalRemapMaxValue = metallicRemapMax.floatValue;
245-
EditorGUI.BeginChangeCheck();
246-
EditorGUILayout.MinMaxSlider(Styles.metallicRemappingText, ref MetalRemapMinValue, ref MetalRemapMaxValue, 0.0f, 1.0f);
247-
if (EditorGUI.EndChangeCheck())
248-
{
249-
metallicRemapMin.floatValue = MetalRemapMinValue;
250-
metallicRemapMax.floatValue = MetalRemapMaxValue;
251-
}
252-
253-
float AORemapMinValue = AORemapMin.floatValue;
254-
float AORemapMaxValue = AORemapMax.floatValue;
255-
EditorGUI.BeginChangeCheck();
256-
EditorGUILayout.MinMaxSlider(Styles.aoRemappingText, ref AORemapMinValue, ref AORemapMaxValue, 0.0f, 1.0f);
257-
if (EditorGUI.EndChangeCheck())
258-
{
259-
AORemapMin.floatValue = AORemapMinValue;
260-
AORemapMax.floatValue = AORemapMaxValue;
261-
}
233+
MinMaxShaderProperty(metallicRemapMin, metallicRemapMax, 0.0f, 1.0f, Styles.metallicRemappingText);
234+
MinMaxShaderProperty(AORemapMin, AORemapMax, 0.0f, 1.0f, Styles.aoRemappingText);
262235
}
263236

264-
float smoothnessRemapMinValue = smoothnessRemapMin.floatValue;
265-
float smoothnessRemapMaxValue = smoothnessRemapMax.floatValue;
266-
EditorGUI.BeginChangeCheck();
267-
EditorGUILayout.MinMaxSlider(Styles.smoothnessRemappingText, ref smoothnessRemapMinValue, ref smoothnessRemapMaxValue, 0.0f, 1.0f);
268-
if (EditorGUI.EndChangeCheck())
269-
{
270-
smoothnessRemapMin.floatValue = smoothnessRemapMinValue;
271-
smoothnessRemapMax.floatValue = smoothnessRemapMaxValue;
272-
}
237+
MinMaxShaderProperty(smoothnessRemapMin, smoothnessRemapMax, 0.0f, 1.0f, Styles.smoothnessRemappingText);
273238
}
274239
else
275240
{
@@ -281,66 +246,34 @@ void DrawDecalGUI()
281246
materialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
282247
}
283248

284-
EditorGUI.BeginChangeCheck();
285-
var maskBlendSrcValue = (int)maskBlendSrc.floatValue;
286-
maskBlendSrcValue = EditorGUILayout.Popup(Styles.normalOpacityChannelText, maskBlendSrcValue, allMaskMap ? blendSourceNames : blendSourceNamesNoMap);
287-
if (EditorGUI.EndChangeCheck())
288-
maskBlendSrc.floatValue = maskBlendSrcValue;
249+
PopupShaderProperty(maskBlendSrc, Styles.normalOpacityChannelText, allMaskMap ? blendSourceNames : blendSourceNamesNoMap);
289250

290251
EditorGUI.indentLevel--;
291252

292253
materialEditor.ShaderProperty(maskMapBlueScale, allMaskMap ? Styles.maskMapBlueScaleText : Styles.opacityBlueScaleText);
293-
294-
295254
materialEditor.ShaderProperty(decalBlend, Styles.decalBlendText);
296-
//if (affectEmission.floatValue == 1.0f) // Always show emissive part
297-
using (var scope = new EditorGUI.ChangeCheckScope())
298-
{
299-
materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissionIntensityText);
300255

301-
if (useEmissiveIntensity.floatValue == 1.0f)
302-
{
303-
materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorLDR);
304-
using (new EditorGUILayout.HorizontalScope())
305-
{
306-
EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue;
307-
308-
if (unit == EmissiveIntensityUnit.Nits)
309-
materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
310-
else
311-
{
312-
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
313-
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
314-
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
315-
}
316-
emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit);
317-
}
318-
}
319-
else
320-
{
321-
materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorHDR);
322-
}
323-
324-
materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText);
256+
EditorGUI.BeginChangeCheck();
257+
materialEditor.ShaderProperty(useEmissiveIntensity, Styles.useEmissionIntensityText);
258+
bool updateEmissiveColor = EditorGUI.EndChangeCheck();
325259

326-
// If anything change, update the emission value
327-
if (scope.changed)
328-
{
329-
if (useEmissiveIntensity.floatValue == 1.0f)
330-
{
331-
materialEditor.serializedObject.ApplyModifiedProperties();
332-
foreach (Material target in materials)
333-
{
334-
target.UpdateEmissiveColorFromIntensityAndEmissiveColorLDR();
335-
}
336-
materialEditor.serializedObject.Update();
337-
}
338-
else
339-
{
340-
emissiveColor.colorValue = emissiveColorHDR.colorValue;
341-
}
342-
}
260+
if (useEmissiveIntensity.floatValue == 0.0f)
261+
{
262+
EditorGUI.BeginChangeCheck();
263+
materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorHDR);
264+
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
265+
emissiveColor.colorValue = emissiveColorHDR.colorValue;
266+
}
267+
else
268+
{
269+
EditorGUI.BeginChangeCheck();
270+
materialEditor.TexturePropertySingleLine(Styles.emissionMapText, emissiveColorMap, emissiveColorLDR);
271+
EmissionUIBlock.DoEmissiveIntensityGUI(materialEditor, emissiveIntensity, emissiveIntensityUnit);
272+
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
273+
EmissionUIBlock.UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(materialEditor, materials);
343274
}
275+
276+
materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText);
344277
}
345278
}
346279
}

com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/EmissionUIBlock.cs

Lines changed: 52 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using UnityEngine;
43
using UnityEngine.Rendering.HighDefinition;
5-
using UnityEngine.Rendering;
64
using System.Reflection;
75
using System.Linq.Expressions;
86
using System.Linq;
@@ -122,7 +120,7 @@ public override void OnGUI()
122120
}
123121
}
124122

125-
void UpdateEmissiveColorFromIntensityAndEmissiveColorLDR()
123+
internal static void UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(MaterialEditor materialEditor, Material[] materials)
126124
{
127125
materialEditor.serializedObject.ApplyModifiedProperties();
128126
foreach (Material target in materials)
@@ -132,16 +130,56 @@ void UpdateEmissiveColorFromIntensityAndEmissiveColorLDR()
132130
materialEditor.serializedObject.Update();
133131
}
134132

135-
void UpdateEmissionUnit(float newUnitFloat)
133+
internal static void UpdateEmissiveColorLDRFromIntensityAndEmissiveColor(MaterialEditor materialEditor, Material[] materials)
136134
{
135+
materialEditor.serializedObject.ApplyModifiedProperties();
137136
foreach (Material target in materials)
138137
{
139-
if (target.HasProperty(kEmissiveIntensityUnit) && target.HasProperty(kEmissiveIntensity))
138+
target.UpdateEmissiveColorLDRFromIntensityAndEmissiveColor();
139+
}
140+
materialEditor.serializedObject.Update();
141+
}
142+
143+
public static void DoEmissiveIntensityGUI(MaterialEditor materialEditor, MaterialProperty emissiveIntensity, MaterialProperty emissiveIntensityUnit)
144+
{
145+
bool unitIsMixed = emissiveIntensityUnit.hasMixedValue;
146+
bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue;
147+
148+
using (new EditorGUILayout.HorizontalScope())
149+
{
150+
EditorGUI.showMixedValue = intensityIsMixed;
151+
EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue;
152+
153+
if (unitIsMixed)
140154
{
141-
target.SetFloat(kEmissiveIntensityUnit, newUnitFloat);
155+
using (new EditorGUI.DisabledScope(unitIsMixed))
156+
materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
142157
}
158+
else
159+
{
160+
if (!intensityIsMixed && unit == EmissiveIntensityUnit.EV100)
161+
{
162+
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
163+
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
164+
evValue = Mathf.Clamp(evValue, 0, float.MaxValue);
165+
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
166+
}
167+
else
168+
{
169+
EditorGUI.BeginChangeCheck();
170+
materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
171+
if (EditorGUI.EndChangeCheck())
172+
emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue);
173+
}
174+
}
175+
176+
EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue;
177+
EditorGUI.BeginChangeCheck();
178+
var newUnit = (EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit);
179+
if (EditorGUI.EndChangeCheck())
180+
emissiveIntensityUnit.floatValue = (float)newUnit;
143181
}
144-
materialEditor.serializedObject.Update();
182+
EditorGUI.showMixedValue = false;
145183
}
146184

147185
void DrawEmissionGUI()
@@ -153,85 +191,19 @@ void DrawEmissionGUI()
153191
// This flag allows us to track is a material has a non-null emission color. That would require us to enable the target pass
154192
if (useEmissiveIntensity.floatValue == 0)
155193
{
156-
EditorGUI.BeginChangeCheck();
157194
DoEmissiveTextureProperty(emissiveColor);
158-
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
159-
emissiveColor.colorValue = emissiveColor.colorValue;
160195
EditorGUILayout.HelpBox(Styles.emissiveIntensityFromHDRColorText.text, MessageType.Info, true);
161196
}
162197
else
163198
{
164-
float newUnitFloat;
165-
float newIntensity = emissiveIntensity.floatValue;
166-
bool unitIsMixed = emissiveIntensityUnit.hasMixedValue;
167-
bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue;
168-
bool intensityChanged = false;
169-
bool unitChanged = false;
170-
EditorGUI.BeginChangeCheck();
171-
{
172-
DoEmissiveTextureProperty(emissiveColorLDR);
173-
174-
using (new EditorGUILayout.HorizontalScope())
175-
{
176-
EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue;
177-
EditorGUI.showMixedValue = intensityIsMixed;
178-
179-
if (unit == EmissiveIntensityUnit.Nits)
180-
{
181-
using (var change = new EditorGUI.ChangeCheckScope())
182-
{
183-
materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
184-
intensityChanged = change.changed;
185-
if (intensityChanged)
186-
newIntensity = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue);
187-
}
188-
}
189-
else
190-
{
191-
float value = emissiveIntensity.floatValue;
192-
if (!intensityIsMixed)
193-
{
194-
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
195-
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
196-
newIntensity = Mathf.Clamp(evValue, 0, float.MaxValue);
197-
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
198-
}
199-
else
200-
{
201-
using (var change = new EditorGUI.ChangeCheckScope())
202-
{
203-
newIntensity = EditorGUILayout.FloatField(Styles.emissiveIntensityText, value);
204-
intensityChanged = change.changed;
205-
}
206-
}
207-
}
208-
EditorGUI.showMixedValue = false;
209-
210-
EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue;
211-
using (var change = new EditorGUI.ChangeCheckScope())
212-
{
213-
newUnitFloat = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit);
214-
unitChanged = change.changed;
215-
}
216-
EditorGUI.showMixedValue = false;
217-
}
218-
}
219-
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
220-
{
221-
if (unitChanged)
222-
{
223-
if (unitIsMixed)
224-
UpdateEmissionUnit(newUnitFloat);
225-
else
226-
emissiveIntensityUnit.floatValue = newUnitFloat;
227-
}
228-
229-
// We don't allow changes on intensity if units are mixed
230-
if (intensityChanged && !unitIsMixed)
231-
emissiveIntensity.floatValue = newIntensity;
199+
if (updateEmissiveColor)
200+
UpdateEmissiveColorLDRFromIntensityAndEmissiveColor(materialEditor, materials);
232201

233-
UpdateEmissiveColorFromIntensityAndEmissiveColorLDR();
234-
}
202+
EditorGUI.BeginChangeCheck();
203+
DoEmissiveTextureProperty(emissiveColorLDR);
204+
DoEmissiveIntensityGUI(materialEditor, emissiveIntensity, emissiveIntensityUnit);
205+
if (EditorGUI.EndChangeCheck())
206+
UpdateEmissiveColorFromIntensityAndEmissiveColorLDR(materialEditor, materials);
235207
}
236208

237209
materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText);

0 commit comments

Comments
 (0)