Skip to content

Commit

Permalink
Reflection Probes: Retain world-space capture position when influence…
Browse files Browse the repository at this point in the history
… volume is resized. Previously, capture position would scale with the size of the influence volume, because it is serialized in proxy space, and no special logic existed to handle its transform. (#22)
  • Loading branch information
pastasfuture committed Oct 19, 2022
1 parent e911488 commit e9b0516
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static void DrawHandles(SerializedHDProbe serialized, Editor owner)
switch (EditMode.editMode)
{
case EditBaseShape:
InfluenceVolumeUI.DrawHandles_EditBase(serialized.probeSettings.influence, owner, probe.transform);
InfluenceVolumeUI.DrawHandles_EditBase(serialized.probeSettings.influence, owner, probe.transform, serialized.probeSettings.proxyCapturePositionProxySpace);
break;
case EditInfluenceShape:
InfluenceVolumeUI.DrawHandles_EditInfluence(serialized.probeSettings.influence, owner, probe.transform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace UnityEditor.Rendering.HighDefinition
{
partial class InfluenceVolumeUI
{
public static void DrawHandles_EditBase(SerializedInfluenceVolume serialized, Editor owner, Transform transform)
public static void DrawHandles_EditBase(SerializedInfluenceVolume serialized, Editor owner, Transform transform, SerializedProperty proxyCapturePositionProxySpace)
{
switch ((InfluenceShape)serialized.shape.intValue)
{
case InfluenceShape.Box:
DrawBoxHandle(serialized, owner, transform, s_BoxBaseHandle);
DrawBoxHandle(serialized, owner, transform, s_BoxBaseHandle, proxyCapturePositionProxySpace);
break;
case InfluenceShape.Sphere:
using (new Handles.DrawingScope(Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one)))
Expand Down Expand Up @@ -103,13 +103,15 @@ public static void DrawHandles_EditInfluenceNormal(SerializedInfluenceVolume ser
}
}

static void DrawBoxHandle(SerializedInfluenceVolume serialized, Editor owner, Transform transform, HierarchicalBox box)
static void DrawBoxHandle(SerializedInfluenceVolume serialized, Editor owner, Transform transform, HierarchicalBox box, SerializedProperty proxyCapturePositionProxySpace)
{
using (new Handles.DrawingScope(Matrix4x4.TRS(Vector3.zero, transform.rotation, Vector3.one)))
{
box.center = Quaternion.Inverse(transform.rotation) * transform.position;
box.size = serialized.boxSize.vector3Value;

Vector3 proxyCapturePositionWS = transform.position + (transform.rotation * proxyCapturePositionProxySpace.vector3Value);

EditorGUI.BeginChangeCheck();
box.DrawHull(true);
box.DrawHandle();
Expand All @@ -119,6 +121,8 @@ static void DrawBoxHandle(SerializedInfluenceVolume serialized, Editor owner, Tr
Undo.RecordObject(transform, "Moving Influence");
transform.position = newPosition;

proxyCapturePositionProxySpace.vector3Value = Vector3.Max(serialized.boxSize.vector3Value * -0.5f, Vector3.Min(serialized.boxSize.vector3Value * 0.5f, Quaternion.Inverse(transform.rotation) * (proxyCapturePositionWS - transform.position)));

// Clamp blend distances
var blendPositive = serialized.boxBlendDistancePositive.vector3Value;
var blendNegative = serialized.boxBlendDistanceNegative.vector3Value;
Expand Down

0 comments on commit e9b0516

Please sign in to comment.