Hi, I’m currently banging my head against the wall trying to setup two cameras that render to each eye independently. Using HDRP, unity 2022.3.8f1, OpenXR, XR plugin Management.Build target - Windows using the HP Reverb headset.
XR is enabled via “Initialize XR on Startup” within xr plugin management
Things I have tried:
-
Setting the render mode to multipass
-
Setting the target eye for the camera via script on start and on enable using “cam.stereoTargetEye = StereoTarget;”
-
turning off single pass Project settings>HDRP>XR
-
Attempting to use render textures to work around this issue
When I do a debug log of the variable value camera.stereoActiveEye within OnEnable it returns ‘Mono’. How do I change that? The render pass for xr mirror is still present, which continues to mirror one cameras output to both eyes regardless of everything I have tried, do I need to do a custom render pipeline to disable that pass outright?
Im not sure what im missing here. I had set via my script, each camera’s stereoTargetEye to be left and right respectively but the game view still displays whatever was the last activated camera for both eyes, in both editor and headset. Can anyone help? Ive seen others ask the same question online in various places but no one seems to get an answer. Is this functionality simply not supported anymore in the SRP’s?
If anyone comes across this post and is struggling I eventually figured out a solution, there might be a better one out there. Setting it up is a lot more convoluted then it used to be in the built in RP. This is done using single passed instanced rendering.This requires fullscreen custom passes in 2022. The idea here is to render the view of the left and right eye into render textures, then have a third camera render the results of those two cameras to the headset.
Steps to do it:
-
Create 3 cameras in your xr rig: Left eye, Right Eye, and Master.
-
Create two custom render textures, name them for left and right eye accordingly.
-
Set the Target texture field in the left and right camera’s with the corresponding render textures you made.
-
For left and right eye cam’s enable custom frame settings, then override custom pass so that its disabled.
-
For master cam enable custom frame settings and then override basically everything so that its only displaying custom pass (this is done for optimization reasons no reason to do redundant rendering work).
-
Create a new game object with a custom pass volume component.
-
In that component Set mode to Camera, assign the master camera, set injection point to be after post process.
-
Add a custom full screen pass, set target color and depth to camera, set clear flags to color, depth.
-
Create a new shader graph shader, this shader will take in two texture2d’s as input for left eye and right eye. Ensure the shader has those texture inputs set to public. Set the material to be fullscreen within the graph inspector.
-
In the shader create two sample texture 2d nodes, plug in the left eye texture input into one of these nodes, then do the same for the right.
-
Then create a branch node, plug in the rgba output from the Sample Texture2D nodes into the true and false inputs on the branch node.
-
Then create an eye index node, plug that into the predicate input.
-
Plug the output of the branch node into the base color input on the master node.
-
Create a material using this shader.
-
Assign this material into the FullScreen Material field in the custom pass volume and insure the render textures are set in the material in the inspector.
-
Ensure that XR mode is enabled on all three cameras.
-
This should now allow you to see different camera views per eye in your headset.
2 Likes