Skip to content

Fixed interpolation issue with wind orientation (case 1379841). #6284

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 6 commits into from
Nov 25, 2021
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 @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed SpeedTree graph compatibility by adding raytracing quality keyword to provide a safe path.
- Fixed options to trigger cached shadows updates on light transform changes.
- Fixed objects belonging to preview scenes being marked as dirty during migration (case 1367204).
- Fixed interpolation issue with wind orientation (case 1379841).

### Changed
- Optimizations for the physically based depth of field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,19 @@ public override void OnInspectorGUI()

sealed class LocalWindParameterDrawer
{
public static readonly string[] modeNames = Enum.GetNames(typeof(WindParameter.WindOverrideMode));
public static readonly int popupWidth = 70;
static readonly string[] modeNames = Enum.GetNames(typeof(WindParameter.WindOverrideMode));
static readonly string[] modeNamesNoMultiply = { WindParameter.WindOverrideMode.Custom.ToString(), WindParameter.WindOverrideMode.Global.ToString(), WindParameter.WindOverrideMode.Additive.ToString() };
static readonly int popupWidth = 70;

public static bool BeginGUI(out Rect rect, GUIContent title, SerializedDataParameter parameter, SerializedProperty mode)
public static bool BeginGUI(out Rect rect, GUIContent title, SerializedDataParameter parameter, SerializedProperty mode, bool excludeMultiply)
{
rect = EditorGUILayout.GetControlRect();
rect.xMax -= popupWidth + 2;

var popupRect = rect;
popupRect.x = rect.xMax + 2;
popupRect.width = popupWidth;
mode.intValue = EditorGUI.Popup(popupRect, mode.intValue, modeNames);
mode.intValue = EditorGUI.Popup(popupRect, mode.intValue, excludeMultiply ? modeNamesNoMultiply : modeNames);

if (mode.intValue == (int)WindParameter.WindOverrideMode.Additive)
{
Expand Down Expand Up @@ -203,7 +204,7 @@ sealed class WindOrientationParameterDrawer : VolumeParameterDrawer
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var mode = parameter.value.FindPropertyRelative("mode");
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode))
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode, true))
{
var value = parameter.value.FindPropertyRelative("customValue");
value.floatValue = EditorGUI.Slider(rect, title, value.floatValue, 0.0f, 360.0f);
Expand All @@ -220,7 +221,7 @@ sealed class WindSpeedParameterDrawer : VolumeParameterDrawer
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
{
var mode = parameter.value.FindPropertyRelative("mode");
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode))
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode, false))
{
var value = parameter.value.FindPropertyRelative("customValue");
value.floatValue = EditorGUI.FloatField(rect, title, value.floatValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,5 +1179,50 @@ internal static void ReleaseComponentSingletons()
ComponentSingleton<HDAdditionalLightData>.Release();
ComponentSingleton<HDAdditionalCameraData>.Release();
}

internal static float InterpolateOrientation(float fromValue, float toValue, float t)
{
// Compute the direct distance
float directDistance = Mathf.Abs(toValue - fromValue);
float outputValue = 0.0f;

// Handle the two cases
if (fromValue < toValue)
{
float upperRange = 360.0f - toValue;
float lowerRange = fromValue;
float alternativeDistance = upperRange + lowerRange;
if (alternativeDistance < directDistance)
{
float targetValue = toValue - 360.0f;
outputValue = fromValue + (targetValue - fromValue) * t;
if (outputValue < 0.0f)
outputValue += 360.0f;
}
else
{
outputValue = fromValue + (toValue - fromValue) * t;
}
}
else
{
float upperRange = 360.0f - fromValue;
float lowerRange = toValue;
float alternativeDistance = upperRange + lowerRange;
if (alternativeDistance < directDistance)
{
float targetValue = toValue + 360.0f;
outputValue = fromValue + (targetValue - fromValue) * t;
if (outputValue > 360.0f)
outputValue -= 360.0f;
}
else
{
outputValue = fromValue + (toValue - fromValue) * t;
}
}

return outputValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,36 @@ public WindOrientationParameter(float value = 0.0f, WindOverrideMode mode = Wind
/// <returns>The value for this parameter.</returns>
protected override float GetGlobalValue(HDCamera camera) =>
camera.volumeStack.GetComponent<VisualEnvironment>().windOrientation.value;

/// <summary>Interpolates between two values.</summary>
/// <param name="from">The start value</param>
/// <param name="to">The end value</param>
/// <param name="t">The interpolation factor in range [0,1]</param>
public override void Interp(WindParamaterValue from, WindParamaterValue to, float t)
{
// These are not used
m_Value.multiplyValue = 0;

// Binary state that cannot be blended
m_Value.mode = t > 0f ? to.mode : from.mode;

// Override the orientation specific values
m_Value.additiveValue = from.additiveValue + (to.additiveValue - from.additiveValue) * t;
m_Value.customValue = HDUtils.InterpolateOrientation(from.customValue, to.customValue, t);
}

/// <summary>Returns interpolated value from the visual environment.</summary>
/// <param name="camera">The camera containing the volume stack to evaluate</param>
/// <returns>The value for this parameter.</returns>
public float GetValue(HDCamera camera)
{
// Multiply mode is not supported for wind orientation
if (value.mode == WindOverrideMode.Multiply)
throw new NotSupportedException("Texture format not supported");

// Otherwise we want the base behavior
return base.GetValue(camera);
}
}

/// <summary>
Expand Down