Currently, I am in the process of developing an innovative AR headset that utilizes stereo rendering to create lifelike 3D images. However, a challenge has arisen where the image reflected off the reflectors of the headset appears flipped or mirrored. In order to address this issue in my Three.js code, I am considering two possible solutions:
- Flipping every 3D object in the scene.
- Or flipping the camera to replicate the effect of an optically inverted (mirror image) camera.
Below, I have provided the basic structure of my code:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var geometry = new THREE.BoxGeometry();
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
const stereo = new THREE.StereoCamera();
function render() {
//stereo rendering code
camera.updateWorldMatrix();
stereo.update(camera);
const size = new THREE.Vector2();
renderer.getSize(size);
renderer.setScissorTest(true);
renderer.setScissor(0, 0, size.width / 2, size.height);
renderer.setViewport(0, 0, size.width / 2, size.height);
renderer.render(scene, stereo.cameraL);
renderer.setScissor(size.width / 2, 0, size.width / 2, size.height);
renderer.setViewport(size.width / 2, 0, size.width / 2, size.height);
renderer.render(scene, stereo.cameraR);
renderer.setScissorTest(false);
}
requestAnimationFrame(render);
I've also included a couple of images to illustrate my desired outcome: https://i.sstatic.net/oZ6x4.png
https://i.sstatic.net/x0B80.png
While it may seem straightforward to alter the cube using a matrix, the challenge arises when multiple other 3D objects are added to the scene. Ideally, I am seeking a method to flip the entire camera in order to generate a mirrored effect for the complete scene in relation to the stereo camera (if feasible).
Your assistance would be greatly appreciated. It is worth mentioning that previous attempts at manually adjusting the display settings in Windows did not achieve the intended result.