Skip to content

Commit b64ed6c

Browse files
Fixes for light anchor #5915
1 parent e6727d8 commit b64ed6c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

com.unity.render-pipelines.core/Editor/Lighting/LightAnchorEditor.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class LightAnchorEditor : Editor
3333
SerializedProperty m_DistanceProperty;
3434
SerializedProperty m_FrameSpaceProperty;
3535
SerializedProperty m_AnchorPositionOverrideProperty;
36+
SerializedProperty m_AnchorPositionOffsetProperty;
3637

3738
LightAnchor manipulator
3839
{
@@ -132,7 +133,8 @@ public override void OnInspectorGUI()
132133

133134
EditorGUI.BeginChangeCheck();
134135
EditorGUILayout.PropertyField(m_DistanceProperty, LightAnchorStyles.distanceProperty);
135-
distanceChanged = EditorGUI.EndChangeCheck();
136+
if (distanceChanged = EditorGUI.EndChangeCheck())
137+
m_DistanceProperty.floatValue = Mathf.Min(m_DistanceProperty.floatValue, LightAnchor.k_MaxDistance);
136138

137139
EditorGUI.BeginChangeCheck();
138140
EditorGUILayout.PropertyField(m_FrameSpaceProperty, LightAnchorStyles.upDirectionProperty);
@@ -142,6 +144,15 @@ public override void OnInspectorGUI()
142144
EditorGUILayout.PropertyField(m_AnchorPositionOverrideProperty, LightAnchorStyles.anchorPositionOverrideProperty);
143145
positionOverrideChanged = EditorGUI.EndChangeCheck();
144146

147+
if (m_AnchorPositionOverrideProperty.objectReferenceValue != null)
148+
{
149+
EditorGUI.indentLevel++;
150+
EditorGUI.BeginChangeCheck();
151+
EditorGUILayout.PropertyField(m_AnchorPositionOffsetProperty, LightAnchorStyles.anchorPositionOffsetProperty);
152+
positionOverrideChanged |= EditorGUI.EndChangeCheck();
153+
EditorGUI.indentLevel--;
154+
}
155+
145156
if (m_FoldoutPreset = EditorGUILayout.Foldout(m_FoldoutPreset, "Common"))
146157
{
147158
Color cachedColor = GUI.backgroundColor;
@@ -301,8 +312,9 @@ public override void OnInspectorGUI()
301312
Debug.LogError($"Can't assign '{newTransform.name}' because it's a child of the Light Anchor component");
302313
else
303314
{
304-
float newDistance = Vector3.Distance(manipulator.transform.position, newTransform.position);
305315
manipulator.anchorPositionOverride = newTransform;
316+
manipulator.anchorPositionOffset = m_AnchorPositionOffsetProperty.vector3Value;
317+
float newDistance = Vector3.Distance(manipulator.transform.position, manipulator.anchorPosition);
306318
// Orient the object to face the new override position
307319
manipulator.SynchronizeOnTransform(camera);
308320
// And adjust it's distance to avoid modifying it's position.
@@ -358,6 +370,7 @@ void OnEnable()
358370
m_DistanceProperty = serializedObject.FindProperty("m_Distance");
359371
m_FrameSpaceProperty = serializedObject.FindProperty("m_FrameSpace");
360372
m_AnchorPositionOverrideProperty = serializedObject.FindProperty("m_AnchorPositionOverride");
373+
m_AnchorPositionOffsetProperty = serializedObject.FindProperty("m_AnchorPositionOffset");
361374
}
362375

363376
void EditorToolsOnactiveToolChanged()
@@ -599,6 +612,7 @@ static class LightAnchorStyles
599612
static public GUIContent distanceProperty = EditorGUIUtility.TrTextContent("Distance", "Controls how far 'back', the light is placed from its anchor");
600613
static public GUIContent upDirectionProperty = EditorGUIUtility.TrTextContent("Up direction", "Specifies the space in which the up direction of the anchor is defined. Local is relative to the camera.");
601614
static public GUIContent anchorPositionOverrideProperty = EditorGUIUtility.TrTextContent("Anchor Position Override", "Specifies the anchor position manually instead of relying on the angles, distance and transform position to compute the anchor position.");
615+
static public GUIContent anchorPositionOffsetProperty = EditorGUIUtility.TrTextContent("Anchor Position Offset", "Specifies the anchor position offset relative to the anchor position override.");
602616
static public GUIContent[] angleSubContent = new[]
603617
{
604618
EditorGUIUtility.TrTextContent("Orbit"),

com.unity.render-pipelines.core/Runtime/Lights/LightAnchor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ public class LightAnchor : MonoBehaviour
1717
{
1818
const float k_ArcRadius = 5;
1919
const float k_AxisLength = 10;
20+
internal const float k_MaxDistance = 10000f;
2021

2122
[SerializeField, Min(0)]
2223
float m_Distance = 0f;
2324
[SerializeField]
2425
UpDirection m_FrameSpace = UpDirection.World;
2526
[SerializeField]
2627
Transform m_AnchorPositionOverride;
28+
[SerializeField]
29+
Vector3 m_AnchorPositionOffset;
2730

2831
[SerializeField]
2932
float m_Yaw;
@@ -74,7 +77,7 @@ public float roll
7477
public float distance
7578
{
7679
get => m_Distance;
77-
set => m_Distance = Mathf.Max(0, value);
80+
set => m_Distance = Mathf.Clamp(value, 0f, k_MaxDistance);
7881
}
7982

8083
/// <summary>
@@ -109,7 +112,7 @@ public Vector3 anchorPosition
109112
get
110113
{
111114
if (anchorPositionOverride != null)
112-
return anchorPositionOverride.position;
115+
return anchorPositionOverride.position + anchorPositionOverride.TransformDirection(anchorPositionOffset);
113116
else
114117
return transform.position + transform.forward * distance;
115118
}
@@ -132,6 +135,15 @@ public Transform anchorPositionOverride
132135
set => m_AnchorPositionOverride = value;
133136
}
134137

138+
/// <summary>
139+
/// Offset relative to the position of the anchor position override transform in object space.
140+
/// </summary>
141+
public Vector3 anchorPositionOffset
142+
{
143+
get => m_AnchorPositionOffset;
144+
set => m_AnchorPositionOffset = value;
145+
}
146+
135147
/// <summary>
136148
/// Normalizes the input angle to be in the range of -180 and 180.
137149
/// </summary>

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
- Fixed support for orthographic camera in path tracing.
3030
- Fixed crossfade not working on the HD ST8 ShaderGraph [case 1369586](https://fogbugz.unity3d.com/f/cases/1369586/)
3131

32+
### Changed
33+
- Changed the max distance for Light Anchors to avoid unstability with high values (case 1362802).
34+
3235
## [12.0.0] - 2021-01-11
3336

3437
### Added

0 commit comments

Comments
 (0)