render stencil portals (stereo)
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Portal
|
||||
m_Shader: {fileID: 4800000, guid: 732968a50c15e194ba1e39cf62976ac1, type: 3}
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 1
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _LeftTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _RightTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _Texture:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _Blend: 0
|
||||
- _BlendOp: 0
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _SampleGI: 0
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _Surface: 0
|
||||
- _WorkflowMode: 1
|
||||
- _ZTest: 4
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &8905466428277890777
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 5
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 603cda73335499d4980d9b171eaffe0d
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,68 +0,0 @@
|
||||
Shader "Escape Room Engine/Portal"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_LeftTex("Left Eye Texture", 2D) = "" {}
|
||||
_RightTex("Right Eye Texture", 2D) = "" {}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
// stencil the portal surface to cut it out from the portal frame
|
||||
Stencil
|
||||
{
|
||||
Ref 1
|
||||
Pass replace
|
||||
}
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile_instancing
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionHCS : SV_POSITION;
|
||||
float4 positionScreen : TEXCOORD0;
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
uniform sampler2D _LeftTex, _RightTex;
|
||||
|
||||
Varyings vert(Attributes IN)
|
||||
{
|
||||
Varyings OUT;
|
||||
UNITY_SETUP_INSTANCE_ID(IN);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
||||
|
||||
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
|
||||
// calculate the screen position which is used to map the portal texture onto the portal
|
||||
OUT.positionScreen = ComputeScreenPos(OUT.positionHCS);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
half4 frag(Varyings IN) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
|
||||
|
||||
const float2 uv = IN.positionScreen.xy / IN.positionScreen.w;
|
||||
|
||||
// sample from the correct texture depending on the eye rendered
|
||||
return unity_StereoEyeIndex == 0 ? tex2D(_LeftTex, uv) : tex2D(_RightTex, uv);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 732968a50c15e194ba1e39cf62976ac1
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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