Skip to content

Commit

Permalink
WebGLMaterials: Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed May 8, 2020
1 parent abc1cb8 commit ec80d5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
12 changes: 9 additions & 3 deletions src/renderers/WebGLRenderer.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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 ) {
Expand Down
53 changes: 22 additions & 31 deletions 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 ) {

Expand Down Expand Up @@ -89,12 +103,6 @@ function WebGLMaterials( properties ) {

}

if ( material.isShaderMaterial ) {

material.uniformsNeedUpdate = false; // #15581

}

}

function refreshUniformsCommon( uniforms, material, environment ) {
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -669,8 +660,8 @@ function WebGLMaterials( properties ) {
}

return {
refreshUniforms: refreshUniforms,
refreshUniformsFog: refreshUniformsFog
refreshFogUniforms: refreshFogUniforms,
refreshMaterialUniforms: refreshMaterialUniforms
};

}
Expand Down

0 comments on commit ec80d5e

Please sign in to comment.