浏览代码

[PlanarReflection] (wip) oblique frustrum drawing

/main
Frédéric Vauchelles 7 年前
当前提交
1fb483ef
共有 3 个文件被更改,包括 53 次插入17 次删除
  1. 6
      ScriptableRenderPipeline/Core/CoreRP/CameraUtils.cs
  2. 12
      ScriptableRenderPipeline/Core/CoreRP/Editor/CameraEditorUtils.cs
  3. 52
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeUI.Handles.cs

6
ScriptableRenderPipeline/Core/CoreRP/CameraUtils.cs


{
public static class CameraUtils
{
public static readonly Matrix4x4 FlipMatrixLHSRHS = Matrix4x4.Scale(new Vector3(1, 1, -1));
public static Vector4 Plane(Vector3 position, Vector3 normal)
{
var n = normal;

public static Matrix4x4 GetWorldToCameraMatrixLHS(this Camera camera)
{
return Matrix4x4.Scale(new Vector3(1, 1, -1)) * camera.worldToCameraMatrix;
return FlipMatrixLHSRHS * camera.worldToCameraMatrix;
return camera.projectionMatrix * Matrix4x4.Scale(new Vector3(1, 1, -1));
return camera.projectionMatrix * FlipMatrixLHSRHS;
}
public static Matrix4x4 CalculateProjectionMatrix(Camera camera)

12
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);

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


using System;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;

{
var viewerCamera = Camera.current;
var c = Gizmos.color;
var m = Gizmos.matrix;
float nearClipPlane, farClipPlane, aspect, fov;
Color backgroundColor;

Matrix4x4 worldToCamera, projection;
Matrix4x4 worldToCameraRHS, projection;
out worldToCamera, out projection,
out worldToCameraRHS, out projection,
// TODO: draw frustrum gizmo
#if false
// TODO: fix frustrum drawing
var viewProj = projection * worldToCameraRHS;
var invViewProj = viewProj.inverse;
var near = new[]
{
new Vector3(-1, -1, -1),
new Vector3(-1, 1, -1),
new Vector3(1, 1, -1),
new Vector3(1, -1, -1),
};
var far = new[]
{
new Vector3(-1, -1, 1),
new Vector3(-1, 1, 1),
new Vector3(1, 1, 1),
new Vector3(1, -1, 1),
};
for (var i = 0; i < near.Length; ++i)
{
var p = invViewProj * new Vector4(near[i].x, near[i].y, near[i].z, 1);
var w = Mathf.Abs(p.w);
near[i].Set(p.x / w, p.y / w, p.z / w);
}
for (var i = 0; i < far.Length; ++i)
{
var p = invViewProj * new Vector4(far[i].x, far[i].y, far[i].z, 1);
var w = Mathf.Abs(p.w);
far[i].Set(p.x / w, p.y / w, p.z / w);
}
Gizmos.color = k_GizmoCamera;
for (var i = 0; i < 4; ++i)
{
Gizmos.DrawLine(near[i], near[(i + 1) % 4]);
Gizmos.DrawLine(far[i], far[(i + 1) % 4]);
Gizmos.DrawLine(near[i], far[i]);
}
Gizmos.matrix = m;
#endif
Gizmos.DrawSphere(capturePosition, HandleUtility.GetHandleSize(capturePosition) * 0.2f);
Gizmos.color = c;

正在加载...
取消
保存