Skip to content

Commit a4c4bc5

Browse files
Fixed interpolation issue with wind orientation (case 1379841). (#6284)
* Fixed interpolation issue with wind orientation (case 1379841). * fix formatting Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent 8fe3d07 commit a4c4bc5

4 files changed

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

4142
### Changed
4243
- Optimizations for the physically based depth of field.

com.unity.render-pipelines.high-definition/Editor/Sky/VisualEnvironmentEditor.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,19 @@ public override void OnInspectorGUI()
152152

153153
sealed class LocalWindParameterDrawer
154154
{
155-
public static readonly string[] modeNames = Enum.GetNames(typeof(WindParameter.WindOverrideMode));
156-
public static readonly int popupWidth = 70;
155+
static readonly string[] modeNames = Enum.GetNames(typeof(WindParameter.WindOverrideMode));
156+
static readonly string[] modeNamesNoMultiply = { WindParameter.WindOverrideMode.Custom.ToString(), WindParameter.WindOverrideMode.Global.ToString(), WindParameter.WindOverrideMode.Additive.ToString() };
157+
static readonly int popupWidth = 70;
157158

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

163164
var popupRect = rect;
164165
popupRect.x = rect.xMax + 2;
165166
popupRect.width = popupWidth;
166-
mode.intValue = EditorGUI.Popup(popupRect, mode.intValue, modeNames);
167+
mode.intValue = EditorGUI.Popup(popupRect, mode.intValue, excludeMultiply ? modeNamesNoMultiply : modeNames);
167168

168169
if (mode.intValue == (int)WindParameter.WindOverrideMode.Additive)
169170
{
@@ -203,7 +204,7 @@ sealed class WindOrientationParameterDrawer : VolumeParameterDrawer
203204
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
204205
{
205206
var mode = parameter.value.FindPropertyRelative("mode");
206-
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode))
207+
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode, true))
207208
{
208209
var value = parameter.value.FindPropertyRelative("customValue");
209210
value.floatValue = EditorGUI.Slider(rect, title, value.floatValue, 0.0f, 360.0f);
@@ -220,7 +221,7 @@ sealed class WindSpeedParameterDrawer : VolumeParameterDrawer
220221
public override bool OnGUI(SerializedDataParameter parameter, GUIContent title)
221222
{
222223
var mode = parameter.value.FindPropertyRelative("mode");
223-
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode))
224+
if (!LocalWindParameterDrawer.BeginGUI(out var rect, title, parameter, mode, false))
224225
{
225226
var value = parameter.value.FindPropertyRelative("customValue");
226227
value.floatValue = EditorGUI.FloatField(rect, title, value.floatValue);

com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Utility/HDUtils.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,5 +1179,50 @@ internal static void ReleaseComponentSingletons()
11791179
ComponentSingleton<HDAdditionalLightData>.Release();
11801180
ComponentSingleton<HDAdditionalCameraData>.Release();
11811181
}
1182+
1183+
internal static float InterpolateOrientation(float fromValue, float toValue, float t)
1184+
{
1185+
// Compute the direct distance
1186+
float directDistance = Mathf.Abs(toValue - fromValue);
1187+
float outputValue = 0.0f;
1188+
1189+
// Handle the two cases
1190+
if (fromValue < toValue)
1191+
{
1192+
float upperRange = 360.0f - toValue;
1193+
float lowerRange = fromValue;
1194+
float alternativeDistance = upperRange + lowerRange;
1195+
if (alternativeDistance < directDistance)
1196+
{
1197+
float targetValue = toValue - 360.0f;
1198+
outputValue = fromValue + (targetValue - fromValue) * t;
1199+
if (outputValue < 0.0f)
1200+
outputValue += 360.0f;
1201+
}
1202+
else
1203+
{
1204+
outputValue = fromValue + (toValue - fromValue) * t;
1205+
}
1206+
}
1207+
else
1208+
{
1209+
float upperRange = 360.0f - fromValue;
1210+
float lowerRange = toValue;
1211+
float alternativeDistance = upperRange + lowerRange;
1212+
if (alternativeDistance < directDistance)
1213+
{
1214+
float targetValue = toValue + 360.0f;
1215+
outputValue = fromValue + (targetValue - fromValue) * t;
1216+
if (outputValue > 360.0f)
1217+
outputValue -= 360.0f;
1218+
}
1219+
else
1220+
{
1221+
outputValue = fromValue + (toValue - fromValue) * t;
1222+
}
1223+
}
1224+
1225+
return outputValue;
1226+
}
11821227
}
11831228
}

com.unity.render-pipelines.high-definition/Runtime/Sky/VisualEnvironment.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,36 @@ public WindOrientationParameter(float value = 0.0f, WindOverrideMode mode = Wind
218218
/// <returns>The value for this parameter.</returns>
219219
protected override float GetGlobalValue(HDCamera camera) =>
220220
camera.volumeStack.GetComponent<VisualEnvironment>().windOrientation.value;
221+
222+
/// <summary>Interpolates between two values.</summary>
223+
/// <param name="from">The start value</param>
224+
/// <param name="to">The end value</param>
225+
/// <param name="t">The interpolation factor in range [0,1]</param>
226+
public override void Interp(WindParamaterValue from, WindParamaterValue to, float t)
227+
{
228+
// These are not used
229+
m_Value.multiplyValue = 0;
230+
231+
// Binary state that cannot be blended
232+
m_Value.mode = t > 0f ? to.mode : from.mode;
233+
234+
// Override the orientation specific values
235+
m_Value.additiveValue = from.additiveValue + (to.additiveValue - from.additiveValue) * t;
236+
m_Value.customValue = HDUtils.InterpolateOrientation(from.customValue, to.customValue, t);
237+
}
238+
239+
/// <summary>Returns interpolated value from the visual environment.</summary>
240+
/// <param name="camera">The camera containing the volume stack to evaluate</param>
241+
/// <returns>The value for this parameter.</returns>
242+
public float GetValue(HDCamera camera)
243+
{
244+
// Multiply mode is not supported for wind orientation
245+
if (value.mode == WindOverrideMode.Multiply)
246+
throw new NotSupportedException("Texture format not supported");
247+
248+
// Otherwise we want the base behavior
249+
return base.GetValue(camera);
250+
}
221251
}
222252

223253
/// <summary>

0 commit comments

Comments
 (0)