Skip to content

Commit

Permalink
Remove WebGLMultisampleRenderTarget. (#23455)
Browse files Browse the repository at this point in the history
* Remove WebGLMultisampleRenderTarget.

* THREE.Legacy.js: Add WebGLMultisampleRenderTarget.

* Exampels: Clean up.

* WebGLRenderer: Use multisampling when possible without reporting errors.

* Update WebGLRenderer.js

Co-authored-by: mrdoob <[email protected]>
  • Loading branch information
Mugen87 and mrdoob authored Feb 11, 2022
1 parent 7ce01a4 commit 48b05d3
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 293 deletions.
57 changes: 0 additions & 57 deletions docs/api/en/renderers/WebGLMultisampleRenderTarget.html

This file was deleted.

4 changes: 4 additions & 0 deletions docs/api/en/renderers/WebGLRenderTarget.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ <h3>[property:DepthTexture depthTexture]</h3>
If set, the scene depth will be rendered to this texture. Default is null.
</p>

<h3>[property:Number samples]</h3>
<p>
Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*.
</p>

<h2>Methods</h2>

Expand Down
57 changes: 0 additions & 57 deletions docs/api/zh/renderers/WebGLMultisampleRenderTarget.html

This file was deleted.

4 changes: 4 additions & 0 deletions docs/api/zh/renderers/WebGLRenderTarget.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ <h3>[property:DepthTexture depthTexture]</h3>
如果设置,那么场景的深度将会被渲染到此纹理上。默认为null
</p>

<h3>[property:Number samples]</h3>
<p>
Defines the count of MSAA samples. Can only be used with WebGL 2. Default is *0*.
</p>

<h2>方法</h2>

Expand Down
2 changes: 0 additions & 2 deletions docs/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -783,7 +782,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",
Expand Down
18 changes: 3 additions & 15 deletions examples/jsm/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
UniformsUtils,
Vector3,
Vector4,
WebGLRenderTarget,
WebGLMultisampleRenderTarget
WebGLRenderTarget
} from 'three';

class Reflector extends Mesh {
Expand All @@ -27,7 +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 || 4;
const multisample = ( options.multisample !== undefined ) ? options.multisample : 4;

//

Expand All @@ -46,18 +45,7 @@ class Reflector extends Mesh {
const textureMatrix = new Matrix4();
const virtualCamera = new PerspectiveCamera();

let renderTarget;

if ( multisample > 0 ) {

renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight );
renderTarget.samples = multisample;

} else {

renderTarget = new WebGLRenderTarget( textureWidth, textureHeight );

}
const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } );

const material = new ShaderMaterial( {
uniforms: UniformsUtils.clone( shader.uniforms ),
Expand Down
18 changes: 3 additions & 15 deletions examples/jsm/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
UniformsUtils,
Vector3,
Vector4,
WebGLRenderTarget,
WebGLMultisampleRenderTarget
WebGLRenderTarget
} from 'three';

class Refractor extends Mesh {
Expand All @@ -28,7 +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 || 4;
const multisample = ( options.multisample !== undefined ) ? options.multisample : 4;

//

Expand All @@ -43,18 +42,7 @@ class Refractor extends Mesh {

// render target

let renderTarget;

if ( multisample > 0 ) {

renderTarget = new WebGLMultisampleRenderTarget( textureWidth, textureHeight );
renderTarget.samples = multisample;

} else {

renderTarget = new WebGLRenderTarget( textureWidth, textureHeight );

}
const renderTarget = new WebGLRenderTarget( textureWidth, textureHeight, { samples: multisample } );

// material

Expand Down
2 changes: 1 addition & 1 deletion examples/webgl2_multisampled_renderbuffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
9 changes: 9 additions & 0 deletions src/Three.Legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
1 change: 0 additions & 1 deletion src/Three.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { REVISION } from './constants.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';
Expand Down
33 changes: 0 additions & 33 deletions src/renderers/WebGLMultisampleRenderTarget.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/renderers/WebGLRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class WebGLRenderTarget extends EventDispatcher {

this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;

this.samples = options.samples !== undefined ? options.samples : 0;

}

setTexture( texture ) {
Expand Down Expand Up @@ -97,6 +99,8 @@ class WebGLRenderTarget extends EventDispatcher {

if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();

this.samples = source.samples;

return this;

}
Expand Down
13 changes: 5 additions & 8 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,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';
Expand Down Expand Up @@ -1189,13 +1188,11 @@ function WebGLRenderer( parameters = {} ) {

if ( _transmissionRenderTarget === null ) {

const renderTargetType = ( isWebGL2 && _antialias === true ) ? WebGLMultisampleRenderTarget : WebGLRenderTarget;

_transmissionRenderTarget = new renderTargetType( 1, 1, {
_transmissionRenderTarget = new WebGLRenderTarget( 1, 1, {
generateMipmaps: true,
type: HalfFloatType,
type: utils.convert( HalfFloatType ) !== null ? HalfFloatType : UnsignedByteType,
minFilter: LinearMipmapLinearFilter,
useRenderToTexture: extensions.has( 'WEBGL_multisampled_render_to_texture' )
samples: ( isWebGL2 && _antialias === true ) ? 4 : 0
} );

}
Expand Down Expand Up @@ -1797,7 +1794,7 @@ 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( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
renderTarget.useRenderToTexture = false;
Expand Down Expand Up @@ -1870,7 +1867,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;

Expand Down
Loading

0 comments on commit 48b05d3

Please sign in to comment.