Skip to content

Fixed multi-editing with new light intensity slider #2600

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 2 commits into from
Nov 19, 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 @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed picking for materials with depth offset.
- Fixed issue with exposure history being uninitialized on second frame.
- Fixed issue when changing FoV with the physical camera fold-out closed.
- Fixed multi-editing with new light intensity slider.

### Changed
- Combined occlusion meshes into one to reduce draw calls and state changes with XR single-pass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ static void DrawLightIntensityGUILayout(SerializedHDLight serialized, Editor own
unitRect.width = k_UnitWidth + .5f;

// Draw the unit textfield
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(valueRect, serialized.intensity, s_Styles.empty);
DrawLightIntensityUnitPopup(unitRect, serialized, owner);

Expand Down Expand Up @@ -691,8 +692,6 @@ static void DrawEmissionContent(SerializedHDLight serialized, Editor owner)
EditorGUILayout.PropertyField(serialized.settings.color, s_Styles.color);
}

EditorGUI.BeginChangeCheck();

DrawLightIntensityGUILayout(serialized, owner);

HDLightType lightType = serialized.type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ public void SetSerializedObject(SerializedObject serialized)
m_SerializedObject = serialized;
}

public virtual void Draw(Rect rect, SerializedProperty value)
public virtual void Draw(Rect rect, SerializedProperty value, ref float floatValue)
{
BuildRects(rect, out var sliderRect, out var iconRect);

if (m_Descriptor.clampValue)
ClampValue(value, m_Descriptor.sliderRange);
ClampValue(ref floatValue, m_Descriptor.sliderRange);

var level = CurrentRange(value.floatValue);
var level = CurrentRange(floatValue);

DoSlider(sliderRect, value, m_Descriptor.sliderRange, level.value);
DoSlider(sliderRect, ref floatValue, m_Descriptor.sliderRange, level.value);

if (m_Descriptor.hasMarkers)
{
Expand All @@ -66,9 +66,9 @@ public virtual void Draw(Rect rect, SerializedProperty value)

var levelIconContent = level.content;
var levelRange = level.value;
DoIcon(iconRect, levelIconContent, value, levelRange.y);
DoIcon(iconRect, levelIconContent, value, floatValue, levelRange.y);

var thumbValue = value.floatValue;
var thumbValue = floatValue;
var thumbPosition = GetPositionOnSlider(thumbValue, level.value);
var thumbTooltip = levelIconContent.tooltip;
DoThumbTooltip(sliderRect, thumbPosition, thumbValue, thumbTooltip);
Expand Down Expand Up @@ -99,8 +99,8 @@ void BuildRects(Rect baseRect, out Rect sliderRect, out Rect iconRect)
iconRect.width = EditorGUIUtility.singleLineHeight;
}

void ClampValue(SerializedProperty value, Vector2 range) =>
value.floatValue = Mathf.Clamp(value.floatValue, range.x, range.y);
void ClampValue(ref float value, Vector2 range) =>
value = Mathf.Clamp(value, range.x, range.y);

private static Color k_DarkThemeColor = new Color32(153, 153, 153, 255);
private static Color k_LiteThemeColor = new Color32(97, 97, 97, 255);
Expand Down Expand Up @@ -143,7 +143,7 @@ void DoSliderMarker(Rect rect, float position, float value, string tooltip)
EditorGUI.LabelField(markerTooltipRect, GetLightUnitTooltip(tooltip, value, m_Descriptor.unitName));
}

void DoIcon(Rect rect, GUIContent icon, SerializedProperty value, float range)
void DoIcon(Rect rect, GUIContent icon, SerializedProperty value, float floatValue, float range)
{
// Draw the context menu feedback before the icon
GUI.Box(rect, GUIContent.none, SliderStyles.k_IconButton);
Expand All @@ -162,20 +162,20 @@ void DoIcon(Rect rect, GUIContent icon, SerializedProperty value, float range)
if (rect.Contains(e.mousePosition))
{
var menuPosition = rect.position + rect.size;
DoContextMenu(menuPosition, value);
DoContextMenu(menuPosition, value, floatValue);
e.Use();
}
}
}

void DoContextMenu(Vector2 pos, SerializedProperty value)
void DoContextMenu(Vector2 pos, SerializedProperty value, float floatValue)
{
var menu = new GenericMenu();

foreach (var preset in m_Descriptor.valueRanges)
{
// Indicate a checkmark if the value is within this preset range.
var isInPreset = CurrentRange(value.floatValue).value == preset.value;
var isInPreset = CurrentRange(floatValue).value == preset.value;

menu.AddItem(EditorGUIUtility.TrTextContent(preset.content.tooltip), isInPreset, () => SetValueToPreset(value, preset));
}
Expand Down Expand Up @@ -218,17 +218,17 @@ protected virtual GUIContent GetLightUnitTooltip(string baseTooltip, float value
return new GUIContent(string.Empty, tooltip);
}

protected virtual void DoSlider(Rect rect, SerializedProperty value, Vector2 sliderRange, Vector2 valueRange)
protected virtual void DoSlider(Rect rect, ref float value, Vector2 sliderRange, Vector2 valueRange)
{
DoSlider(rect, value, sliderRange);
DoSlider(rect, ref value, sliderRange);
}

/// <summary>
/// Draws a linear slider mapped to the min/max value range. Override this for different slider behavior (texture background, power).
/// </summary>
protected virtual void DoSlider(Rect rect, SerializedProperty value, Vector2 sliderRange)
protected virtual void DoSlider(Rect rect, ref float value, Vector2 sliderRange)
{
value.floatValue = GUI.HorizontalSlider(rect, value.floatValue, sliderRange.x, sliderRange.y);
value = GUI.HorizontalSlider(rect, value, sliderRange.x, sliderRange.y);
}

// Remaps value in the domain { Min0, Max0 } to { Min1, Max1 } (by default, normalizes it to (0, 1).
Expand Down Expand Up @@ -338,36 +338,36 @@ bool UpdatePiece(ref Piece piece, float x)
return false;
}

void SliderOutOfBounds(Rect rect, SerializedProperty value)
void SliderOutOfBounds(Rect rect, ref float value)
{
EditorGUI.BeginChangeCheck();
var internalValue = GUI.HorizontalSlider(rect, value.floatValue, 0f, 1f);
var internalValue = GUI.HorizontalSlider(rect, value, 0f, 1f);
if (EditorGUI.EndChangeCheck())
{
Piece p = new Piece();
UpdatePiece(ref p, internalValue);
value.floatValue = SliderToValue(p, internalValue);
value = SliderToValue(p, internalValue);
}
}

protected override void DoSlider(Rect rect, SerializedProperty value, Vector2 sliderRange, Vector2 valueRange)
protected override void DoSlider(Rect rect, ref float value, Vector2 sliderRange, Vector2 valueRange)
{
// Map the internal slider value to the current piecewise function
if (!m_PiecewiseFunctionMap.TryGetValue(valueRange, out var piece))
{
// Assume that if the piece is not found, that means the unit value is out of bounds.
SliderOutOfBounds(rect, value);
SliderOutOfBounds(rect, ref value);
return;
}

// Maintain an internal value to support a single linear continuous function
EditorGUI.BeginChangeCheck();
var internalValue = GUI.HorizontalSlider(rect, ValueToSlider(piece, value.floatValue), 0f, 1f);
var internalValue = GUI.HorizontalSlider(rect, ValueToSlider(piece, value), 0f, 1f);
if (EditorGUI.EndChangeCheck())
{
// Ensure that the current function piece is being used to transform the value
UpdatePiece(ref piece, internalValue);
value.floatValue = SliderToValue(piece, internalValue);
value = SliderToValue(piece, internalValue);
}
}
}
Expand Down Expand Up @@ -404,18 +404,15 @@ public void Setup(LightUnit unit, SerializedHDLight light, Editor owner)
m_SpotReflectorEnabled = light.enableSpotReflector.boolValue;
}

public override void Draw(Rect rect, SerializedProperty value)
public override void Draw(Rect rect, SerializedProperty value, ref float floatValue)
{
// Convert the incoming unit value into Lumen as the punctual slider is always in these terms (internally)
value.floatValue = UnitToLumen(value.floatValue);
float convertedValue = UnitToLumen(floatValue);

base.Draw(rect, value);

value.floatValue = LumenToUnit(value.floatValue);

// Must apply properties here to ensure proper undo/redo functionality.
// The reason this is likely necessary is due to how we handle the internal unit conversion into lumen.
m_Light.Apply();
EditorGUI.BeginChangeCheck();
base.Draw(rect, value, ref convertedValue);
if (EditorGUI.EndChangeCheck())
floatValue = LumenToUnit(convertedValue);
}

protected override GUIContent GetLightUnitTooltip(string baseTooltip, float value, string unit)
Expand Down Expand Up @@ -551,27 +548,27 @@ protected override void SetValueToPreset(SerializedProperty value, LightUnitSlid
m_Settings.ApplyModifiedProperties();
}

protected override void DoSlider(Rect rect, SerializedProperty value, Vector2 sliderRange)
protected override void DoSlider(Rect rect, ref float value, Vector2 sliderRange)
{
SliderWithTextureNoTextField(rect, value, sliderRange, m_Settings);
SliderWithTextureNoTextField(rect, ref value, sliderRange, m_Settings);
}

// Note: We could use the internal SliderWithTexture, however: the internal slider func forces a text-field (and no ability to opt-out of it).
void SliderWithTextureNoTextField(Rect rect, SerializedProperty value, Vector2 range, LightEditor.Settings settings)
void SliderWithTextureNoTextField(Rect rect, ref float value, Vector2 range, LightEditor.Settings settings)
{
GUI.DrawTexture(rect, GetKelvinGradientTexture(settings));

EditorGUI.BeginChangeCheck();

// Draw the exponential slider that fits 6500K to the white point on the gradient texture.
var internalValue = GUI.HorizontalSlider(rect, ValueToSlider(value.floatValue), 0f, 1f, SliderStyles.k_TemperatureBorder, SliderStyles.k_TemperatureThumb);
var internalValue = GUI.HorizontalSlider(rect, ValueToSlider(value), 0f, 1f, SliderStyles.k_TemperatureBorder, SliderStyles.k_TemperatureThumb);

// Map the value back into kelvin.
value.floatValue = SliderToValue(internalValue);
value = SliderToValue(internalValue);

// Round to nearest since so much precision is not necessary for kelvin while sliding.
if (EditorGUI.EndChangeCheck())
value.floatValue = Mathf.Round(value.floatValue);
value = Mathf.Round(value);
}
}

Expand Down Expand Up @@ -620,20 +617,30 @@ public void Draw(HDLightType type, LightUnit lightUnit, SerializedProperty value

void DrawDirectionalUnitSlider(SerializedProperty value, Rect rect)
{
k_DirectionalLightUnitSlider.Draw(rect, value);
float val = value.floatValue;
k_DirectionalLightUnitSlider.Draw(rect, value, ref val);
if (val != value.floatValue)
value.floatValue = val;
}

void DrawPunctualLightUnitSlider(LightUnit lightUnit, SerializedProperty value, Rect rect, SerializedHDLight light, Editor owner)
{
k_PunctualLightUnitSlider.Setup(lightUnit, light, owner);
k_PunctualLightUnitSlider.Draw(rect, value);

float val = value.floatValue;
k_PunctualLightUnitSlider.Draw(rect, value, ref val);
if (val != value.floatValue)
value.floatValue = val;
}

public void DrawExposureSlider(SerializedProperty value, Rect rect)
{
using (new EditorGUI.IndentLevelScope(-EditorGUI.indentLevel))
{
k_ExposureSlider.Draw(rect, value);
float val = value.floatValue;
k_ExposureSlider.Draw(rect, value, ref val);
if (val != value.floatValue)
value.floatValue = val;
}
}

Expand All @@ -642,7 +649,11 @@ public void DrawTemperatureSlider(LightEditor.Settings settings, SerializedPrope
using (new EditorGUI.IndentLevelScope(-EditorGUI.indentLevel))
{
k_TemperatureSlider.Setup(settings);
k_TemperatureSlider.Draw(rect, value);

float val = value.floatValue;
k_TemperatureSlider.Draw(rect, value, ref val);
if (val != value.floatValue)
value.floatValue = val;
}
}
}
Expand Down