I want to create a stereo portal system or a stereo mirror system with single pass rendering for performances.
However, I have some troubles stated below:
XR camera won’t directly render images to stereo render texture created by XRSettings.eyeTextureDesc.
XR camera overwrite the position and the rotation by trackings, so It’s hard to set the Camera to the mirror position.
In Stereo Pass mode, it’s unable to set custom eye projection matrices to XR Camera, so creating mirror texture needs one more pass to flip it.
It’s not easy to get correct eye separation by devices.
and so on…
I have some workaround without single pass rendering but I think they aren’t effective implements in XR.
I hope that freature supports to solve the problems are provided by Unity.
I use SetStereoViewMatrix to disable camera’s overwrites by tracking.
However, in this case, I need to calculate correct eye separation in consideration of device settings updates.
Get render results by command buffer.
renderTexture = new RenderTexture(XRSettings.eyeTextureDesc);
CommandBuffer commandBuffer = new CommandBuffer();
// effectMaterial is to flip render texture.
commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, renderTargetId, effectMaterial);
camera.AddCommandBuffer(CameraEvent.AfterEverything, commandBuffer);
This implement doesn’t prevent the camera from rendering to Screen. so it has a overhead.
Exchange left and right textures by shader for mirroring.
unity_StereoEyeIndex = 1 - i.stereoTargetEyeIndex
Exchanging textures would have some trouble. For instance, results of left texture and right texture aren’t aligned in Y axis.
When setting the same view matrix to left and right, you can see this.