Portal effect using UniversalRP (VR compatible). This project has been inspired on Coding Adventure: Portals implementation.
The Portals project was made using Built-in Render Pipeline; This project was made by using Universal RP that takes advantage of using Scriptable Render Features which allows to inject render passes into the render loop.
In the ScriptableRendererFeature, you can configure the information that requires the ScriptableRenderPass. Also, you can specify the event in which the pass will be enqueued, if this pass will be executed, and in which cameras the effect will be applied, among other actions that you can define according to your needs.
In the ScriptableRenderPass, you can perform all your graphics tasks by using command buffers.
Current support: Unity 2022.3.4f1, Universal RP 14.0.8, xr.oculus 4.0.0, and XR interaction toolkit 2.4.3
Usage of the project
- Clone the repository or download the zip to use this project locally.
- Load the project using Unity 2022.3.4f1 or superior.
- Open the Portal scene located at Assets/Scenes
- Enter to Play mode
To achieve the Portal effect, a couple of ScriptableRendererFeatures were implemented with their respective ScriptableRenderPasses. A high-level implementation is described below:
-
The Portal scene contains two cameras. Each camera has a priority, with the PortalCamera having the highest priority (0) and the MainCamera having the lowest (-1). This allows rendering first the portal scene and then the main scene.
-
The first process stores in a Render Texture from the Portal Camera perspective. The CopyTextureRenderFeature is in charge of performing this operation.
-
Then, when the GrabTextureRenderFeature is executed, it grabs the temporary render texture created in the previous step and Blit it into a Material.
Files to take into account for achieving this:
- C# file(s):
- Graphics:
- CopyTextureRenderFeature and CopyTexturePass: Classes in charge of generating a temporary VR-capable render texture.
- GrabTextureRenderFeature and GrabTexturePass: Classes in charge of retrieving and blitting the temporary render texture in a specific Quad in the scene.
- Behaviors:
- PortalController: This behavior controls the transformation of the PortalCamera to match with the position and rotation of the MainCamera.
- Graphics:
- Shader(s):
- CopyTexture: This shader is a lightweight version of the Blit.hlsl
- GrabTexture: This shader is responsible for reading a
TEXTURE2D_X
and performing theComputeScreenPos
in order to achieve the Portal effect.
Thanks for the awesome resources provided by: