Skip to content

Commit

Permalink
WebGLRenderer: Consider .outputEncoding for background, clear color, …
Browse files Browse the repository at this point in the history
…and fog (#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.
  • Loading branch information
donmccurdy authored Nov 9, 2022
1 parent 5f23cdd commit 22f434c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/renderers/shaders/UniformsUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { sRGBEncoding, LinearSRGBColorSpace, SRGBColorSpace } from '../../constants.js';

/**
* Uniform Utilities
*/
Expand Down Expand Up @@ -73,6 +75,19 @@ export function cloneUniformsGroups( src ) {

}

export function getUnlitUniformColorSpace( renderer ) {

if ( renderer.getRenderTarget() === null ) {

// https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
return renderer.outputEncoding === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace;

}

return LinearSRGBColorSpace;

}

// Legacy

const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
Expand Down
8 changes: 6 additions & 2 deletions src/renderers/webgl/WebGLBackground.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ShaderMaterial } from '../../materials/ShaderMaterial.js';
import { Color } from '../../math/Color.js';
import { Mesh } from '../../objects/Mesh.js';
import { ShaderLib } from '../shaders/ShaderLib.js';
import { cloneUniforms } from '../shaders/UniformsUtils.js';
import { cloneUniforms, getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js';

const _rgb = { r: 0, b: 0, g: 0 };

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

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

function setClear( color, alpha ) {

state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
color.getRGB( _rgb, getUnlitUniformColorSpace( renderer ) );

state.buffers.color.setClear( _rgb.r, _rgb.g, _rgb.b, alpha, premultipliedAlpha );

}

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgl/WebGLMaterials.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BackSide } from '../../constants.js';
import { getUnlitUniformColorSpace } from '../shaders/UniformsUtils.js';

function WebGLMaterials( renderer, properties ) {

function refreshFogUniforms( uniforms, fog ) {

uniforms.fogColor.value.copy( fog.color );
fog.color.getRGB( uniforms.fogColor.value, getUnlitUniformColorSpace( renderer ) );

if ( fog.isFog ) {

Expand Down

0 comments on commit 22f434c

Please sign in to comment.