R3F & StereoCamera #3219
-
Hi, 👋 I'm trying to implement the three.js StereoCamera with r3f. And it drives me nuts as it should be fairly simple, but all my attempts lead to only the right Camera getting rendered. I created a simple sandbox to showcase this (takes a bit to load): I tried using StereoCamera and StereoEffect from three, both lead to the same result. Am I missing something? Has someone encountered this before? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The reason for this is R3F will render your scene by default unless you specify a render priority to useFrame(({ gl, scene, camera, size }) => {
stereoCamera.current.update(camera);
if (gl.autoClear) gl.clear();
gl.autoClear = false;
gl.setScissorTest(true);
gl.setScissor(0, 0, size.width / 2, size.height);
gl.setViewport(0, 0, size.width / 2, size.height);
gl.render(scene, stereoCamera.current.cameraL);
gl.setScissor(size.width / 2, 0, size.width / 2, size.height);
gl.setViewport(size.width / 2, 0, size.width / 2, size.height);
gl.render(scene, stereoCamera.current.cameraR);
gl.setScissorTest(false);
gl.autoClear = true;
}, 1); |
Beta Was this translation helpful? Give feedback.
The reason for this is R3F will render your scene by default unless you specify a render priority to
useFrame
above 0, and you're leaking scissor state to that render so it can be hard to judge from a glance.