Skip to content

WebGPURenderer: Avoid hardcoding color spaces. #31519

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

Merged
merged 1 commit into from
Jul 28, 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
7 changes: 4 additions & 3 deletions src/renderers/common/PostProcessing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
import { ColorManagement } from '../../math/ColorManagement.js';
import { vec4, renderOutput } from '../../nodes/TSL.js';
import { LinearSRGBColorSpace, NoToneMapping } from '../../constants.js';
import { NoToneMapping } from '../../constants.js';
import QuadMesh from '../../renderers/common/QuadMesh.js';

/**
Expand Down Expand Up @@ -110,7 +111,7 @@ class PostProcessing {
const outputColorSpace = renderer.outputColorSpace;

renderer.toneMapping = NoToneMapping;
renderer.outputColorSpace = LinearSRGBColorSpace;
renderer.outputColorSpace = ColorManagement.workingColorSpace;

//

Expand Down Expand Up @@ -219,7 +220,7 @@ class PostProcessing {
const outputColorSpace = renderer.outputColorSpace;

renderer.toneMapping = NoToneMapping;
renderer.outputColorSpace = LinearSRGBColorSpace;
renderer.outputColorSpace = ColorManagement.workingColorSpace;

//

Expand Down
17 changes: 9 additions & 8 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import XRManager from './XRManager.js';
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';

import { Scene } from '../../scenes/Scene.js';
import { ColorManagement } from '../../math/ColorManagement.js';
import { Frustum } from '../../math/Frustum.js';
import { FrustumArray } from '../../math/FrustumArray.js';
import { Matrix4 } from '../../math/Matrix4.js';
import { Vector2 } from '../../math/Vector2.js';
import { Vector4 } from '../../math/Vector4.js';
import { RenderTarget } from '../../core/RenderTarget.js';
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';

import { highpModelNormalViewMatrix, highpModelViewMatrix } from '../../nodes/accessors/ModelNode.js';

Expand Down Expand Up @@ -1210,7 +1211,7 @@ class Renderer {
const { currentToneMapping, currentColorSpace } = this;

const useToneMapping = currentToneMapping !== NoToneMapping;
const useColorSpace = currentColorSpace !== LinearSRGBColorSpace;
const useColorSpace = currentColorSpace !== ColorManagement.workingColorSpace;

if ( useToneMapping === false && useColorSpace === false ) return null;

Expand All @@ -1226,7 +1227,7 @@ class Renderer {
stencilBuffer: stencil,
type: this._colorBufferType,
format: RGBAFormat,
colorSpace: LinearSRGBColorSpace,
colorSpace: ColorManagement.workingColorSpace,
generateMipmaps: false,
minFilter: LinearFilter,
magFilter: LinearFilter,
Expand Down Expand Up @@ -2130,8 +2131,8 @@ class Renderer {
}

/**
* The current output tone mapping of the renderer. When a render target is set,
* the output tone mapping is always `NoToneMapping`.
* The current tone mapping of the renderer. When not producing screen output,
* the tone mapping is always `NoToneMapping`.
*
* @type {number}
*/
Expand All @@ -2142,14 +2143,14 @@ class Renderer {
}

/**
* The current output color space of the renderer. When a render target is set,
* the output color space is always `LinearSRGBColorSpace`.
* The current color space of the renderer. When not producing screen output,
* the color space is always the working color space.
*
* @type {string}
*/
get currentColorSpace() {
Comment on lines -2145 to 2151
Copy link
Collaborator

@donmccurdy donmccurdy Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the “current color space” and “current output color space” phrasing feel unclear to me, since we're describing output but not necessarily .outputColorSpace — maybe this would be clearer named something like targetColorSpace or dstColorSpace? For example:

/**
 * Target color space of the current render stage. Target is the working color
 * space when a render target is assigned, and the output color space otherwise.
 */
get targetColorSpace() { ... }

Importantly, the only possible results are the working and output color spaces. I didn't mean to imply "render target" with the "target" keyword here, so maybe that's confusing too. 😕

(No changes needed in this PR – just a drive-by thought!)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @WestLangley just FYI!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties should describe what color space and tone mapping the renderer is going to apply during the render pass. It is not necessarily what is defined in outputColorSpace and toneMapping. So maybe the term "target" is more clear?


return this.isOutputTarget ? this.outputColorSpace : LinearSRGBColorSpace;
return this.isOutputTarget ? this.outputColorSpace : ColorManagement.workingColorSpace;

}

Expand Down