/PortalURPVR

Portal effect using UniversalRP + VR compatible

Primary LanguageC#

Portal + URP + VR

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

Demo running on Meta Quest 2:

Demo

High level description

High-level implementation

To achieve the Portal effect, a couple of ScriptableRendererFeatures were implemented with their respective ScriptableRenderPasses. A high-level implementation is described below:

  1. 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.

  2. The first process stores in a Render Texture from the Portal Camera perspective. The CopyTextureRenderFeature is in charge of performing this operation.

  3. 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):
  • 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 the ComputeScreenPos in order to achieve the Portal effect.

Resources

Thanks for the awesome resources provided by: