Skip to content

Commit

Permalink
WebGLRenderer: Fix incorrect background color space when setting scen…
Browse files Browse the repository at this point in the history
…e.background to color (#28434)

* ensure the transmission buffer is assigned a color space, render scene background color

* Update screenshot

* Reuse "renderBackground" flag

* Update WebGLRenderer.js

Clean up.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
  • Loading branch information
gkjohnson and Mugen87 authored May 20, 2024
1 parent aa65ec2 commit 6208714
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Binary file modified examples/screenshots/webgl_materials_car.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class WebGLRenderer {

const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };

let _renderBackground = false;

function getTargetPixelRatio() {

return _currentRenderTarget === null ? _pixelRatio : 1;
Expand Down Expand Up @@ -1153,8 +1155,8 @@ class WebGLRenderer {

}

const renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
if ( renderBackground ) {
_renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
if ( _renderBackground ) {

background.addToRenderList( currentRenderList, scene );

Expand Down Expand Up @@ -1199,7 +1201,7 @@ class WebGLRenderer {

}

if ( renderBackground ) background.render( scene );
if ( _renderBackground ) background.render( scene );

for ( let i = 0, l = cameras.length; i < l; i ++ ) {

Expand All @@ -1213,7 +1215,7 @@ class WebGLRenderer {

if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );

if ( renderBackground ) background.render( scene );
if ( _renderBackground ) background.render( scene );

renderScene( currentRenderList, scene, camera );

Expand Down Expand Up @@ -1430,7 +1432,8 @@ class WebGLRenderer {
samples: 4,
stencilBuffer: stencil,
resolveDepthBuffer: false,
resolveStencilBuffer: false
resolveStencilBuffer: false,
colorSpace: ColorManagement.workingColorSpace,
} );

// debug
Expand Down Expand Up @@ -1461,6 +1464,8 @@ class WebGLRenderer {

_this.clear();

if ( _renderBackground ) background.render( scene );

// Turn off the features which can affect the frag color for opaque objects pass.
// Otherwise they are applied twice in opaque objects pass and transmission objects pass.
const currentToneMapping = _this.toneMapping;
Expand Down

0 comments on commit 6208714

Please sign in to comment.