Skip to content

Commit 4f4bcc4

Browse files
Improve compatibility of Post-Processing with VR (#23)
* Update EffectComposer.js for better compatibility with VR * Update Pass.js for better compatibility with VR
1 parent d89dbce commit 4f4bcc4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

examples/jsm/postprocessing/EffectComposer.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { CopyShader } from '../shaders/CopyShader.js';
99
import { ShaderPass } from './ShaderPass.js';
1010
import { ClearMaskPass, MaskPass } from './MaskPass.js';
1111

12+
const size = /* @__PURE__ */ new Vector2();
13+
1214
class EffectComposer {
1315

1416
constructor( renderer, renderTarget ) {
@@ -19,7 +21,7 @@ class EffectComposer {
1921

2022
if ( renderTarget === undefined ) {
2123

22-
const size = renderer.getSize( new Vector2() );
24+
renderer.getSize( size );
2325
this._width = size.width;
2426
this._height = size.height;
2527

@@ -48,6 +50,22 @@ class EffectComposer {
4850
this.copyPass.material.blending = NoBlending;
4951

5052
this.clock = new Clock();
53+
54+
this.onSessionStateChange = this.onSessionStateChange.bind( this );
55+
this.renderer.xr.addEventListener( 'sessionstart', this.onSessionStateChange );
56+
this.renderer.xr.addEventListener( 'sessionend', this.onSessionStateChange );
57+
58+
}
59+
60+
onSessionStateChange() {
61+
62+
this.renderer.getSize( size );
63+
this._width = size.width;
64+
this._height = size.height;
65+
66+
this._pixelRatio = this.renderer.xr.isPresenting ? 1 : this.renderer.getPixelRatio();
67+
68+
this.setSize( this._width, this._height );
5169

5270
}
5371

@@ -169,7 +187,7 @@ class EffectComposer {
169187

170188
if ( renderTarget === undefined ) {
171189

172-
const size = this.renderer.getSize( new Vector2() );
190+
this.renderer.getSize( size );
173191
this._pixelRatio = this.renderer.getPixelRatio();
174192
this._width = size.width;
175193
this._height = size.height;
@@ -223,6 +241,9 @@ class EffectComposer {
223241

224242
this.copyPass.dispose();
225243

244+
this.renderer.xr.removeEventListener( 'sessionstart', this.onSessionStateChange );
245+
this.renderer.xr.removeEventListener( 'sessionend', this.onSessionStateChange );
246+
226247
}
227248

228249
}

examples/jsm/postprocessing/Pass.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ class FullScreenQuad {
7474

7575
render( renderer ) {
7676

77-
renderer.render( this._mesh, _camera );
77+
// Disable XR projection for fullscreen effects
78+
// https://github.com/mrdoob/three.js/pull/18846
79+
const xrEnabled = renderer.xr.enabled;
7880

81+
renderer.xr.enabled = false;
82+
renderer.render( this._mesh, _camera );
83+
renderer.xr.enabled = xrEnabled;
7984
}
8085

8186
get material() {

0 commit comments

Comments
 (0)