diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 519816eb530..19bdcfaf2a8 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -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. diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/VisualEnvironmentEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/VisualEnvironmentEditor.cs index f5f5bb7c49c..1a4efbcbc37 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/VisualEnvironmentEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/VisualEnvironmentEditor.cs @@ -152,10 +152,11 @@ 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; @@ -163,7 +164,7 @@ public static bool BeginGUI(out Rect rect, GUIContent title, SerializedDataParam 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) { @@ -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); @@ -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); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs index fc4172a5296..9f46f0dfd17 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs @@ -1179,5 +1179,50 @@ internal static void ReleaseComponentSingletons() ComponentSingleton.Release(); ComponentSingleton.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; + } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/VisualEnvironment.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/VisualEnvironment.cs index 06b4e581719..77330b9298a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/VisualEnvironment.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/VisualEnvironment.cs @@ -218,6 +218,36 @@ public WindOrientationParameter(float value = 0.0f, WindOverrideMode mode = Wind /// The value for this parameter. protected override float GetGlobalValue(HDCamera camera) => camera.volumeStack.GetComponent().windOrientation.value; + + /// Interpolates between two values. + /// The start value + /// The end value + /// The interpolation factor in range [0,1] + 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); + } + + /// Returns interpolated value from the visual environment. + /// The camera containing the volume stack to evaluate + /// The value for this parameter. + 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); + } } ///