diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 0a2f4bcac5377..ec9c1417a7173 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -12,7 +12,7 @@ import { FloatType, UnsignedByteType, LinearEncoding, - NoToneMapping, + NoToneMapping } from '../constants.js'; import { MathUtils } from '../math/MathUtils.js'; import { DataTexture } from '../textures/DataTexture.js'; @@ -1861,11 +1861,11 @@ function WebGLRenderer( parameters ) { if ( fog && material.fog ) { - materials.refreshUniformsFog( m_uniforms, fog ); + materials.refreshFogUniforms( m_uniforms, fog ); } - materials.refreshUniforms( m_uniforms, material, environment, _pixelRatio, _height ); + materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height ); // RectAreaLight Texture // TODO (mrdoob): Find a nicer implementation @@ -1875,6 +1875,12 @@ function WebGLRenderer( parameters ) { WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures ); + if ( material.isShaderMaterial ) { + + material.uniformsNeedUpdate = false; // #15581 + + } + } if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) { diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index d23d957e096ce..a3a327448915c 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -1,15 +1,29 @@ -import { BackSide } from "../../constants.js"; - /** * @author mrdoob / http://mrdoob.com/ - * - * This is a helper which deals with webgl specific logic of builtin materials - * i.e. uniforms refresh before material is being rendered */ +import { BackSide } from "../../constants.js"; + function WebGLMaterials( properties ) { - function refreshUniforms( uniforms, material, environment, pixelRatio, height ) { + function refreshFogUniforms( uniforms, fog ) { + + uniforms.fogColor.value.copy( fog.color ); + + if ( fog.isFog ) { + + uniforms.fogNear.value = fog.near; + uniforms.fogFar.value = fog.far; + + } else if ( fog.isFogExp2 ) { + + uniforms.fogDensity.value = fog.density; + + } + + } + + function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) { if ( material.isMeshBasicMaterial ) { @@ -89,12 +103,6 @@ function WebGLMaterials( properties ) { } - if ( material.isShaderMaterial ) { - - material.uniformsNeedUpdate = false; // #15581 - - } - } function refreshUniformsCommon( uniforms, material, environment ) { @@ -376,23 +384,6 @@ function WebGLMaterials( properties ) { } - function refreshUniformsFog( uniforms, fog ) { - - uniforms.fogColor.value.copy( fog.color ); - - if ( fog.isFog ) { - - uniforms.fogNear.value = fog.near; - uniforms.fogFar.value = fog.far; - - } else if ( fog.isFogExp2 ) { - - uniforms.fogDensity.value = fog.density; - - } - - } - function refreshUniformsLambert( uniforms, material ) { if ( material.emissiveMap ) { @@ -669,8 +660,8 @@ function WebGLMaterials( properties ) { } return { - refreshUniforms: refreshUniforms, - refreshUniformsFog: refreshUniformsFog + refreshFogUniforms: refreshFogUniforms, + refreshMaterialUniforms: refreshMaterialUniforms }; }