Skip to content
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

Introduce Scene.environmentIntensity #27903

Merged
merged 1 commit into from Mar 19, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/en/scenes/Scene.html
Expand Up @@ -62,6 +62,12 @@ <h3>[property:Texture environment]</h3>
[page:MeshStandardMaterial.envMap]. Default is `null`.
</p>

<h3>[property:Float environmentIntensity]</h3>
<p>
Attenuates the color of the environment. Only influences environment maps
assigned to [page:Scene.environment]. Default is `1`.
</p>

<h3>[property:Euler environmentRotation]</h3>
<p>
The rotation of the environment map in radians. Only influences physical materials
Expand Down
2 changes: 2 additions & 0 deletions src/loaders/ObjectLoader.js
Expand Up @@ -798,6 +798,8 @@ class ObjectLoader extends Loader {
if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );

if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );

break;
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/WebGLRenderer.js
Expand Up @@ -1986,6 +1986,12 @@ class WebGLRenderer {

}

if ( material.isMeshStandardMaterial && material.envMap === null && scene.environment !== null ) {

m_uniforms.envMapIntensity.value = scene.environmentIntensity;

}

if ( refreshMaterial ) {

p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
Expand Down
5 changes: 2 additions & 3 deletions src/renderers/webgl/WebGLMaterials.js
Expand Up @@ -393,11 +393,10 @@ function WebGLMaterials( renderer, properties ) {

}

const envMap = properties.get( material ).envMap;

if ( envMap ) {
if ( material.envMap ) {

//uniforms.envMap.value = material.envMap; // part of uniforms common

uniforms.envMapIntensity.value = material.envMapIntensity;

}
Expand Down
8 changes: 7 additions & 1 deletion src/scenes/Scene.js
Expand Up @@ -18,6 +18,8 @@ class Scene extends Object3D {
this.backgroundBlurriness = 0;
this.backgroundIntensity = 1;
this.backgroundRotation = new Euler();

this.environmentIntensity = 1;
this.environmentRotation = new Euler();

this.overrideMaterial = null;
Expand All @@ -41,6 +43,8 @@ class Scene extends Object3D {
this.backgroundBlurriness = source.backgroundBlurriness;
this.backgroundIntensity = source.backgroundIntensity;
this.backgroundRotation.copy( source.backgroundRotation );

this.environmentIntensity = source.environmentIntensity;
this.environmentRotation.copy( source.environmentRotation );

if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
Expand All @@ -56,10 +60,12 @@ class Scene extends Object3D {
const data = super.toJSON( meta );

if ( this.fog !== null ) data.object.fog = this.fog.toJSON();

if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;

data.object.backgroundRotation = this.backgroundRotation.toArray();

if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
data.object.environmentRotation = this.environmentRotation.toArray();

return data;
Expand Down