浏览代码

[PlanarReflection] Update capture space

/main
Frédéric Vauchelles 7 年前
当前提交
64f68c11
共有 3 个文件被更改,包括 15 次插入10 次删除
  1. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/CameraUtils.cs
  2. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
  3. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/CameraUtils.cs


return plane;
}
public static Vector4 Plane(Matrix4x4 basis, Vector3 pos, Vector3 normal, float sideSign = 1, float clipPlaneOffset = 0)
public static Vector4 CameraSpacePlane(Matrix4x4 worldToCamera, Vector3 pos, Vector3 normal, float sideSign = 1, float clipPlaneOffset = 0)
var cpos = basis.MultiplyPoint(offsetPos);
var cnormal = basis.MultiplyVector(normal).normalized * sideSign;
var cpos = worldToCamera.MultiplyPoint(offsetPos);
var cnormal = worldToCamera.MultiplyVector(normal).normalized * sideSign;
return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal));
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs


set { m_CaptureMirrorPlaneLocalNormal = value; }
}
public Vector3 captureMirrorPlaneNormal { get { return transform.TransformDirection(m_CaptureMirrorPlaneLocalNormal); } }
public Vector4 captureMirrorPlane { get { return CameraUtils.Plane(captureMirrorPlanePosition, captureMirrorPlaneNormal); } }
#region Proxy Properties
public Matrix4x4 proxyToWorld

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/ReflectionSystemInternal.cs


camera.clearFlags = viewerCamera.clearFlags;
camera.backgroundColor = viewerCamera.backgroundColor;
var plane = probe.captureMirrorPlane;
var reflectionMatrix = CalculateReflectionMatrix(plane);
camera.worldToCameraMatrix = (viewerCamera.worldToCameraMatrix * reflectionMatrix) * Matrix4x4.Scale(new Vector3(-1, 1, 1));
var clipPlane = CameraSpacePlane(camera, probe.captureMirrorPlanePosition, probe.captureMirrorPlaneNormal, 1.0f, 0);
var proj = camera.CalculateObliqueMatrix(clipPlane);
camera.projectionMatrix = proj;
var planeNormal = probe.captureMirrorPlaneNormal;
var planePosition = probe.captureMirrorPlanePosition;
var sourceProj = viewerCamera.projectionMatrix;
var planeWS = CameraUtils.Plane(planePosition, planeNormal);
var reflectionMatrix = CameraUtils.CalculateReflectionMatrix(planeWS);
var worldToCameraMatrix = (viewerCamera.worldToCameraMatrix * reflectionMatrix) * Matrix4x4.Scale(new Vector3(-1, 1, 1));
var clipPlane = CameraUtils.CameraSpacePlane(camera.worldToCameraMatrix, planePosition, planeNormal);
var proj = CameraUtils.CalculateObliqueMatrix(sourceProj, clipPlane);
var newPos = reflectionMatrix.MultiplyPoint(viewerCamera.transform.position);
camera.transform.position = newPos;

camera.transform.rotation = Quaternion.LookRotation(forward, up);
camera.projectionMatrix = proj;
camera.worldToCameraMatrix = worldToCameraMatrix;
//camera.fieldOfView = GetCaptureCameraFOVFor(probe, viewerCamera);
//camera.aspect = 1;

正在加载...
取消
保存