Skip to content

Commit

Permalink
Remove WebGLMultisampleRenderTarget. (mrdoob#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 <info@mrdoob.com>
  • Loading branch information
2 people authored and nianxy committed Apr 10, 2024
1 parent 0133374 commit 878eb3d
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 273 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 @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/objects/Reflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//

Expand All @@ -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 ),
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/objects/Refractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//

Expand All @@ -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

Expand Down
9 changes: 7 additions & 2 deletions examples/webgl2_multisampled_renderbuffers.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@
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,
polygonOffset: true,
polygonOffsetFactor: 1, // positive value pushes polygon further away
polygonOffsetUnits: 1
} );
const material2 = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true } );

for ( let i = 0; i < 10; i ++ ) {
Expand Down Expand Up @@ -127,7 +132,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
Expand Up @@ -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';
Expand Down
33 changes: 0 additions & 33 deletions src/renderers/WebGLMultisampleRenderTarget.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/renderers/WebGLRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,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;

}

Expand Down Expand Up @@ -105,6 +106,8 @@ class WebGLRenderTarget extends EventDispatcher {

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

this.samples = source.samples;

return this;

}
Expand Down
16 changes: 4 additions & 12 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
sRGBEncoding,
NoToneMapping,
LinearMipmapLinearFilter,
NearestFilter,
ClampToEdgeWrapping
} from '../constants.js';
import { platform } from '../platform.js';
import { Frustum } from '../math/Frustum.js';
Expand All @@ -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';
Expand All @@ -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() {

Expand Down Expand Up @@ -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( 1, 1, {
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
} );

}
Expand Down Expand Up @@ -1848,7 +1840,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( 'render-to-texture extension was disabled because an external texture was provided' );
renderTarget.useRenderToTexture = false;
Expand Down Expand Up @@ -1921,7 +1913,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 878eb3d

Please sign in to comment.