Skip to content
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
20 changes: 19 additions & 1 deletion examples/jsm/math/ColorSpaces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LinearTransfer, Matrix3, SRGBTransfer } from 'three';
import { LinearTransfer, Matrix3, SRGBTransfer, SRGBColorSpace, ColorManagement } from 'three';

/** @module ColorSpaces */

Expand Down Expand Up @@ -114,6 +114,24 @@ export const LinearRec2020ColorSpaceImpl = {
luminanceCoefficients: REC2020_LUMINANCE_COEFFICIENTS,
};

/**
* Extended-sRGB color space.
*
* @type {string}
* @constant
*/
export const ExtendedSRGBColorSpace = 'extended-srgb';

/**
* Implementation object for the Extended-sRGB color space.
*
* @type {module:ColorSpaces~ColorSpaceImpl}
* @constant
*/
export const ExtendedSRGBColorSpaceImpl = {
...ColorManagement.spaces[ SRGBColorSpace ],
outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace, toneMappingMode: 'extended' }
};

/**
* An object holding the color space implementation.
Expand Down
11 changes: 9 additions & 2 deletions examples/webgpu_tsl_vfx_linkedparticles.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
import WebGPU from 'three/addons/capabilities/WebGPU.js';

import { ExtendedSRGBColorSpace, ExtendedSRGBColorSpaceImpl } from 'three/addons/math/ColorSpaces.js';

THREE.ColorManagement.define( { [ ExtendedSRGBColorSpace ]: ExtendedSRGBColorSpaceImpl } );

let camera, scene, renderer, postProcessing, controls, timer, light;

let updateParticles, spawnParticles; // TSL compute nodes
Expand Down Expand Up @@ -90,12 +94,15 @@

// renderer

renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer = new THREE.WebGPURenderer( { antialias: true, outputType: THREE.HalfFloatType } );
renderer.setClearColor( 0x14171a );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.toneMapping = THREE.ACESFilmicToneMapping;

renderer.outputColorSpace = ExtendedSRGBColorSpace;
// TODO: Add support for tone mapping #29573
// renderer.toneMapping = THREE.ACESFilmicToneMapping;
document.body.appendChild( renderer.domElement );

// TSL function
Expand Down
8 changes: 7 additions & 1 deletion src/math/ColorManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function createColorManagement() {
* - luminanceCoefficients: RGB luminance coefficients
*
* Optional:
* - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
* - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace, toneMappingMode: 'extended' | 'standard' }
* - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
*
* Reference:
Expand Down Expand Up @@ -103,6 +103,12 @@ function createColorManagement() {

},

getToneMappingMode: function ( colorSpace ) {

return this.spaces[ colorSpace ].outputColorSpaceConfig.toneMappingMode || 'standard';

},

getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {

return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
Expand Down
10 changes: 8 additions & 2 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
import { WebGPUCoordinateSystem } from '../../constants.js';
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
import { warnOnce } from '../../utils.js';
import { ColorManagement } from '../../math/ColorManagement.js';

/**
* A backend implementation targeting WebGPU.
Expand Down Expand Up @@ -238,15 +239,20 @@ class WebGPUBackend extends Backend {

const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';

this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
const toneMappingMode = ColorManagement.getToneMappingMode( this.renderer.outputColorSpace );

this.context.configure( {
device: this.device,
format: this.utils.getPreferredCanvasFormat(),
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
alphaMode: alphaMode
alphaMode: alphaMode,
toneMapping: {
mode: toneMappingMode
}
} );

this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );

this.updateSize();

}
Expand Down