diff --git a/docs/api/en/renderers/WebGLMultipleRenderTargets.html b/docs/api/en/renderers/WebGLMultipleRenderTargets.html index 57b33c08027f92..8023287c12f4a9 100644 --- a/docs/api/en/renderers/WebGLMultipleRenderTargets.html +++ b/docs/api/en/renderers/WebGLMultipleRenderTargets.html @@ -27,12 +27,18 @@

Examples

Constructor

-

[name]([param:Number width], [param:Number height], [param:Number count])

+

[name]([param:Number width], [param:Number height], [param:Number count], [param:Object options])

[page:Number width] - The width of the render target.
[page:Number height] - The height of the render target.
- [page:Number count] - The number of render targets. + [page:Number count] - The number of render targets.
+ + options - (optional object that holds texture parameters for an auto-generated target + texture and depthBuffer/stencilBuffer booleans. + + For an explanation of the texture parameters see [page:Texture Texture]. + For a list of valid options, see [page:WebGLRenderTarget WebGLRenderTarget].

Properties

diff --git a/docs/api/en/renderers/WebGLMultisampleRenderTarget.html b/docs/api/en/renderers/WebGLMultisampleRenderTarget.html deleted file mode 100644 index c7274dfce60bff..00000000000000 --- a/docs/api/en/renderers/WebGLMultisampleRenderTarget.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - [page:WebGLRenderTarget] → - -

[name]

- -

- A special render target that can be used to utilize multi-sampled renderbuffers. - Heads up: [name] can only be used with a WebGL 2 rendering context. -

- -

Examples

- -

- [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ] -

- -

Constructor

- - -

[name]([param:Number width], [param:Number height], [param:Object options])

- -

- [page:Float width] - The width of the render target.
- [page:Float height] - The height of the render target.
- [page:Object options] - (optional) object that holds texture parameters for an auto-generated target - texture and depthBuffer/stencilBuffer booleans. -

- -

Properties

- -

[property:number samples]

-

- Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported - size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*. -

- -

[page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.

- -

Methods

- -

[page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.

- -

Source

- -

- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] -

- - diff --git a/docs/api/en/renderers/WebGLRenderTarget.html b/docs/api/en/renderers/WebGLRenderTarget.html index 7f264688672929..823721c8e183c6 100644 --- a/docs/api/en/renderers/WebGLRenderTarget.html +++ b/docs/api/en/renderers/WebGLRenderTarget.html @@ -93,6 +93,10 @@

[property:DepthTexture depthTexture]

If set, the scene depth will be rendered to this texture. Default is null.

+

[property:Number samples]

+

+ Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*. +

Methods

diff --git a/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html b/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html deleted file mode 100644 index 974ced3690800e..00000000000000 --- a/docs/api/zh/renderers/WebGLMultisampleRenderTarget.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - - - - - [page:WebGLRenderTarget] → - -

[name]

- -

- A special render target that can be used to utilize multi-sampled renderbuffers. - Heads up: [name] can only be used with a WebGL 2 rendering context. -

- -

Examples

- -

- [example:webgl2_multisampled_renderbuffers webgl2 / multisampled / renderbuffers ] -

- -

Constructor

- - -

[name]([param:Number width], [param:Number height], [param:Object options])

- -

- [page:Float width] - The width of the render target.
- [page:Float height] - The height of the render target.
- [page:Object options] - (optional) object that holds texture parameters for an auto-generated target - texture and depthBuffer/stencilBuffer booleans. -

- -

Properties

- -

[property:number samples]

-

- Specifies the number of samples to be used for the renderbuffer storage. However, the maximum supported - size for multisampling is platform dependent and defined via *gl.MAX_SAMPLES*. -

- -

[page:WebGLRenderTarget WebGLRenderTarget] properties are available on this class.

- -

Methods

- -

[page:WebGLRenderTarget WebGLRenderTarget] methods are available on this class.

- -

Source

- -

- [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js] -

- - diff --git a/docs/api/zh/renderers/WebGLRenderTarget.html b/docs/api/zh/renderers/WebGLRenderTarget.html index 072a5efe405acb..d124d812ffd65a 100644 --- a/docs/api/zh/renderers/WebGLRenderTarget.html +++ b/docs/api/zh/renderers/WebGLRenderTarget.html @@ -89,6 +89,10 @@

[property:DepthTexture depthTexture]

如果设置,那么场景的深度将会被渲染到此纹理上。默认为null

+

[property:Number samples]

+

+ Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*. +

方法

diff --git a/docs/list.json b/docs/list.json index 323e83dac3b009..5fea23ab7a9a58 100644 --- a/docs/list.json +++ b/docs/list.json @@ -283,7 +283,6 @@ "Renderers": { "WebGLMultipleRenderTargets": "api/en/renderers/WebGLMultipleRenderTargets", - "WebGLMultisampleRenderTarget": "api/en/renderers/WebGLMultisampleRenderTarget", "WebGLRenderer": "api/en/renderers/WebGLRenderer", "WebGL1Renderer": "api/en/renderers/WebGL1Renderer", "WebGLRenderTarget": "api/en/renderers/WebGLRenderTarget", @@ -782,7 +781,6 @@ "渲染器": { "WebGLMultipleRenderTargets": "api/zh/renderers/WebGLMultipleRenderTargets", - "WebGLMultisampleRenderTarget": "api/zh/renderers/WebGLMultisampleRenderTarget", "WebGLRenderer": "api/zh/renderers/WebGLRenderer", "WebGL1Renderer": "api/zh/renderers/WebGL1Renderer", "WebGLRenderTarget": "api/zh/renderers/WebGLRenderTarget", diff --git a/examples/jsm/objects/Reflector.js b/examples/jsm/objects/Reflector.js index 01b9b318868709..19fa3b266f8203 100644 --- a/examples/jsm/objects/Reflector.js +++ b/examples/jsm/objects/Reflector.js @@ -26,6 +26,7 @@ class Reflector extends Mesh { const textureHeight = options.textureHeight || 512; const clipBias = options.clipBias || 0; const shader = options.shader || Reflector.ReflectorShader; + const multisample = ( options.multisample !== undefined ) ? options.multisample : 4; // @@ -44,7 +45,7 @@ class Reflector extends Mesh { const textureMatrix = new Matrix4(); const virtualCamera = new PerspectiveCamera(); - const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight ); + const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } ); const material = new ShaderMaterial( { uniforms: UniformsUtils.clone( shader.uniforms ), diff --git a/examples/jsm/objects/Refractor.js b/examples/jsm/objects/Refractor.js index 3e09f97a602a6c..0c879fe408a119 100644 --- a/examples/jsm/objects/Refractor.js +++ b/examples/jsm/objects/Refractor.js @@ -27,6 +27,7 @@ class Refractor extends Mesh { const textureHeight = options.textureHeight || 512; const clipBias = options.clipBias || 0; const shader = options.shader || Refractor.RefractorShader; + const multisample = ( options.multisample !== undefined ) ? options.multisample : 4; // @@ -41,7 +42,7 @@ class Refractor extends Mesh { // render target - const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight ); + const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } ); // material diff --git a/examples/webgl2_multisampled_renderbuffers.html b/examples/webgl2_multisampled_renderbuffers.html index 1f76fe79135a09..fab710cd78615a 100644 --- a/examples/webgl2_multisampled_renderbuffers.html +++ b/examples/webgl2_multisampled_renderbuffers.html @@ -92,7 +92,7 @@ group = new THREE.Group(); const geometry = new THREE.SphereGeometry( 10, 64, 40 ); - const material = new THREE.MeshLambertMaterial( { color: 0xee0808 } ); + const material = new THREE.MeshLambertMaterial( { color: 0xee0808 } ); const material2 = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true } ); for ( let i = 0; i < 10; i ++ ) { @@ -127,7 +127,7 @@ // const size = renderer.getDrawingBufferSize( new THREE.Vector2() ); - const renderTarget = new THREE.WebGLMultisampleRenderTarget( size.width, size.height ); + const renderTarget = new THREE.WebGLRenderTarget( size.width, size.height, { samples: 4 } ); const renderPass = new RenderPass( scene, camera ); const copyPass = new ShaderPass( CopyShader ); diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js index 69ea7487eba24d..7786bdfc243214 100644 --- a/src/Three.Legacy.js +++ b/src/Three.Legacy.js @@ -1975,3 +1975,12 @@ export function ImmediateRenderObject() { console.error( 'THREE.ImmediateRenderObject has been removed.' ); } + +export function WebGLMultisampleRenderTarget( width, height, options ) { + + console.error( 'THREE.WebGLMultisampleRenderTarget has been removed. Use a normal render target and set the "samples" property to greater 0 to enable multisampling.' ); + const renderTarget = new WebGLRenderTarget( width, height, options ); + renderTarget.samples = 4; + return renderTarget; + +} diff --git a/src/Three.d.ts b/src/Three.d.ts index b294901bbff8e8..ef408840baa3b7 100644 --- a/src/Three.d.ts +++ b/src/Three.d.ts @@ -176,7 +176,6 @@ export * from './objects/Group'; /** * Renderers */ -export * from './renderers/WebGLMultisampleRenderTarget'; export * from './renderers/WebGLCubeRenderTarget'; export * from './renderers/WebGLMultipleRenderTargets'; export * from './renderers/WebGLRenderTarget'; diff --git a/src/Three.js b/src/Three.js index 3cf3e16cea4a39..a5f713cdd5aedf 100644 --- a/src/Three.js +++ b/src/Three.js @@ -2,7 +2,6 @@ import { REVISION } from './constants.js'; export { platform } from './platform.js'; export { WebGLMultipleRenderTargets } from './renderers/WebGLMultipleRenderTargets.js'; -export { WebGLMultisampleRenderTarget } from './renderers/WebGLMultisampleRenderTarget.js'; export { WebGLCubeRenderTarget } from './renderers/WebGLCubeRenderTarget.js'; export { WebGLRenderTarget } from './renderers/WebGLRenderTarget.js'; export { WebGLRenderer } from './renderers/WebGLRenderer.js'; diff --git a/src/renderers/WebGLMultipleRenderTargets.js b/src/renderers/WebGLMultipleRenderTargets.js index 73bd6d6738ec68..9c370bd36da6c0 100644 --- a/src/renderers/WebGLMultipleRenderTargets.js +++ b/src/renderers/WebGLMultipleRenderTargets.js @@ -2,9 +2,9 @@ import { WebGLRenderTarget } from './WebGLRenderTarget.js'; class WebGLMultipleRenderTargets extends WebGLRenderTarget { - constructor( width, height, count ) { + constructor( width, height, count, options = {} ) { - super( width, height ); + super( width, height, options ); const texture = this.texture; diff --git a/src/renderers/WebGLMultisampleRenderTarget.d.ts b/src/renderers/WebGLMultisampleRenderTarget.d.ts deleted file mode 100644 index ab0fdef50bc858..00000000000000 --- a/src/renderers/WebGLMultisampleRenderTarget.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { WebGLRenderTarget, WebGLRenderTargetOptions } from './WebGLRenderTarget'; - -export class WebGLMultisampleRenderTarget extends WebGLRenderTarget { - constructor(width: number, height: number, options?: WebGLRenderTargetOptions); - - readonly isWebGLMultisampleRenderTarget: true; - - /** - * Specifies the number of samples to be used for the renderbuffer storage.However, the maximum supported size for multisampling is platform dependent and defined via gl.MAX_SAMPLES. - * @default 4 - */ - samples: number; -} diff --git a/src/renderers/WebGLMultisampleRenderTarget.js b/src/renderers/WebGLMultisampleRenderTarget.js deleted file mode 100644 index 0d08ab6c1945cd..00000000000000 --- a/src/renderers/WebGLMultisampleRenderTarget.js +++ /dev/null @@ -1,33 +0,0 @@ -import { WebGLRenderTarget } from './WebGLRenderTarget.js'; - -class WebGLMultisampleRenderTarget extends WebGLRenderTarget { - - constructor( width, height, options = {} ) { - - super( width, height, options ); - - this.samples = 4; - - this.ignoreDepthForMultisampleCopy = options.ignoreDepth !== undefined ? options.ignoreDepth : true; - this.useRenderToTexture = ( options.useRenderToTexture !== undefined ) ? options.useRenderToTexture : false; - this.useRenderbuffer = this.useRenderToTexture === false; - - } - - copy( source ) { - - super.copy.call( this, source ); - - this.samples = source.samples; - this.useRenderToTexture = source.useRenderToTexture; - this.useRenderbuffer = source.useRenderbuffer; - - return this; - - } - -} - -WebGLMultisampleRenderTarget.prototype.isWebGLMultisampleRenderTarget = true; - -export { WebGLMultisampleRenderTarget }; diff --git a/src/renderers/WebGLRenderTarget.d.ts b/src/renderers/WebGLRenderTarget.d.ts index c2f22041d09f4a..6e3ce5aec451bb 100644 --- a/src/renderers/WebGLRenderTarget.d.ts +++ b/src/renderers/WebGLRenderTarget.d.ts @@ -17,6 +17,7 @@ export interface WebGLRenderTargetOptions { generateMipmaps?: boolean | undefined; // true; depthTexture?: DepthTexture | undefined; encoding?: TextureEncoding | undefined; + samples?: number | undefined; // 0 } export class WebGLRenderTarget extends EventDispatcher { diff --git a/src/renderers/WebGLRenderTarget.js b/src/renderers/WebGLRenderTarget.js index eab1dab600f8b8..6e1e1a433ad045 100644 --- a/src/renderers/WebGLRenderTarget.js +++ b/src/renderers/WebGLRenderTarget.js @@ -35,6 +35,7 @@ class WebGLRenderTarget extends EventDispatcher { this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true; this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false; + this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null; /** @@ -43,6 +44,7 @@ class WebGLRenderTarget extends EventDispatcher { * see WebGlTextures.setupRenderBufferStorage * */ platform.properties && ( this.useDEPTH_COMPONENT24 = platform.properties.rendertargetUseDEPTH_COMPONENT24 ); + this.samples = options.samples !== undefined ? options.samples : 0; } @@ -101,7 +103,10 @@ class WebGLRenderTarget extends EventDispatcher { this.depthBuffer = source.depthBuffer; this.stencilBuffer = source.stencilBuffer; - this.depthTexture = source.depthTexture; + + if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone(); + + this.samples = source.samples; return this; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 4eaa3313cdc063..75f4518b82b705 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -11,8 +11,6 @@ import { sRGBEncoding, NoToneMapping, LinearMipmapLinearFilter, - NearestFilter, - ClampToEdgeWrapping } from '../constants.js'; import { platform } from '../platform.js'; import { Frustum } from '../math/Frustum.js'; @@ -33,7 +31,6 @@ import { WebGLGeometries } from './webgl/WebGLGeometries.js'; import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js'; import { WebGLInfo } from './webgl/WebGLInfo.js'; import { WebGLMorphtargets } from './webgl/WebGLMorphtargets.js'; -import { WebGLMultisampleRenderTarget } from './WebGLMultisampleRenderTarget.js'; import { WebGLObjects } from './webgl/WebGLObjects.js'; import { WebGLPrograms } from './webgl/WebGLPrograms.js'; import { WebGLProperties } from './webgl/WebGLProperties.js'; @@ -48,7 +45,6 @@ import { WebGLUtils } from './webgl/WebGLUtils.js'; import { WebXRManager } from './webxr/WebXRManager.js'; import { WebGLMaterials } from './webgl/WebGLMaterials.js'; import { createElementNS } from '../utils.js'; -import { Texture } from '../textures/Texture.js'; function createCanvasElement() { @@ -1256,17 +1252,13 @@ function WebGLRenderer( parameters = {} ) { if ( _transmissionRenderTarget === null ) { const needsAntialias = _antialias === true && capabilities.isWebGL2 === true; - const renderTargetType = needsAntialias ? WebGLMultisampleRenderTarget : WebGLRenderTarget; const hasColorBufferHalfFloat = extensions.has( 'EXT_color_buffer_half_float' ) || ( capabilities.isWebGL2 && extensions.has( 'EXT_color_buffer_float' ) ); - _transmissionRenderTarget = new renderTargetType( 1024, 1024, { + _transmissionRenderTarget = new WebGLRenderTarget( 1024, 1024, { generateMipmaps: true, type: hasColorBufferHalfFloat ? HalfFloatType : UnsignedByteType, minFilter: LinearMipmapLinearFilter, - magFilter: NearestFilter, - wrapS: ClampToEdgeWrapping, - wrapT: ClampToEdgeWrapping, - useRenderToTexture: extensions.has( 'WEBGL_multisampled_render_to_texture' ) + samples: needsAntialias ? 4 : 0 } ); } @@ -1848,11 +1840,10 @@ function WebGLRenderer( parameters = {} ) { // The multisample_render_to_texture extension doesn't work properly if there // are midframe flushes and an external depth buffer. Disable use of the extension. - if ( renderTarget.useRenderToTexture ) { + if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) { - console.warn( 'render-to-texture extension was disabled because an external texture was provided' ); - renderTarget.useRenderToTexture = false; - renderTarget.useRenderbuffer = true; + console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' ); + renderTargetProperties.__useRenderToTexture = false; } @@ -1921,7 +1912,7 @@ function WebGLRenderer( parameters = {} ) { framebuffer = __webglFramebuffer[ activeCubeFace ]; isCube = true; - } else if ( renderTarget.useRenderbuffer ) { + } else if ( ( capabilities.isWebGL2 && renderTarget.samples > 0 ) && textures.useMultisampledRenderToTexture( renderTarget ) === false ) { framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer; diff --git a/src/renderers/webgl/WebGLTextures.js b/src/renderers/webgl/WebGLTextures.js index 59c65eea17df26..3e3eb0a1a2fecb 100644 --- a/src/renderers/webgl/WebGLTextures.js +++ b/src/renderers/webgl/WebGLTextures.js @@ -10,9 +10,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const maxCubemapSize = capabilities.maxCubemapSize; const maxTextureSize = capabilities.maxTextureSize; const maxSamples = capabilities.maxSamples; - const hasMultisampledRenderToTexture = extensions.has( 'WEBGL_multisampled_render_to_texture' ); - const MultisampledRenderToTextureExtension = hasMultisampledRenderToTexture ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : undefined; + const MultisampledRenderToTextureExtension = extensions.has( 'WEBGL_multisampled_render_to_texture' ) ? extensions.get( 'WEBGL_multisampled_render_to_texture' ) : null; const supportsInvalidateFramebuffer = typeof navigator === 'undefined' ? false : /OculusBrowser/g.test( navigator.userAgent ); + const _videoTextures = new WeakMap(); let _canvas; @@ -1104,7 +1104,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer ); - if ( renderTarget.useRenderToTexture ) { + + if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) ); @@ -1128,7 +1129,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, let glInternalFormat = renderTarget.useDEPTH_COMPONENT24 ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16; - if ( isMultisample || renderTarget.useRenderToTexture ) { + if ( isMultisample || useMultisampledRenderToTexture( renderTarget ) ) { const depthTexture = renderTarget.depthTexture; @@ -1148,7 +1149,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const samples = getRenderTargetSamples( renderTarget ); - if ( renderTarget.useRenderToTexture ) { + if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); @@ -1170,11 +1171,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const samples = getRenderTargetSamples( renderTarget ); - if ( isMultisample && renderTarget.useRenderbuffer ) { + if ( isMultisample && useMultisampledRenderToTexture( renderTarget ) === false ) { _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height ); - } else if ( renderTarget.useRenderToTexture ) { + } else if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height ); @@ -1197,11 +1198,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.sRGBToLinearWithShader ); const samples = getRenderTargetSamples( renderTarget ); - if ( isMultisample && renderTarget.useRenderbuffer ) { + if ( isMultisample && useMultisampledRenderToTexture( renderTarget ) === false ) { _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); - } else if ( renderTarget.useRenderToTexture ) { + } else if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); @@ -1249,7 +1250,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, if ( renderTarget.depthTexture.format === DepthFormat ) { - if ( renderTarget.useRenderToTexture ) { + if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples ); @@ -1261,7 +1262,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) { - if ( renderTarget.useRenderToTexture ) { + if ( useMultisampledRenderToTexture( renderTarget ) ) { MultisampledRenderToTextureExtension.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples ); @@ -1408,41 +1409,32 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, } - } else if ( renderTarget.useRenderbuffer ) { - - if ( isWebGL2 ) { - - renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); - renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer(); - - _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer ); - - const glFormat = utils.convert( texture.format, texture.encoding ); - const glType = utils.convert( texture.type ); - const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.sRGBToLinearWithShader ); - const samples = getRenderTargetSamples( renderTarget ); - _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); - - state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); - _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer ); - _gl.bindRenderbuffer( _gl.RENDERBUFFER, null ); + } else if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRenderToTexture( renderTarget ) === false ) { - if ( renderTarget.depthBuffer ) { + renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); + renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer(); - renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); - setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true ); + _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer ); - } - - state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + const glFormat = utils.convert( texture.format, texture.encoding ); + const glType = utils.convert( texture.type ); + const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding ); + const samples = getRenderTargetSamples( renderTarget ); + _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer ); + _gl.bindRenderbuffer( _gl.RENDERBUFFER, null ); - } else { + if ( renderTarget.depthBuffer ) { - console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' ); + renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true ); } + state.bindFramebuffer( _gl.FRAMEBUFFER, null ); + } } @@ -1563,68 +1555,68 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, function updateMultisampleRenderTarget( renderTarget ) { - if ( renderTarget.useRenderbuffer ) { - - if ( isWebGL2 ) { + if ( ( isWebGL2 && renderTarget.samples > 0 ) && useMultisampledRenderToTexture( renderTarget ) === false ) { - const width = renderTarget.width; - const height = renderTarget.height; - let mask = _gl.COLOR_BUFFER_BIT; - const invalidationArray = [ _gl.COLOR_ATTACHMENT0 ]; - const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; + const width = renderTarget.width; + const height = renderTarget.height; + let mask = _gl.COLOR_BUFFER_BIT; + const invalidationArray = [ _gl.COLOR_ATTACHMENT0 ]; + const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; - if ( renderTarget.depthBuffer ) { + if ( renderTarget.depthBuffer ) { - invalidationArray.push( depthStyle ); + invalidationArray.push( depthStyle ); - } + } - if ( ! renderTarget.ignoreDepthForMultisampleCopy ) { + const renderTargetProperties = properties.get( renderTarget ); + const ignoreDepthValues = ( renderTargetProperties.__ignoreDepthValues !== undefined ) ? renderTargetProperties.__ignoreDepthValues : false; - if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT; - if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT; + if ( ignoreDepthValues === false ) { - } + if ( renderTarget.depthBuffer ) mask |= _gl.DEPTH_BUFFER_BIT; + if ( renderTarget.stencilBuffer ) mask |= _gl.STENCIL_BUFFER_BIT; - const renderTargetProperties = properties.get( renderTarget ); + } - state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); - state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer ); - if ( renderTarget.ignoreDepthForMultisampleCopy ) { + if ( ignoreDepthValues === true ) { - _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, [ depthStyle ] ); - _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] ); + _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, [ depthStyle ] ); + _gl.invalidateFramebuffer( _gl.DRAW_FRAMEBUFFER, [ depthStyle ] ); - } + } - _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST ); + _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST ); - // https://github.com/mrdoob/three.js/pull/23692 - if ( supportsInvalidateFramebuffer ) { + // https://github.com/mrdoob/three.js/pull/23692 + if ( supportsInvalidateFramebuffer ) { - _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArray ); + _gl.invalidateFramebuffer( _gl.READ_FRAMEBUFFER, invalidationArray ); - } + } - state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null ); - state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); + state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null ); + state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer ); - } else { + } - console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' ); + } - } + function getRenderTargetSamples( renderTarget ) { - } + return Math.min( maxSamples, renderTarget.samples ); } - function getRenderTargetSamples( renderTarget ) { + function useMultisampledRenderToTexture( renderTarget ) { + + const renderTargetProperties = properties.get( renderTarget ); - return ( isWebGL2 && ( renderTarget.useRenderbuffer || renderTarget.useRenderToTexture ) ) ? - Math.min( maxSamples, renderTarget.samples ) : 0; + return isWebGL2 && renderTarget.samples > 0 && extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTargetProperties.__useRenderToTexture !== false; } @@ -1702,6 +1694,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, this.updateMultisampleRenderTarget = updateMultisampleRenderTarget; this.setupDepthRenderbuffer = setupDepthRenderbuffer; this.setupFrameBufferTexture = setupFrameBufferTexture; + this.useMultisampledRenderToTexture = useMultisampledRenderToTexture; this.safeSetTexture2D = safeSetTexture2D; this.safeSetTextureCube = safeSetTextureCube; diff --git a/src/renderers/webxr/WebXRManager.js b/src/renderers/webxr/WebXRManager.js index 53c6ca7d82825a..04df05d6ad443e 100644 --- a/src/renderers/webxr/WebXRManager.js +++ b/src/renderers/webxr/WebXRManager.js @@ -7,7 +7,6 @@ import { WebGLAnimation } from '../webgl/WebGLAnimation.js'; import { WebGLRenderTarget } from '../WebGLRenderTarget.js'; import { WebXRController } from './WebXRController.js'; import { DepthTexture } from '../../textures/DepthTexture.js'; -import { WebGLMultisampleRenderTarget } from '../WebGLMultisampleRenderTarget.js'; import { DepthFormat, DepthStencilFormat, @@ -31,13 +30,11 @@ class WebXRManager extends EventDispatcher { let referenceSpace = null; let referenceSpaceType = 'local-floor'; - const hasMultisampledRenderToTexture = renderer.extensions.has( 'WEBGL_multisampled_render_to_texture' ); let pose = null; let glBinding = null; let glProjLayer = null; let glBaseLayer = null; - let isMultisample = false; let xrFrame = null; const attributes = gl.getContextAttributes(); let initialRenderTarget = null; @@ -267,7 +264,6 @@ class WebXRManager extends EventDispatcher { } else { - isMultisample = attributes.antialias; let depthFormat = null; let depthType = null; let glDepthFormat = null; @@ -292,36 +288,20 @@ class WebXRManager extends EventDispatcher { session.updateRenderState( { layers: [ glProjLayer ] } ); - if ( isMultisample ) { - - newRenderTarget = new WebGLMultisampleRenderTarget( - glProjLayer.textureWidth, - glProjLayer.textureHeight, - { - format: RGBAFormat, - type: UnsignedByteType, - depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ), - stencilBuffer: attributes.stencil, - ignoreDepth: glProjLayer.ignoreDepthValues, - useRenderToTexture: hasMultisampledRenderToTexture, - encoding: renderer.outputEncoding - } ); - - } else { - - newRenderTarget = new WebGLRenderTarget( - glProjLayer.textureWidth, - glProjLayer.textureHeight, - { - format: RGBAFormat, - type: UnsignedByteType, - depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ), - stencilBuffer: attributes.stencil, - ignoreDepth: glProjLayer.ignoreDepthValues, - encoding: renderer.outputEncoding - } ); - - } + newRenderTarget = new WebGLRenderTarget( + glProjLayer.textureWidth, + glProjLayer.textureHeight, + { + format: RGBAFormat, + type: UnsignedByteType, + depthTexture: new DepthTexture( glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, undefined, undefined, undefined, undefined, undefined, undefined, depthFormat ), + stencilBuffer: attributes.stencil, + encoding: renderer.outputEncoding, + samples: attributes.antialias ? 4 : 0 + } ); + + const renderTargetProperties = renderer.properties.get( newRenderTarget ); + renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues; }