Skip to content

Commit a777371

Browse files
committed
support multi-pass with webxr multiview
1 parent 8d5eafc commit a777371

File tree

10 files changed

+40
-21
lines changed

10 files changed

+40
-21
lines changed

src/core/RenderTarget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class RenderTarget extends EventDispatcher {
7979
* @type {number}
8080
* @default 1
8181
*/
82-
this.depth = 1;
82+
this.depth = options.depth ? options.depth : 1;
8383

8484
/**
8585
* A rectangular area inside the render target's viewport. Fragments that are
@@ -107,7 +107,7 @@ class RenderTarget extends EventDispatcher {
107107
*/
108108
this.viewport = new Vector4( 0, 0, width, height );
109109

110-
const image = { width: width, height: height, depth: 1 };
110+
const image = { width: width, height: height, depth: this.depth };
111111

112112
options = Object.assign( {
113113
generateMipmaps: false,

src/renderers/common/Renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ class Renderer {
11921192

11931193
frameBufferTarget.depthBuffer = depth;
11941194
frameBufferTarget.stencilBuffer = stencil;
1195-
frameBufferTarget.setSize( width, height );
1195+
frameBufferTarget.setSize( width, height, this.getOutputRenderTarget() ? this.getOutputRenderTarget().depth : 1 );
11961196
frameBufferTarget.viewport.copy( this._viewport );
11971197
frameBufferTarget.scissor.copy( this._scissor );
11981198
frameBufferTarget.viewport.multiplyScalar( this._pixelRatio );

src/renderers/common/Textures.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import DataMap from './DataMap.js';
22

33
import { Vector3 } from '../../math/Vector3.js';
44
import { DepthTexture } from '../../textures/DepthTexture.js';
5+
import { DepthArrayTexture } from '../../textures/DepthArrayTexture.js';
56
import { DepthStencilFormat, DepthFormat, UnsignedIntType, UnsignedInt248Type, UnsignedByteType } from '../../constants.js';
67

78
const _size = /*@__PURE__*/ new Vector3();
@@ -76,11 +77,20 @@ class Textures extends DataMap {
7677

7778
if ( depthTexture === undefined && useDepthTexture ) {
7879

79-
depthTexture = new DepthTexture();
80+
if (size.depth > 1) {
81+
82+
depthTexture = new DepthArrayTexture();
83+
84+
} else {
85+
86+
depthTexture = new DepthTexture();
87+
88+
}
8089
depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
8190
depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
8291
depthTexture.image.width = mipWidth;
8392
depthTexture.image.height = mipHeight;
93+
depthTexture.image.depth = size.depth;
8494

8595
depthTextureMips[ activeMipmapLevel ] = depthTexture;
8696

src/renderers/common/XRManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,12 @@ class XRManager extends EventDispatcher {
897897
samples: attributes.antialias ? 4 : 0,
898898
resolveDepthBuffer: ( glProjLayer.ignoreDepthValues === false ),
899899
resolveStencilBuffer: ( glProjLayer.ignoreDepthValues === false ),
900+
depth: this._usesMultiview ? 2 : 1
900901
} );
901902

902903
this._xrRenderTarget.hasExternalTextures = true;
903904
this._xrRenderTarget.usesMultiview = this._usesMultiview;
905+
this._xrRenderTarget.depth = this._usesMultiview ? 2 : 1;
904906

905907
this._referenceSpace = await session.requestReferenceSpace( this.getReferenceSpaceType() );
906908

src/renderers/common/nodes/Nodes.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ChainMap from '../ChainMap.js';
33
import NodeBuilderState from './NodeBuilderState.js';
44
import { cubeMapNode } from '../../../nodes/utils/CubeMapNode.js';
55
import { NodeFrame } from '../../../nodes/Nodes.js';
6-
import { objectGroup, renderGroup, frameGroup, cubeTexture, texture, fog, rangeFogFactor, densityFogFactor, reference, pmremTexture, screenUV } from '../../../nodes/TSL.js';
6+
import { objectGroup, renderGroup, frameGroup, cubeTexture, texture, texture3D, fog, rangeFogFactor, densityFogFactor, reference, pmremTexture, screenUV } from '../../../nodes/TSL.js';
77

88
import { CubeUVReflectionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from '../../../constants.js';
99
import { hashArray } from '../../../nodes/core/NodeUtils.js';
@@ -661,7 +661,7 @@ class Nodes extends DataMap {
661661

662662
const renderer = this.renderer;
663663

664-
return renderer.toneMapping + ',' + renderer.currentColorSpace;
664+
return renderer.toneMapping + ',' + renderer.currentColorSpace + ',' + renderer.xr.isPresenting;
665665

666666
}
667667

@@ -692,7 +692,9 @@ class Nodes extends DataMap {
692692
const renderer = this.renderer;
693693
const cacheKey = this.getOutputCacheKey();
694694

695-
const output = texture( outputTarget, screenUV ).renderOutput( renderer.toneMapping, renderer.currentColorSpace );
695+
const output = outputTarget.isTextureArray ?
696+
texture3D( outputTarget, screenUV ).renderOutput( renderer.toneMapping, renderer.currentColorSpace ) :
697+
texture( outputTarget, screenUV ).renderOutput( renderer.toneMapping, renderer.currentColorSpace );
696698

697699
_outputNodeMap.set( outputTarget, cacheKey );
698700

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ class WebGLBackend extends Backend {
20632063

20642064
} else {
20652065

2066-
if ( hasExternalTextures && this.renderer.xr.usesMultiview() ) {
2066+
if ( this.renderer.xr.usesMultiview() ) {
20672067

20682068
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, attachment, textureData.textureGPU, 0, samples, 0, 2 );
20692069

@@ -2100,7 +2100,7 @@ class WebGLBackend extends Backend {
21002100
textureData.renderTarget = descriptor.renderTarget;
21012101
textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
21022102

2103-
if ( hasExternalTextures && this.renderer.xr.usesMultiview() ) {
2103+
if ( this.renderer.xr.usesMultiview() ) {
21042104

21052105
multiviewExt.framebufferTextureMultisampleMultiviewOVR( gl.FRAMEBUFFER, depthStyle, textureData.textureGPU, 0, samples, 0, 2 );
21062106

@@ -2116,7 +2116,6 @@ class WebGLBackend extends Backend {
21162116

21172117
gl.framebufferTextureLayer( gl.FRAMEBUFFER, depthStyle, textureData.textureGPU, 0, layer );
21182118

2119-
21202119
} else {
21212120

21222121
gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,7 @@ ${ flowData.code }
557557

558558
}
559559

560-
if ( uniform.type === 'texture3D' ) {
561-
562-
snippet = `${typePrefix}sampler3D ${ uniform.name };`;
563-
564-
} else if ( texture.compareFunction ) {
560+
if ( texture.compareFunction ) {
565561

566562
if ( texture.isDepthArrayTexture === true ) {
567563

@@ -573,10 +569,14 @@ ${ flowData.code }
573569

574570
}
575571

576-
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
572+
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true || texture.isTextureArray === true ) {
577573

578574
snippet = `${typePrefix}sampler2DArray ${ uniform.name };`;
579575

576+
} else if ( uniform.type === 'texture3D' ) {
577+
578+
snippet = `${typePrefix}sampler3D ${ uniform.name };`;
579+
580580
} else {
581581

582582
snippet = `${typePrefix}sampler2D ${ uniform.name };`;

src/renderers/webgl-fallback/utils/WebGLTextureUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class WebGLTextureUtils {
112112

113113
glTextureType = gl.TEXTURE_CUBE_MAP;
114114

115-
} else if ( texture.isDepthArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
115+
} else if ( texture.isDepthArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true || texture.isTextureArray ) {
116116

117117
glTextureType = gl.TEXTURE_2D_ARRAY;
118118

@@ -307,7 +307,7 @@ class WebGLTextureUtils {
307307
if ( textureType === gl.TEXTURE_3D || textureType === gl.TEXTURE_2D_ARRAY ) {
308308

309309
// WebGL 2 does not support wrapping for depth 2D array textures
310-
if ( ! texture.isDepthArrayTexture ) {
310+
if ( ! texture.isDepthArrayTexture && ! texture.isTextureArray ) {
311311

312312
gl.texParameteri( textureType, gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );
313313

@@ -409,7 +409,7 @@ class WebGLTextureUtils {
409409

410410
this.setTextureParameters( glTextureType, texture );
411411

412-
if ( texture.isDepthArrayTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture ) {
412+
if ( texture.isDepthArrayTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture || texture.isTextureArray ) {
413413

414414
gl.texStorage3D( gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, width, height, depth );
415415

src/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ class WGSLNodeBuilder extends NodeBuilder {
453453

454454
textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode;
455455

456-
if ( texture.isDataArrayTexture || texture.isDepthArrayTexture || texture.isData3DTexture ) {
456+
if ( texture.isDataArrayTexture || texture.isDepthArrayTexture || texture.isData3DTexture || texture.isTextureArray ) {
457457

458458
textureData.arrayLayerCount = new VarNode(
459459
new ExpressionNode(
@@ -1683,7 +1683,7 @@ ${ flowData.code }
16831683

16841684
textureType = 'texture_cube<f32>';
16851685

1686-
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
1686+
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true || texture.isTextureArray === true ) {
16871687

16881688
textureType = 'texture_2d_array<f32>';
16891689

src/textures/Texture.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ class Texture extends EventDispatcher {
366366

367367
}
368368

369+
get isTextureArray() {
370+
371+
return this.source.data.depth > 1;
372+
373+
}
374+
369375
/**
370376
* Updates the texture transformation matrix from the from the properties {@link Texture#offset},
371377
* {@link Texture#repeat}, {@link Texture#rotation}, and {@link Texture#center}.

0 commit comments

Comments
 (0)