Skip to content

Commit 22f434c

Browse files
authored
WebGLRenderer: Consider .outputEncoding for background, clear color, and fog (mrdoob#23937)
* Respect renderer.outputEncoding for background and clear color - Applies only when ColorManagement.legacyMode = false * Remove unused import * Fog: Update color management under legacyMode=false to match background and clear color.
1 parent 5f23cdd commit 22f434c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/renderers/shaders/UniformsUtils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { sRGBEncoding, LinearSRGBColorSpace, SRGBColorSpace } from '../../constants.js';
2+
13
/**
24
* Uniform Utilities
35
*/
@@ -73,6 +75,19 @@ export function cloneUniformsGroups( src ) {
7375

7476
}
7577

78+
export function getUnlitUniformColorSpace( renderer ) {
79+
80+
if ( renderer.getRenderTarget() === null ) {
81+
82+
// https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
83+
return renderer.outputEncoding === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;
84+
85+
}
86+
87+
return LinearSRGBColorSpace;
88+
89+
}
90+
7691
// Legacy
7792

7893
const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };

src/renderers/webgl/WebGLBackground.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { ShaderMaterial } from '../../materials/ShaderMaterial.js';
55
import { Color } from '../../math/Color.js';
66
import { Mesh } from '../../objects/Mesh.js';
77
import { ShaderLib } from '../shaders/ShaderLib.js';
8-
import { cloneUniforms } from '../shaders/UniformsUtils.js';
8+
import { cloneUniforms, getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js';
9+
10+
const _rgb = { r: 0, b: 0, g: 0 };
911

1012
function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha ) {
1113

@@ -193,7 +195,9 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
193195

194196
function setClear( color, alpha ) {
195197

196-
state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
198+
color.getRGB( _rgb, getUnlitUniformColorSpace( renderer ) );
199+
200+
state.buffers.color.setClear( _rgb.r, _rgb.g, _rgb.b, alpha, premultipliedAlpha );
197201

198202
}
199203

src/renderers/webgl/WebGLMaterials.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { BackSide } from '../../constants.js';
2+
import { getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js';
23

34
function WebGLMaterials( renderer, properties ) {
45

56
function refreshFogUniforms( uniforms, fog ) {
67

7-
uniforms.fogColor.value.copy( fog.color );
8+
fog.color.getRGB( uniforms.fogColor.value, getUnlitUniformColorSpace( renderer ) );
89

910
if ( fog.isFog ) {
1011

0 commit comments

Comments
 (0)