super-three 0.157.0 → 0.157.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/three.js CHANGED
@@ -14754,7 +14754,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
14754
14754
  if ( boxMesh === undefined ) {
14755
14755
 
14756
14756
  boxMesh = new Mesh(
14757
- new BoxGeometry( 1, 1, 1 ),
14757
+ new BoxGeometry( 10000, 10000, 10000 ),
14758
14758
  new ShaderMaterial( {
14759
14759
  name: 'BackgroundCubeMaterial',
14760
14760
  uniforms: cloneUniforms( ShaderLib.backgroundCube.uniforms ),
@@ -17850,6 +17850,103 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
17850
17850
 
17851
17851
  }
17852
17852
 
17853
+ /**
17854
+ * @author fernandojsg / http://fernandojsg.com
17855
+ * @author Takahiro https://github.com/takahirox
17856
+ */
17857
+
17858
+ class WebGLMultiview {
17859
+
17860
+ constructor( renderer, extensions, gl ) {
17861
+
17862
+ this.renderer = renderer;
17863
+
17864
+ this.DEFAULT_NUMVIEWS = 2;
17865
+ this.maxNumViews = 0;
17866
+ this.gl = gl;
17867
+
17868
+ this.extensions = extensions;
17869
+
17870
+ this.available = this.extensions.has( 'OCULUS_multiview' );
17871
+
17872
+ if ( this.available ) {
17873
+
17874
+ const extension = this.extensions.get( 'OCULUS_multiview' );
17875
+
17876
+ this.maxNumViews = this.gl.getParameter( extension.MAX_VIEWS_OVR );
17877
+
17878
+ this.mat4 = [];
17879
+ this.mat3 = [];
17880
+ this.cameraArray = [];
17881
+
17882
+ for ( var i = 0; i < this.maxNumViews; i ++ ) {
17883
+
17884
+ this.mat4[ i ] = new Matrix4();
17885
+ this.mat3[ i ] = new Matrix3();
17886
+
17887
+ }
17888
+
17889
+ }
17890
+
17891
+ }
17892
+
17893
+ //
17894
+ getCameraArray( camera ) {
17895
+
17896
+ if ( camera.isArrayCamera ) return camera.cameras;
17897
+
17898
+ this.cameraArray[ 0 ] = camera;
17899
+
17900
+ return this.cameraArray;
17901
+
17902
+ }
17903
+
17904
+ updateCameraProjectionMatricesUniform( camera, uniforms ) {
17905
+
17906
+ var cameras = this.getCameraArray( camera );
17907
+
17908
+ for ( var i = 0; i < cameras.length; i ++ ) {
17909
+
17910
+ this.mat4[ i ].copy( cameras[ i ].projectionMatrix );
17911
+
17912
+ }
17913
+
17914
+ uniforms.setValue( this.gl, 'projectionMatrices', this.mat4 );
17915
+
17916
+ }
17917
+
17918
+ updateCameraViewMatricesUniform( camera, uniforms ) {
17919
+
17920
+ var cameras = this.getCameraArray( camera );
17921
+
17922
+ for ( var i = 0; i < cameras.length; i ++ ) {
17923
+
17924
+ this.mat4[ i ].copy( cameras[ i ].matrixWorldInverse );
17925
+
17926
+ }
17927
+
17928
+ uniforms.setValue( this.gl, 'viewMatrices', this.mat4 );
17929
+
17930
+ }
17931
+
17932
+ updateObjectMatricesUniforms( object, camera, uniforms ) {
17933
+
17934
+ var cameras = this.getCameraArray( camera );
17935
+
17936
+ for ( var i = 0; i < cameras.length; i ++ ) {
17937
+
17938
+ this.mat4[ i ].multiplyMatrices( cameras[ i ].matrixWorldInverse, object.matrixWorld );
17939
+ this.mat3[ i ].getNormalMatrix( this.mat4[ i ] );
17940
+
17941
+ }
17942
+
17943
+ uniforms.setValue( this.gl, 'modelViewMatrices', this.mat4 );
17944
+ uniforms.setValue( this.gl, 'normalMatrices', this.mat3 );
17945
+
17946
+ }
17947
+
17948
+ }
17949
+
17853
17950
  function WebGLObjects( gl, geometries, attributes, info ) {
17854
17951
 
17855
17952
  let updateMap = new WeakMap();
@@ -19543,6 +19640,8 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
19543
19640
  let prefixVertex, prefixFragment;
19544
19641
  let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
19545
19642
 
19643
+ const numMultiviewViews = parameters.numMultiviewViews;
19644
+
19546
19645
  if ( parameters.isRawShaderMaterial ) {
19547
19646
 
19548
19647
  prefixVertex = [
@@ -19949,6 +20048,53 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
19949
20048
  '#define textureCubeGradEXT textureGrad'
19950
20049
  ].join( '\n' ) + '\n' + prefixFragment;
19951
20050
 
20051
+ // Multiview
20052
+
20053
+ if ( numMultiviewViews > 0 ) {
20054
+
20055
+ // TODO: fix light transforms here?
20056
+
20057
+ prefixVertex = [
20058
+ '#extension GL_OVR_multiview : require',
20059
+ 'layout(num_views = ' + numMultiviewViews + ') in;',
20060
+ '#define VIEW_ID gl_ViewID_OVR'
20061
+ ].join( '\n' ) + '\n' + prefixVertex;
20062
+
20063
+ prefixVertex = prefixVertex.replace(
20064
+ [
20065
+ 'uniform mat4 modelViewMatrix;',
20066
+ 'uniform mat4 projectionMatrix;',
20067
+ 'uniform mat4 viewMatrix;',
20068
+ 'uniform mat3 normalMatrix;'
20069
+ ].join( '\n' ),
20070
+ [
20071
+ 'uniform mat4 modelViewMatrices[' + numMultiviewViews + '];',
20072
+ 'uniform mat4 projectionMatrices[' + numMultiviewViews + '];',
20073
+ 'uniform mat4 viewMatrices[' + numMultiviewViews + '];',
20074
+ 'uniform mat3 normalMatrices[' + numMultiviewViews + '];',
20075
+
20076
+ '#define modelViewMatrix modelViewMatrices[VIEW_ID]',
20077
+ '#define projectionMatrix projectionMatrices[VIEW_ID]',
20078
+ '#define viewMatrix viewMatrices[VIEW_ID]',
20079
+ '#define normalMatrix normalMatrices[VIEW_ID]'
20080
+ ].join( '\n' )
20081
+ );
20082
+
20083
+ prefixFragment = [
20084
+ '#extension GL_OVR_multiview : require',
20085
+ '#define VIEW_ID gl_ViewID_OVR'
20086
+ ].join( '\n' ) + '\n' + prefixFragment;
20087
+
20088
+ prefixFragment = prefixFragment.replace(
20089
+ 'uniform mat4 viewMatrix;',
20090
+ [
20091
+ 'uniform mat4 viewMatrices[' + numMultiviewViews + '];',
20092
+ '#define viewMatrix viewMatrices[VIEW_ID]'
20093
+ ].join( '\n' )
20094
+ );
20095
+
20096
+ }
20097
+
19952
20098
  }
19953
20099
 
19954
20100
  const vertexGlsl = versionString + prefixVertex + vertexShader;
@@ -20113,6 +20259,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
20113
20259
  this.program = program;
20114
20260
  this.vertexShader = glVertexShader;
20115
20261
  this.fragmentShader = glFragmentShader;
20262
+ this.numMultiviewViews = numMultiviewViews;
20116
20263
 
20117
20264
  return this;
20118
20265
 
@@ -20342,6 +20489,8 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
20342
20489
 
20343
20490
  const currentRenderTarget = renderer.getRenderTarget();
20344
20491
 
20492
+ const numMultiviewViews = currentRenderTarget && currentRenderTarget.isWebGLMultiviewRenderTarget ? currentRenderTarget.numViews : 0;
20493
+
20345
20494
  const IS_INSTANCEDMESH = object.isInstancedMesh === true;
20346
20495
 
20347
20496
  const HAS_MAP = !! material.map;
@@ -20432,6 +20581,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
20432
20581
  instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
20433
20582
 
20434
20583
  supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES,
20584
+ numMultiviewViews: numMultiviewViews,
20435
20585
  outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace ),
20436
20586
 
20437
20587
  map: HAS_MAP,
@@ -20779,6 +20929,8 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
20779
20929
  _programLayers.enable( 18 );
20780
20930
  if ( parameters.decodeVideoTexture )
20781
20931
  _programLayers.enable( 19 );
20932
+ if ( parameters.numMultiviewViews )
20933
+ _programLayers.enable( 20 );
20782
20934
 
20783
20935
  array.push( _programLayers.mask );
20784
20936
 
@@ -23614,12 +23766,16 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
23614
23766
  const maxSamples = capabilities.maxSamples;
23615
23767
  const multisampledRTTExt = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null;
23616
23768
  const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent );
23769
+ const multiviewExt = extensions.has( 'OCULUS_multiview' ) ? extensions.get( 'OCULUS_multiview' ) : null;
23617
23770
 
23618
23771
  const _videoTextures = new WeakMap();
23619
23772
  let _canvas;
23620
23773
 
23621
23774
  const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source
23622
23775
 
23776
+ let _deferredUploads = [];
23777
+ let _deferTextureUploads = false;
23778
+
23623
23779
  // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
23624
23780
  // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
23625
23781
  // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
@@ -24087,8 +24243,11 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
24087
24243
 
24088
24244
  } else {
24089
24245
 
24090
- uploadTexture( textureProperties, texture, slot );
24091
- return;
24246
+ if ( uploadTexture( textureProperties, texture, slot ) ) {
24247
+
24248
+ return;
24249
+
24250
+ }
24092
24251
 
24093
24252
  }
24094
24253
 
@@ -24321,8 +24480,45 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
24321
24480
 
24322
24481
  }
24323
24482
 
24483
+ function setDeferTextureUploads( deferFlag ) {
24484
+
24485
+ _deferTextureUploads = deferFlag;
24486
+
24487
+ }
24488
+
24489
+ function runDeferredUploads() {
24490
+
24491
+ const previousDeferSetting = _deferTextureUploads;
24492
+ _deferTextureUploads = false;
24493
+
24494
+ for ( const upload of _deferredUploads ) {
24495
+
24496
+ uploadTexture( upload.textureProperties, upload.texture, upload.slot );
24497
+ upload.texture.isPendingDeferredUpload = false;
24498
+
24499
+ }
24500
+
24501
+ _deferredUploads = [];
24502
+
24503
+ _deferTextureUploads = previousDeferSetting;
24504
+
24505
+ }
24506
+
24324
24507
  function uploadTexture( textureProperties, texture, slot ) {
24325
24508
 
24509
+ if ( _deferTextureUploads ) {
24510
+
24511
+ if ( ! texture.isPendingDeferredUpload ) {
24512
+
24513
+ texture.isPendingDeferredUpload = true;
24514
+ _deferredUploads.push( { textureProperties: textureProperties, texture: texture, slot: slot } );
24515
+
24516
+ }
24517
+
24518
+ return false;
24519
+
24520
+ }
24521
+
24326
24522
  let textureType = _gl.TEXTURE_2D;
24327
24523
 
24328
24524
  if ( texture.isDataArrayTexture || texture.isCompressedArrayTexture ) textureType = _gl.TEXTURE_2D_ARRAY;
@@ -24739,6 +24935,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
24739
24935
  }
24740
24936
 
24741
24937
  textureProperties.__version = texture.version;
24938
+ return true;
24742
24939
 
24743
24940
  }
24744
24941
 
@@ -24968,7 +25165,11 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
24968
25165
  const width = Math.max( 1, renderTarget.width >> level );
24969
25166
  const height = Math.max( 1, renderTarget.height >> level );
24970
25167
 
24971
- if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) {
25168
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
25169
+
25170
+ state.texStorage3D( _gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.numViews );
25171
+
25172
+ } else if ( textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY ) {
24972
25173
 
24973
25174
  state.texImage3D( textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null );
24974
25175
 
@@ -24982,13 +25183,31 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
24982
25183
 
24983
25184
  state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
24984
25185
 
24985
- if ( useMultisampledRTT( renderTarget ) ) {
25186
+ const multisampled = useMultisampledRTT( renderTarget );
25187
+
25188
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
25189
+
25190
+ if ( multisampled ) {
25191
+
25192
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
25193
+
25194
+ } else {
25195
+
25196
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, 0, renderTarget.numViews );
24986
25197
 
24987
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
25198
+ }
24988
25199
 
24989
25200
  } else if ( textureTarget === _gl.TEXTURE_2D || ( textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z ) ) { // see #24753
24990
25201
 
24991
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
25202
+ if ( multisampled ) {
25203
+
25204
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
25205
+
25206
+ } else {
25207
+
25208
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
25209
+
25210
+ }
24992
25211
 
24993
25212
  }
24994
25213
 
@@ -25002,7 +25221,59 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
25002
25221
 
25003
25222
  _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
25004
25223
 
25005
- if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
25224
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
25225
+
25226
+ const useMultisample = useMultisampledRTT( renderTarget );
25227
+ const numViews = renderTarget.numViews;
25228
+
25229
+ const depthTexture = renderTarget.depthTexture;
25230
+ let glInternalFormat = _gl.DEPTH_COMPONENT24;
25231
+ let glDepthAttachment = _gl.DEPTH_ATTACHMENT;
25232
+
25233
+ if ( depthTexture && depthTexture.isDepthTexture ) {
25234
+
25235
+ if ( depthTexture.type === FloatType ) {
25236
+
25237
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
25238
+
25239
+ } else if ( depthTexture.type === UnsignedInt248Type ) {
25240
+
25241
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
25242
+ glDepthAttachment = _gl.DEPTH_STENCIL_ATTACHMENT;
25243
+
25244
+ }
25245
+
25246
+ // we're defaulting to _gl.DEPTH_COMPONENT24 so don't assign here
25247
+ // or else DeepScan will complain
25248
+
25249
+ // else if ( depthTexture.type === UnsignedIntType ) {
25250
+
25251
+ // glInternalFormat = _gl.DEPTH_COMPONENT24;
25252
+
25253
+ // }
25254
+
25255
+ }
25256
+
25257
+ let depthStencilTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
25258
+ if ( depthStencilTexture === undefined ) {
25259
+
25260
+ depthStencilTexture = _gl.createTexture();
25261
+ _gl.bindTexture( _gl.TEXTURE_2D_ARRAY, depthStencilTexture );
25262
+ _gl.texStorage3D( _gl.TEXTURE_2D_ARRAY, 1, glInternalFormat, renderTarget.width, renderTarget.height, numViews );
25263
+
25264
+ }
25265
+
25266
+ if ( useMultisample ) {
25267
+
25268
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, getRenderTargetSamples( renderTarget ), 0, numViews );
25269
+
25270
+ } else {
25271
+
25272
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, glDepthAttachment, depthStencilTexture, 0, 0, numViews );
25273
+
25274
+ }
25275
+
25276
+ } else if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
25006
25277
 
25007
25278
  let glInternalFormat = ( isWebGL2 === true ) ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16;
25008
25279
 
@@ -25126,37 +25397,85 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
25126
25397
  }
25127
25398
 
25128
25399
  setTexture2D( renderTarget.depthTexture, 0 );
25400
+ if ( renderTarget.depthTexture.image.depth != 1 ) {
25401
+
25402
+ setTexture2DArray( renderTarget.depthTexture, 0 );
25403
+
25404
+ } else {
25405
+
25406
+ setTexture2D( renderTarget.depthTexture, 0 );
25407
+
25408
+ }
25129
25409
 
25130
25410
  const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
25131
25411
  const samples = getRenderTargetSamples( renderTarget );
25132
25412
 
25133
- if ( renderTarget.depthTexture.format === DepthFormat ) {
25413
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
25134
25414
 
25135
- if ( useMultisampledRTT( renderTarget ) ) {
25415
+ const useMultisample = useMultisampledRTT( renderTarget );
25416
+ const numViews = renderTarget.numViews;
25136
25417
 
25137
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
25418
+ if ( renderTarget.depthTexture.format === DepthFormat ) {
25138
25419
 
25139
- } else {
25420
+ if ( useMultisample ) {
25140
25421
 
25141
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
25422
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews );
25142
25423
 
25143
- }
25424
+ } else {
25144
25425
 
25145
- } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
25426
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, webglDepthTexture, 0, 0, numViews );
25427
+
25428
+ }
25146
25429
 
25147
- if ( useMultisampledRTT( renderTarget ) ) {
25430
+ } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
25148
25431
 
25149
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
25432
+ if ( useMultisample ) {
25433
+
25434
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, samples, 0, numViews );
25435
+
25436
+ } else {
25437
+
25438
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, webglDepthTexture, 0, 0, numViews );
25439
+
25440
+ }
25150
25441
 
25151
25442
  } else {
25152
25443
 
25153
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
25444
+ throw new Error( 'Unknown depthTexture format' );
25154
25445
 
25155
25446
  }
25156
25447
 
25157
25448
  } else {
25158
25449
 
25159
- throw new Error( 'Unknown depthTexture format' );
25450
+ if ( renderTarget.depthTexture.format === DepthFormat ) {
25451
+
25452
+ if ( useMultisampledRTT( renderTarget ) ) {
25453
+
25454
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
25455
+
25456
+ } else {
25457
+
25458
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
25459
+
25460
+ }
25461
+
25462
+ } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
25463
+
25464
+ if ( useMultisampledRTT( renderTarget ) ) {
25465
+
25466
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
25467
+
25468
+ } else {
25469
+
25470
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
25471
+
25472
+ }
25473
+
25474
+ } else {
25475
+
25476
+ throw new Error( 'Unknown depthTexture format' );
25477
+
25478
+ }
25160
25479
 
25161
25480
  }
25162
25481
 
@@ -25435,6 +25754,12 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
25435
25754
 
25436
25755
  }
25437
25756
 
25757
+ if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
25758
+
25759
+ glTextureType = _gl.TEXTURE_2D_ARRAY;
25760
+
25761
+ }
25762
+
25438
25763
  state.bindTexture( glTextureType, textureProperties.__webglTexture );
25439
25764
  setTextureParameters( glTextureType, texture, supportsMips );
25440
25765
 
@@ -25464,9 +25789,9 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
25464
25789
 
25465
25790
  // Setup depth and stencil buffers
25466
25791
 
25467
- if ( renderTarget.depthBuffer ) {
25792
+ if ( renderTarget.depthBuffer || renderTarget.isWebGLMultiviewRenderTarget === true ) {
25468
25793
 
25469
- setupDepthRenderbuffer( renderTarget );
25794
+ this.setupDepthRenderbuffer( renderTarget );
25470
25795
 
25471
25796
  }
25472
25797
 
@@ -25702,12 +26027,16 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
25702
26027
  this.setTexture3D = setTexture3D;
25703
26028
  this.setTextureCube = setTextureCube;
25704
26029
  this.rebindTextures = rebindTextures;
26030
+ this.uploadTexture = uploadTexture;
25705
26031
  this.setupRenderTarget = setupRenderTarget;
25706
26032
  this.updateRenderTargetMipmap = updateRenderTargetMipmap;
25707
26033
  this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
26034
+ this.setupDepthTexture = setupDepthTexture;
25708
26035
  this.setupDepthRenderbuffer = setupDepthRenderbuffer;
25709
26036
  this.setupFrameBufferTexture = setupFrameBufferTexture;
25710
26037
  this.useMultisampledRTT = useMultisampledRTT;
26038
+ this.runDeferredUploads = runDeferredUploads;
26039
+ this.setDeferTextureUploads = setDeferTextureUploads;
25711
26040
 
25712
26041
  }
25713
26042
 
@@ -26564,6 +26893,39 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
26564
26893
  dispatchEvent: EventDispatcher.prototype.dispatchEvent
26565
26894
  } );
26566
26895
 
26896
+ /**
26897
+ * @author fernandojsg / http://fernandojsg.com
26898
+ * @author Takahiro https://github.com/takahirox
26899
+ */
26900
+
26901
+
26902
+ class WebGLMultiviewRenderTarget extends WebGLRenderTarget {
26903
+
26904
+ constructor( width, height, numViews, options = {} ) {
26905
+
26906
+ super( width, height, options );
26907
+
26908
+ this.depthBuffer = false;
26909
+ this.stencilBuffer = false;
26910
+
26911
+ this.numViews = numViews;
26912
+
26913
+ }
26914
+
26915
+ copy( source ) {
26916
+
26917
+ super.copy( source );
26918
+
26919
+ this.numViews = source.numViews;
26920
+
26921
+ return this;
26922
+
26923
+ }
26924
+
26925
+ }
26926
+
26927
+ WebGLMultiviewRenderTarget.prototype.isWebGLMultiviewRenderTarget = true;
26928
+
26567
26929
  const _moveEvent = { type: 'move' };
26568
26930
 
26569
26931
  class WebXRController {
@@ -26958,7 +27320,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
26958
27320
 
26959
27321
  class WebXRManager extends EventDispatcher {
26960
27322
 
26961
- constructor( renderer, gl ) {
27323
+ constructor( renderer, gl, extensions, useMultiview ) {
26962
27324
 
26963
27325
  super();
26964
27326
 
@@ -27014,6 +27376,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
27014
27376
  this.enabled = false;
27015
27377
 
27016
27378
  this.isPresenting = false;
27379
+ this.isMultiview = false;
27017
27380
 
27018
27381
  this.getCameraPose = function ( ) {
27019
27382
 
@@ -27257,29 +27620,51 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
27257
27620
 
27258
27621
  }
27259
27622
 
27623
+ scope.isMultiview = useMultiview && extensions.has( 'OCULUS_multiview' );
27624
+
27260
27625
  const projectionlayerInit = {
27261
27626
  colorFormat: gl.RGBA8,
27262
27627
  depthFormat: glDepthFormat,
27263
27628
  scaleFactor: framebufferScaleFactor
27264
27629
  };
27265
27630
 
27631
+ if ( scope.isMultiview ) {
27632
+
27633
+ projectionlayerInit.textureType = 'texture-array';
27634
+
27635
+ }
27636
+
27266
27637
  glBinding = new XRWebGLBinding( session, gl );
27267
27638
 
27268
27639
  glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
27269
27640
 
27270
27641
  session.updateRenderState( { layers: [ glProjLayer ] } );
27271
27642
 
27272
- newRenderTarget = new WebGLRenderTarget(
27273
- glProjLayer.textureWidth,
27274
- glProjLayer.textureHeight,
27275
- {
27276
- format: RGBAFormat,
27277
- type: UnsignedByteType,
27278
- depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
27279
- stencilBuffer: attributes.stencil,
27280
- colorSpace: renderer.outputColorSpace,
27281
- samples: attributes.antialias ? 4 : 0
27282
- } );
27643
+ const renderTargetOptions = {
27644
+ format: RGBAFormat,
27645
+ type: UnsignedByteType,
27646
+ depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ),
27647
+ stencilBuffer: attributes.stencil,
27648
+ colorSpace: renderer.outputColorSpace,
27649
+ samples: attributes.antialias ? 4 : 0
27650
+ };
27651
+
27652
+ if ( scope.isMultiview ) {
27653
+
27654
+ const extension = extensions.get( 'OCULUS_multiview' );
27655
+
27656
+ this.maxNumViews = gl.getParameter( extension.MAX_VIEWS_OVR );
27657
+
27658
+ newRenderTarget = new WebGLMultiviewRenderTarget( glProjLayer.textureWidth, glProjLayer.textureHeight, 2, renderTargetOptions );
27659
+
27660
+ } else {
27661
+
27662
+ newRenderTarget = new WebGLRenderTarget(
27663
+ glProjLayer.textureWidth,
27664
+ glProjLayer.textureHeight,
27665
+ renderTargetOptions );
27666
+
27667
+ }
27283
27668
 
27284
27669
  const renderTargetProperties = renderer.properties.get( newRenderTarget );
27285
27670
  renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues;
@@ -28731,6 +29116,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
28731
29116
  preserveDrawingBuffer = false,
28732
29117
  powerPreference = 'default',
28733
29118
  failIfMajorPerformanceCaveat = false,
29119
+ multiviewStereo = false,
28734
29120
  } = parameters;
28735
29121
 
28736
29122
  this.isWebGLRenderer = true;
@@ -28965,6 +29351,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
28965
29351
  let extensions, capabilities, state, info;
28966
29352
  let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
28967
29353
  let programCache, materials, renderLists, renderStates, clipping, shadowMap;
29354
+ let multiview;
28968
29355
 
28969
29356
  let background, morphtargets, bufferRenderer, indexedBufferRenderer;
28970
29357
 
@@ -28998,6 +29385,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
28998
29385
  renderLists = new WebGLRenderLists();
28999
29386
  renderStates = new WebGLRenderStates( extensions, capabilities );
29000
29387
  background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha );
29388
+ multiview = new WebGLMultiview( _this, extensions, _gl );
29001
29389
  shadowMap = new WebGLShadowMap( _this, objects, capabilities );
29002
29390
  uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );
29003
29391
 
@@ -29020,7 +29408,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
29020
29408
 
29021
29409
  // xr
29022
29410
 
29023
- const xr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
29411
+ const xr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this, _gl, extensions, multiviewStereo ) : new WebVRManager( _this );
29024
29412
 
29025
29413
  this.xr = xr;
29026
29414
 
@@ -29767,13 +30155,23 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
29767
30155
 
29768
30156
  if ( camera.isArrayCamera ) {
29769
30157
 
29770
- const cameras = camera.cameras;
30158
+ if ( xr.enabled && xr.isMultiview ) {
30159
+
30160
+ textures.setDeferTextureUploads( true );
30161
+
30162
+ renderScene( currentRenderList, scene, camera, camera.cameras[ 0 ].viewport );
29771
30163
 
29772
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
30164
+ } else {
30165
+
30166
+ const cameras = camera.cameras;
29773
30167
 
29774
- const camera2 = cameras[ i ];
30168
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
29775
30169
 
29776
- renderScene( currentRenderList, scene, camera2, camera2.viewport );
30170
+ const camera2 = cameras[ i ];
30171
+
30172
+ renderScene( currentRenderList, scene, camera2, camera2.viewport );
30173
+
30174
+ }
29777
30175
 
29778
30176
  }
29779
30177
 
@@ -29801,6 +30199,8 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
29801
30199
 
29802
30200
  if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
29803
30201
 
30202
+ textures.runDeferredUploads();
30203
+
29804
30204
  if ( xr.enabled && xr.submitFrame ) {
29805
30205
 
29806
30206
  xr.submitFrame();
@@ -30268,6 +30668,7 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30268
30668
  materialProperties.vertexAlphas = parameters.vertexAlphas;
30269
30669
  materialProperties.vertexTangents = parameters.vertexTangents;
30270
30670
  materialProperties.toneMapping = parameters.toneMapping;
30671
+ materialProperties.numMultiviewViews = parameters.numMultiviewViews;
30271
30672
 
30272
30673
  }
30273
30674
 
@@ -30299,6 +30700,8 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30299
30700
 
30300
30701
  }
30301
30702
 
30703
+ const numMultiviewViews = _currentRenderTarget && _currentRenderTarget.isWebGLMultiviewRenderTarget ? _currentRenderTarget.numViews : 0;
30704
+
30302
30705
  const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
30303
30706
  const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;
30304
30707
 
@@ -30402,6 +30805,10 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30402
30805
 
30403
30806
  needsProgramChange = true;
30404
30807
 
30808
+ } else if ( materialProperties.numMultiviewViews !== numMultiviewViews ) {
30809
+
30810
+ needsProgramChange = true;
30811
+
30405
30812
  }
30406
30813
 
30407
30814
  } else {
@@ -30448,8 +30855,17 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30448
30855
 
30449
30856
  // common camera uniforms
30450
30857
 
30451
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
30452
- p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
30858
+ if ( program.numMultiviewViews > 0 ) {
30859
+
30860
+ multiview.updateCameraProjectionMatricesUniform( camera, p_uniforms );
30861
+ multiview.updateCameraViewMatricesUniform( camera, p_uniforms );
30862
+
30863
+ } else {
30864
+
30865
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
30866
+ p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
30867
+
30868
+ }
30453
30869
 
30454
30870
  const uCamPos = p_uniforms.map.cameraPosition;
30455
30871
 
@@ -30597,8 +31013,17 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30597
31013
 
30598
31014
  // common matrices
30599
31015
 
30600
- p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
30601
- p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
31016
+ if ( program.numMultiviewViews > 0 ) {
31017
+
31018
+ multiview.updateObjectMatricesUniforms( object, camera, p_uniforms );
31019
+
31020
+ } else {
31021
+
31022
+ p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
31023
+ p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
31024
+
31025
+ }
31026
+
30602
31027
  p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
30603
31028
 
30604
31029
  // UBOs
@@ -30708,20 +31133,16 @@ console.warn( 'Scripts "build/three.js" and "build/three.min.js" are deprecated
30708
31133
  const renderTargetProperties = properties.get( renderTarget );
30709
31134
  renderTargetProperties.__hasExternalTextures = true;
30710
31135
 
30711
- if ( renderTargetProperties.__hasExternalTextures ) {
31136
+ renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
30712
31137
 
30713
- renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
31138
+ if ( ! renderTargetProperties.__autoAllocateDepthBuffer && ! _currentRenderTarget.isWebGLMultiviewRenderTarget ) {
30714
31139
 
30715
- if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) {
31140
+ // The multisample_render_to_texture extension doesn't work properly if there
31141
+ // are midframe flushes and an external depth buffer. Disable use of the extension.
31142
+ if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
30716
31143
 
30717
- // The multisample_render_to_texture extension doesn't work properly if there
30718
- // are midframe flushes and an external depth buffer. Disable use of the extension.
30719
- if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
30720
-
30721
- console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
30722
- renderTargetProperties.__useRenderToTexture = false;
30723
-
30724
- }
31144
+ console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
31145
+ renderTargetProperties.__useRenderToTexture = false;
30725
31146
 
30726
31147
  }
30727
31148