Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renderer: Introduce colorBufferType. #30425

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/webgpu_xr_cubes.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

raycaster = new THREE.Raycaster();

renderer = new THREE.WebGPURenderer( { antialias: true, forceWebGL: true } );
renderer = new THREE.WebGPURenderer( { antialias: true, forceWebGL: true, colorBufferType: THREE.UnsignedByteType } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
Expand Down
4 changes: 3 additions & 1 deletion src/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,15 @@ class PassNode extends TempNode {

this.renderTarget.samples = this.options.samples === undefined ? renderer.samples : this.options.samples;

// Disable MSAA for WebGL backend for now
// TODO: Disable MSAA for WebGL backend for now
if ( renderer.backend.isWebGLBackend === true ) {

this.renderTarget.samples = 0;

}

this.renderTarget.texture.type = renderer.getColorBufferType();

return this.scope === PassNode.COLOR ? this.getTextureNode() : this.getLinearDepthNode();

}
Expand Down
31 changes: 29 additions & 2 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Renderer {
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. This parameter can set to any other integer value than 0
* to overwrite the default.
* @param {Function?} [parameters.getFallback=null] - This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
* @param {Number} [parameters.colorBufferType=HalfFloatType] - Defines the type of color buffers. The default `HalfFloatType` is recommend for best
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
*/
constructor( backend, parameters = {} ) {

Expand All @@ -76,7 +78,8 @@ class Renderer {
stencil = false,
antialias = false,
samples = 0,
getFallback = null
getFallback = null,
colorBufferType = HalfFloatType
} = parameters;

/**
Expand Down Expand Up @@ -577,6 +580,17 @@ class Renderer {
*/
this.onDeviceLost = this._onDeviceLost;

/**
* Defines the type of color buffers. The default `HalfFloatType` is recommend for
* best quality. To save memory and bandwidth, `UnsignedByteType` might be used.
* This will reduce rendering quality though.
*
* @private
* @type {Number}
* @default HalfFloatType
*/
this._colorBufferType = colorBufferType;

/**
* Whether the renderer has been initialized or not.
*
Expand Down Expand Up @@ -974,6 +988,17 @@ class Renderer {

}

/**
* Returns the color buffer type.
*
* @return {Number} The color buffer type.
*/
getColorBufferType() {

return this._colorBufferType;

}

/**
* Default implementation of the device lost callback.
*
Expand Down Expand Up @@ -1128,7 +1153,7 @@ class Renderer {
frameBufferTarget = new RenderTarget( width, height, {
depthBuffer: depth,
stencilBuffer: stencil,
type: HalfFloatType, // FloatType
type: this._colorBufferType,
format: RGBAFormat,
colorSpace: LinearSRGBColorSpace,
generateMipmaps: false,
Expand Down Expand Up @@ -2026,6 +2051,8 @@ class Renderer {
this._renderContexts.dispose();
this._textures.dispose();

if ( this._frameBufferTarget !== null ) this._frameBufferTarget.dispose();

Object.values( this.backend.timestampQueryPool ).forEach( queryPool => {

if ( queryPool !== null ) queryPool.dispose();
Expand Down
10 changes: 6 additions & 4 deletions src/renderers/webgpu/WebGPURenderer.Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BasicNodeLibrary from './nodes/BasicNodeLibrary.js';
* This alternative version of {@link WebGPURenderer} only supports node materials.
* So classes like `MeshBasicMaterial` are not compatible.
*
* @private
* @augments module:Renderer~Renderer
*/
class WebGPURenderer extends Renderer {
Expand All @@ -20,10 +21,11 @@ class WebGPURenderer extends Renderer {
* @param {Boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
* @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
* @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0
* to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses it
* WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses it WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Number} [parameters.outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
* @param {Number} [parameters.colorBufferType=HalfFloatType] - Defines the type of color buffers. The default `HalfFloatType` is recommend for best
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
*/
constructor( parameters = {} ) {

Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgpu/WebGPURenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class WebGPURenderer extends Renderer {
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
* @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
* @param {Number} [parameters.outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
* @param {Number} [parameters.colorBufferType=HalfFloatType] - Defines the type of color buffers. The default `HalfFloatType` is recommend for best
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
*/
constructor( parameters = {} ) {

Expand Down