Skip to content

Fix few multi-editing issues with Emission UI #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed an issue where asset preview could be rendered white because of static lighting sky.
- Fixed an issue where static lighting was not updated when removing the static lighting sky profile.
- Fixed the show cookie atlas debug mode not displaying correctly when enabling the clear cookie atlas option.
- Fixed various multi-editing issues when changing Emission parameters.

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ public override void OnGUI()
}
}

void UpdateEmissiveColorAndIntensity()
{
materialEditor.serializedObject.ApplyModifiedProperties();
foreach (Material target in materials)
{
if (target.HasProperty(kEmissiveColorLDR) && target.HasProperty(kEmissiveIntensity) && target.HasProperty(kEmissiveColor))
{
target.SetColor(kEmissiveColor, target.GetColor(kEmissiveColorLDR) * target.GetFloat(kEmissiveIntensity));
}
}
materialEditor.serializedObject.Update();
}

void UpdateEmissionUnit(float newUnitFloat)
{
foreach (Material target in materials)
{
if (target.HasProperty(kEmissiveIntensityUnit) && target.HasProperty(kEmissiveIntensity))
{
target.SetFloat(kEmissiveIntensityUnit, newUnitFloat);
}
}
materialEditor.serializedObject.Update();
}

void DrawEmissionGUI()
{
EditorGUI.BeginChangeCheck();
Expand All @@ -120,35 +145,85 @@ void DrawEmissionGUI()
else
{
EditorGUI.BeginChangeCheck();
DoEmissiveTextureProperty(emissiveColorLDR);
// Normalize all emissive colors for each target separately
foreach (Material material in materials)
{
DoEmissiveTextureProperty(emissiveColorLDR);
emissiveColorLDR.colorValue = NormalizeEmissionColor(ref updateEmissiveColor, emissiveColorLDR.colorValue);
if (material.HasProperty(kEmissiveColorLDR))
material.SetColor(kEmissiveColorLDR, NormalizeEmissionColor(ref updateEmissiveColor, material.GetColor(kEmissiveColorLDR)));
}
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
UpdateEmissiveColorAndIntensity();

float newUnitFloat;
float newIntensity = emissiveIntensity.floatValue;
bool unitIsMixed = emissiveIntensityUnit.hasMixedValue;
bool intensityIsMixed = unitIsMixed || emissiveIntensity.hasMixedValue;
bool intensityChanged = false;
bool unitChanged = false;
EditorGUI.BeginChangeCheck();
{
using (new EditorGUILayout.HorizontalScope())
{
EmissiveIntensityUnit unit = (EmissiveIntensityUnit)emissiveIntensityUnit.floatValue;
EditorGUI.showMixedValue = intensityIsMixed;

if (unit == EmissiveIntensityUnit.Nits)
{
using (var change = new EditorGUI.ChangeCheckScope())
{
materialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
if (change.changed)
emissiveIntensity.floatValue = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue);
intensityChanged = change.changed;
if (intensityChanged)
newIntensity = Mathf.Clamp(emissiveIntensity.floatValue, 0, float.MaxValue);
}
}
else
{
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
evValue = Mathf.Clamp(evValue, 0, float.MaxValue);
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
float value = emissiveIntensity.floatValue;
if (!intensityIsMixed)
{
float evValue = LightUtils.ConvertLuminanceToEv(emissiveIntensity.floatValue);
evValue = EditorGUILayout.FloatField(Styles.emissiveIntensityText, evValue);
newIntensity = Mathf.Clamp(evValue, 0, float.MaxValue);
emissiveIntensity.floatValue = LightUtils.ConvertEvToLuminance(evValue);
}
else
{
using (var change = new EditorGUI.ChangeCheckScope())
{
newIntensity = EditorGUILayout.FloatField(Styles.emissiveIntensityText, value);
intensityChanged = change.changed;
}
}
}
EditorGUI.showMixedValue = false;

EditorGUI.showMixedValue = emissiveIntensityUnit.hasMixedValue;
using (var change = new EditorGUI.ChangeCheckScope())
{
newUnitFloat = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit);
unitChanged = change.changed;
}
emissiveIntensityUnit.floatValue = (float)(EmissiveIntensityUnit)EditorGUILayout.EnumPopup(unit);
EditorGUI.showMixedValue = false;
}
}
if (EditorGUI.EndChangeCheck() || updateEmissiveColor)
emissiveColor.colorValue = emissiveColorLDR.colorValue * emissiveIntensity.floatValue;
{
if(unitChanged)
{
if (unitIsMixed)
UpdateEmissionUnit(newUnitFloat);
else
emissiveIntensityUnit.floatValue = newUnitFloat;
}

// We don't allow changes on intensity if units are mixed
if (intensityChanged && !unitIsMixed)
emissiveIntensity.floatValue = newIntensity;

UpdateEmissiveColorAndIntensity();
}
}

materialEditor.ShaderProperty(emissiveExposureWeight, Styles.emissiveExposureWeightText);
Expand Down