NEWS : This subject is under an unity issue. Please vote here if you also want portals systems in VR Unity Issue Tracker - [Shadergraph] ScreenPosition node does not work when XR is active
Hello there !
I’ve made the project free to access here : Sheyne / HDRPPortalVR · GitLab
So the main goal is to have a working HDRP VR portal (And potentially URP later), since I havn’t found any on the asset store nor on the internet.
I managed to get a working HDRP portal system.
I’ve been using this youtube video :
Sebastian Lague do share it’s portal project with us on github : GitHub - SebLague/Portals: Portals in Unity
So basically I used shadergraph with the Unlit node and I converted the shader he’s using to have his code working with HDRP. I also had to put his render function for the portals in a LateUpdate loop, since the OnPreCull event was removed from HDRP as seen here : [https://forum.unity.com/threads/fee...e-render-pipelines.470095/page-8#post-3408481]( Feedback Wanted: Scriptable Render Pipelines page-8#post-3408481)
The Shader in shadergraph is very simple. I just connected the screen position as UV and declared a texture2D as an entry for the texture sampled.
A camera for each portal follow the player camera location and the render will be captured on renders textures to apply them on the portals materials, using the shader above.
As it can be seen, in this video : Screen capture - 338782343c0992fc2fcbbf2cb9c1975c - Gyazo the cameras follow the player location.
I also had to remove the post processing from this cameras because it stacked with the player post processing camera and ended up showing different results on the portal.
Then, our portal.cs script apply at runtime a texture2D from the camera attached to the portal to the portal screen material. It’s done here : https://hastebin.com/qewevarati.csharp in the void render() function. This function is called as I said above in late update, as the last script in the script execution order.
The script also do other things like taking care of cutting the mesh when traveling the portal but it doesn’t matter for now.
Here is the result : a portal properly working in HDRP Screen capture - 8ad09a3aec9d4762d678017c508954e4 - Gyazo
Now the problem is : Whenever I try to plug my VR headset on (Oculus CV1), everything turn wrong. The result can be seen here : Screen capture - 79ce55f67240dd13056e33b66b95a25d - Gyazo
It seem to put both player eyes on the screen as a render texture at the same time.
I’d like to be able to apply the left eye of the render camera on the left eye render of the portal and the right eye of the render camera on the right eye render of the portal.
I do not really know where to start, and if it require to change the shader in shader graph if there is even a way to do it. Since we are on HDRP we cannot really handwrite the shaders.
Thanks if you have any start of answers !