From 78e39ae178f41d9fe4e398277b4f32761a8409db Mon Sep 17 00:00:00 2001 From: Enzo Francesca <99999751+enzofrancescaHM@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:41:47 +0100 Subject: [PATCH 1/2] Update EffectComposer.js for better compatibility with VR --- examples/jsm/postprocessing/EffectComposer.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/examples/jsm/postprocessing/EffectComposer.js b/examples/jsm/postprocessing/EffectComposer.js index b814654202e9be..c861a56660b058 100644 --- a/examples/jsm/postprocessing/EffectComposer.js +++ b/examples/jsm/postprocessing/EffectComposer.js @@ -9,6 +9,8 @@ import { CopyShader } from '../shaders/CopyShader.js'; import { ShaderPass } from './ShaderPass.js'; import { ClearMaskPass, MaskPass } from './MaskPass.js'; +const size = /* @__PURE__ */ new Vector2(); + class EffectComposer { constructor( renderer, renderTarget ) { @@ -19,7 +21,7 @@ class EffectComposer { if ( renderTarget === undefined ) { - const size = renderer.getSize( new Vector2() ); + renderer.getSize( size ); this._width = size.width; this._height = size.height; @@ -48,6 +50,22 @@ class EffectComposer { this.copyPass.material.blending = NoBlending; this.clock = new Clock(); + + this.onSessionStateChange = this.onSessionStateChange.bind( this ); + this.renderer.xr.addEventListener( 'sessionstart', this.onSessionStateChange ); + this.renderer.xr.addEventListener( 'sessionend', this.onSessionStateChange ); + + } + + onSessionStateChange() { + + this.renderer.getSize( size ); + this._width = size.width; + this._height = size.height; + + this._pixelRatio = this.renderer.xr.isPresenting ? 1 : this.renderer.getPixelRatio(); + + this.setSize( this._width, this._height ); } @@ -169,7 +187,7 @@ class EffectComposer { if ( renderTarget === undefined ) { - const size = this.renderer.getSize( new Vector2() ); + this.renderer.getSize( size ); this._pixelRatio = this.renderer.getPixelRatio(); this._width = size.width; this._height = size.height; @@ -223,6 +241,9 @@ class EffectComposer { this.copyPass.dispose(); + this.renderer.xr.removeEventListener( 'sessionstart', this.onSessionStateChange ); + this.renderer.xr.removeEventListener( 'sessionend', this.onSessionStateChange ); + } } From f10e2e4a5ff046a0deaa9ca10fc02804d1252aeb Mon Sep 17 00:00:00 2001 From: Enzo Francesca <99999751+enzofrancescaHM@users.noreply.github.com> Date: Sat, 1 Feb 2025 16:43:20 +0100 Subject: [PATCH 2/2] Update Pass.js for better compatibility with VR --- examples/jsm/postprocessing/Pass.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/jsm/postprocessing/Pass.js b/examples/jsm/postprocessing/Pass.js index a81582d13de21a..111f8031cb878f 100644 --- a/examples/jsm/postprocessing/Pass.js +++ b/examples/jsm/postprocessing/Pass.js @@ -74,8 +74,13 @@ class FullScreenQuad { render( renderer ) { - renderer.render( this._mesh, _camera ); + // Disable XR projection for fullscreen effects + // https://github.com/mrdoob/three.js/pull/18846 + const xrEnabled = renderer.xr.enabled; + renderer.xr.enabled = false; + renderer.render( this._mesh, _camera ); + renderer.xr.enabled = xrEnabled; } get material() {