浏览代码

[PlanarReflection] Update capture frustrum calculation

/main
Frédéric Vauchelles 7 年前
当前提交
c8c5a6a6
共有 2 个文件被更改,包括 38 次插入15 次删除
  1. 30
      ScriptableRenderPipeline/Core/CoreRP/Editor/CameraEditorUtils.cs
  2. 23
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeUI.Handles.cs

30
ScriptableRenderPipeline/Core/CoreRP/Editor/CameraEditorUtils.cs


return true;
}
public static Matrix4x4 GetCameraClipToWorld(
Vector3 position, Quaternion rotation,
float nearClipPlane, float farClipPlane,
float fov, float aspect)
{
var p = Matrix4x4.Perspective(fov, aspect, nearClipPlane, farClipPlane);
var v = Matrix4x4.TRS(position, rotation, new Vector3(1, 1, -1)).inverse;
var vp = p * v;
var clipToWorld = vp.inverse;
return clipToWorld;
}
public static Vector3 PerspectiveClipToWorld(Matrix4x4 clipToWorld, Vector3 viewPositionWS, Vector3 positionCS)
{
var tempCS = new Vector3(positionCS.x, positionCS.y, 0.95f);
var result = clipToWorld.MultiplyPoint(tempCS);
var r = result - viewPositionWS;
return r.normalized * positionCS.z + viewPositionWS;
}
public static void GetFrustrumPlaneAt(Matrix4x4 clipToWorld, Vector3 viewPosition, float distance, Vector3[] points)
{
points[0] = new Vector3(-1, -1, distance); // leftBottomFar
points[1] = new Vector3(-1, 1, distance); // leftTopFar
points[2] = new Vector3(1, 1, distance); // rightTopFar
points[3] = new Vector3(1, -1, distance); // rightBottomFar
for (var i = 0; i < 4; ++i)
points[i] = CameraEditorUtils.PerspectiveClipToWorld(clipToWorld, viewPosition, points[i]);
}
static Vector3 MidPointPositionSlider(Vector3 position1, Vector3 position2, Vector3 direction)
{
Vector3 midPoint = Vector3.Lerp(position1, position2, 0.5f);

23
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeUI.Handles.cs


static void DrawGizmos_CaptureFrustrum(PlanarReflectionProbeUI s, PlanarReflectionProbe d)
{
var farClipPlane = d.captureFarPlane;
var nearClipPlane = d.captureNearPlane;
var mat = Matrix4x4.TRS(d.capturePosition, d.captureRotation, Vector3.one);
var clipToWorld = CameraEditorUtils.GetCameraClipToWorld(
d.capturePosition, d.captureRotation,
d.captureNearPlane, d.captureFarPlane,
90, 1);
far[0] = new Vector3(0, 0, farClipPlane); // leftBottomFar
far[1] = new Vector3(0, 1, farClipPlane); // leftTopFar
far[2] = new Vector3(1, 1, farClipPlane); // rightTopFar
far[3] = new Vector3(1, 0, farClipPlane); // rightBottomFar
for (var i = 0; i < 4; ++i)
far[i] = mat.MultiplyPoint(far[i]);
near[0] = new Vector3(0, 0, nearClipPlane); // leftBottomNear
near[1] = new Vector3(0, 1, nearClipPlane); // leftTopNear
near[2] = new Vector3(1, 1, nearClipPlane); // rightTopNear
near[3] = new Vector3(1, 0, nearClipPlane); // rightBottomNear
for (var i = 0; i < 4; ++i)
near[i] = mat.MultiplyPoint(near[i]);
CameraEditorUtils.GetFrustrumPlaneAt(clipToWorld, d.capturePosition, d.captureFarPlane, far);
CameraEditorUtils.GetFrustrumPlaneAt(clipToWorld, d.capturePosition, d.captureNearPlane, near);
var c = Gizmos.color;
Gizmos.color = k_GizmoCamera;

Gizmos.DrawLine(far[i], far[(i + 1) % 4]);
Gizmos.DrawLine(near[i], far[i]);
}
Gizmos.DrawSphere(d.capturePosition, HandleUtility.GetHandleSize(d.capturePosition) * 0.2f);
Gizmos.color = c;
}
}
正在加载...
取消
保存