render stencil portals (stereo)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:fe685ec1767f73d42b749ea8045bfe43",
|
||||
"GUID:776d03a35f1b52c4a9aed9f56d7b4229",
|
||||
"GUID:8804073475ba36c47830e8e19dc699ce",
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using EscapeRoomEngine.VR.Runtime;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -87,12 +88,28 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
public Camera SetUpCamera(Camera playerCamera)
|
||||
public Camera SetUpCamera(Camera playerCamera, Camera.MonoOrStereoscopicEye monoOrEye)
|
||||
{
|
||||
// place camera
|
||||
var m = portalTransform.localToWorldMatrix * HalfRotation *
|
||||
linkedPortal.portalTransform.worldToLocalMatrix * playerCamera.transform.localToWorldMatrix;
|
||||
playerCamera.transform.SetPositionAndRotation(m.GetPosition(), m.rotation);
|
||||
Matrix4x4 cameraTransform;
|
||||
if (monoOrEye == Camera.MonoOrStereoscopicEye.Mono)
|
||||
{
|
||||
cameraTransform = portalTransform.localToWorldMatrix * HalfRotation *
|
||||
linkedPortal.portalTransform.worldToLocalMatrix *
|
||||
playerCamera.transform.localToWorldMatrix;
|
||||
}
|
||||
else
|
||||
{
|
||||
// stereoRenderCounter = (stereoRenderCounter + 1) % 2;
|
||||
var eye = monoOrEye == Camera.MonoOrStereoscopicEye.Left
|
||||
? Camera.StereoscopicEye.Left
|
||||
: Camera.StereoscopicEye.Right;
|
||||
cameraTransform = portalTransform.localToWorldMatrix * HalfRotation *
|
||||
linkedPortal.portalTransform.worldToLocalMatrix *
|
||||
Player.Instance.GetEye(eye).localToWorldMatrix;
|
||||
playerCamera.projectionMatrix = playerCamera.GetStereoProjectionMatrix(eye);
|
||||
}
|
||||
playerCamera.transform.SetPositionAndRotation(cameraTransform.GetPosition(), cameraTransform.rotation);
|
||||
|
||||
// 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
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
|
||||
private class PortalCameraRenderPass : ScriptableRenderPass
|
||||
{
|
||||
private static readonly List<ShaderTagId> ShaderTagIds = new List<ShaderTagId>
|
||||
private static readonly List<ShaderTagId> ShaderTagIds = new()
|
||||
{
|
||||
new("SRPDefaultUnlit"), new("UniversalForward"), new("UniversalForwardOnly")
|
||||
new ShaderTagId("SRPDefaultUnlit"), new ShaderTagId("UniversalForward"), new ShaderTagId("UniversalForwardOnly")
|
||||
};
|
||||
|
||||
private RenderStateBlock _renderStateBlock;
|
||||
@@ -74,8 +74,15 @@ namespace EscapeRoomEngine.Portal.Runtime
|
||||
var originalPosition = cameraTransform.position;
|
||||
var originalRotation = cameraTransform.rotation;
|
||||
var originalProjection = camera.projectionMatrix;
|
||||
camera = linkedPortal.SetUpCamera(camera);
|
||||
RenderingUtils.SetViewAndProjectionMatrices(_commandBuffer, camera.worldToCameraMatrix, GL.GetGPUProjectionMatrix(camera.projectionMatrix, true), false);
|
||||
camera = linkedPortal.SetUpCamera(camera,
|
||||
camera.stereoEnabled
|
||||
? cameraData.xr.multipassId == 0
|
||||
? Camera.MonoOrStereoscopicEye.Left
|
||||
: Camera.MonoOrStereoscopicEye.Right
|
||||
: Camera.MonoOrStereoscopicEye.Mono);
|
||||
RenderingUtils.SetViewAndProjectionMatrices(_commandBuffer,
|
||||
camera.worldToCameraMatrix,
|
||||
GL.GetGPUProjectionMatrix(camera.projectionMatrix, true), false);
|
||||
|
||||
// execute command buffer
|
||||
context.ExecuteCommandBuffer(_commandBuffer);
|
||||
|
||||
Reference in New Issue
Block a user