desert portal
This commit is contained in:
@@ -29,7 +29,7 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
/// <summary>
|
||||
/// The mesh where the rendered texture will be drawn on.
|
||||
/// </summary>
|
||||
[SerializeField] private MeshRenderer screen;
|
||||
[SerializeField] public MeshRenderer screen;
|
||||
|
||||
private PlayerCamera _playerCamera;
|
||||
private Camera _camera;
|
||||
@@ -47,12 +47,14 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_camera.enabled = true;
|
||||
RenderPipelineManager.beginCameraRendering += Render;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
RenderPipelineManager.beginCameraRendering -= Render;
|
||||
_camera.enabled = false;
|
||||
}
|
||||
|
||||
private void Render(ScriptableRenderContext scriptableRenderContext, Camera _)
|
||||
@@ -63,8 +65,6 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
// don't render this portal if it is not visible
|
||||
return;
|
||||
|
||||
var t = portal.transform;
|
||||
|
||||
screen.enabled = false;
|
||||
|
||||
foreach (var eye in Eyes)
|
||||
@@ -83,15 +83,16 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
}
|
||||
|
||||
// position portal camera
|
||||
var m = t.localToWorldMatrix * Portal.HalfRotation * portal.linkedPortal.transform.worldToLocalMatrix *
|
||||
var m = portal.portalTransform.localToWorldMatrix * Portal.HalfRotation *
|
||||
portal.linkedPortal.portalTransform.worldToLocalMatrix *
|
||||
_playerCamera.GetEyeTransform(eye).localToWorldMatrix;
|
||||
transform.SetPositionAndRotation(m.GetPosition(), m.rotation);
|
||||
_camera.projectionMatrix = _playerCamera.camera.GetStereoProjectionMatrix(eye);
|
||||
|
||||
// set camera clip plane to portal (otherwise the wall behind the portal would be rendered)
|
||||
// calculating the clip plane: https://computergraphics.stackexchange.com/a/1506
|
||||
var n = -t.forward; // clip plane normal
|
||||
var portalPlane = new Plane(n, t.position); // clip plane in world space
|
||||
var n = -portal.portalTransform.forward; // clip plane normal
|
||||
var portalPlane = new Plane(n, portal.portalTransform.position); // clip plane in world space
|
||||
var clipPlane = _camera.worldToCameraMatrix.inverse.transpose *
|
||||
new Vector4(n.x, n.y, n.z, portalPlane.distance); // vector format clip plane in camera space
|
||||
if (-portalPlane.GetDistanceToPoint(transform.position) >= minNearClipPlane)
|
||||
|
||||
Reference in New Issue
Block a user