Skip to content

Commit a13c6a3

Browse files
authored
Introduce scene.backgroundIntensity (mrdoob#24876)
1 parent 0a02067 commit a13c6a3

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

Diff for: docs/api/en/scenes/Scene.html

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ <h3>[property:Float backgroundBlurriness]</h3>
4040
Sets the blurriness of the background. Only influences environment maps assigned to [page:Scene.background]. Valid input is a float between *0* and *1*. Default is *0*.
4141
</p>
4242

43+
<h3>[property:Float backgroundIntensity]</h3>
44+
<p>
45+
Attenuates the color of the background. Only applies to background textures. Default is *1*.
46+
</p>
47+
4348
<h3>[property:Texture environment]</h3>
4449
<p>
4550
Sets the environment map for all physical materials in the scene.

Diff for: src/renderers/shaders/ShaderLib.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ const ShaderLib = {
218218
uniforms: {
219219
uvTransform: { value: /*@__PURE__*/ new Matrix3() },
220220
t2D: { value: null },
221+
backgroundIntensity: { value: 1 }
221222
},
222223

223224
vertexShader: ShaderChunk.background_vert,
@@ -230,7 +231,8 @@ const ShaderLib = {
230231
uniforms: {
231232
envMap: { value: null },
232233
flipEnvMap: { value: - 1 },
233-
backgroundBlurriness: { value: 0 }
234+
backgroundBlurriness: { value: 0 },
235+
backgroundIntensity: { value: 1 }
234236
},
235237

236238
vertexShader: ShaderChunk.backgroundCube_vert,

Diff for: src/renderers/shaders/ShaderLib/background.glsl.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@ void main() {
1313

1414
export const fragment = /* glsl */`
1515
uniform sampler2D t2D;
16+
uniform float backgroundIntensity;
1617
1718
varying vec2 vUv;
1819
1920
void main() {
2021
21-
gl_FragColor = texture2D( t2D, vUv );
22+
vec4 texColor = texture2D( t2D, vUv );
2223
2324
#ifdef DECODE_VIDEO_TEXTURE
2425
2526
// inline sRGB decode (TODO: Remove this code when https://crbug.com/1256340 is solved)
2627
27-
gl_FragColor = vec4( mix( pow( gl_FragColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), gl_FragColor.rgb * 0.0773993808, vec3( lessThanEqual( gl_FragColor.rgb, vec3( 0.04045 ) ) ) ), gl_FragColor.w );
28+
texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
2829
2930
#endif
3031
32+
texColor.rgb *= backgroundIntensity;
33+
34+
gl_FragColor = texColor;
35+
3136
#include <tonemapping_fragment>
3237
#include <encodings_fragment>
3338

Diff for: src/renderers/shaders/ShaderLib/backgroundCube.glsl.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const fragment = /* glsl */`
2929
3030
uniform float flipEnvMap;
3131
uniform float backgroundBlurriness;
32+
uniform float backgroundIntensity;
3233
3334
varying vec3 vWorldDirection;
3435
@@ -50,6 +51,8 @@ void main() {
5051
5152
#endif
5253
54+
texColor.rgb *= backgroundIntensity;
55+
5356
gl_FragColor = texColor;
5457
5558
#include <tonemapping_fragment>

Diff for: src/renderers/webgl/WebGLBackground.js

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
105105
boxMesh.material.uniforms.envMap.value = background;
106106
boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? - 1 : 1;
107107
boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;
108+
boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
108109

109110
if ( currentBackground !== background ||
110111
currentBackgroundVersion !== background.version ||
@@ -159,6 +160,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
159160
}
160161

161162
planeMesh.material.uniforms.t2D.value = background;
163+
planeMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
162164

163165
if ( background.matrixAutoUpdate === true ) {
164166

Diff for: src/scenes/Scene.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Scene extends Object3D {
1515
this.fog = null;
1616

1717
this.backgroundBlurriness = 0;
18+
this.backgroundIntensity = 1;
1819

1920
this.overrideMaterial = null;
2021

@@ -35,6 +36,7 @@ class Scene extends Object3D {
3536
if ( source.fog !== null ) this.fog = source.fog.clone();
3637

3738
this.backgroundBlurriness = source.backgroundBlurriness;
39+
this.backgroundIntensity = source.backgroundIntensity;
3840

3941
if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
4042

@@ -50,6 +52,7 @@ class Scene extends Object3D {
5052

5153
if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
5254
if ( this.backgroundBlurriness > 0 ) data.backgroundBlurriness = this.backgroundBlurriness;
55+
if ( this.backgroundIntensity !== 1 ) data.backgroundIntensity = this.backgroundIntensity;
5356

5457
return data;
5558

0 commit comments

Comments
 (0)