@@ -241,9 +241,34 @@ export class NgtpEffectComposer extends NgtRxStore implements OnInit {
241241 const enabled = this . get ( 'enabled' ) ;
242242 const autoClear = this . get ( 'autoClear' ) ;
243243 const gl = this . store . get ( 'gl' ) ;
244+ const size = this . store . get ( 'size' ) ;
245+ const camera = this . store . get ( 'camera' ) ;
244246 if ( composer && enabled ) {
245- gl . autoClear = autoClear ;
246- composer . render ( delta ) ;
247+ if ( ! gl . xr . isPresenting ) {
248+ gl . autoClear = autoClear ;
249+ composer . render ( delta ) ;
250+ return ;
251+ }
252+
253+ // manually handle XR
254+ gl . xr . enabled = false ;
255+ // update camera with XRPose
256+ gl . xr . updateCamera ( camera as THREE . PerspectiveCamera ) ;
257+
258+ // render stereo cameras
259+ const { cameras } = gl . xr . getCamera ( ) ;
260+ cameras . forEach ( ( { viewport, matrixWorld, projectionMatrix } ) => {
261+ gl . setViewport ( viewport ) ;
262+ camera . position . setFromMatrixPosition ( matrixWorld ) ;
263+ camera . projectionMatrix . copy ( projectionMatrix ) ;
264+
265+ composer . render ( delta ) ;
266+ } ) ;
267+
268+ // reset
269+ gl . setViewport ( 0 , 0 , size . width , size . height ) ;
270+ gl . xr . updateCamera ( camera as THREE . PerspectiveCamera ) ;
271+ gl . xr . enabled = true ;
247272 }
248273 } ,
249274 enabled ? renderPriority : 0
0 commit comments