From 61338ff9e7378a32463c07a778252df63fffc4c9 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 15:03:15 +0300 Subject: [PATCH 01/10] introduced WebGLMaterials helper --- src/renderers/WebGLRenderer.js | 662 +---------------------- src/renderers/webgl/WebGLMaterials.d.ts | 12 + src/renderers/webgl/WebGLMaterials.js | 670 ++++++++++++++++++++++++ 3 files changed, 686 insertions(+), 658 deletions(-) create mode 100644 src/renderers/webgl/WebGLMaterials.d.ts create mode 100644 src/renderers/webgl/WebGLMaterials.js diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 528e6e8cbaa43f..ac98ec2cfd1ee9 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -242,7 +242,7 @@ function WebGLRenderer( parameters ) { var extensions, capabilities, state, info; var properties, textures, attributes, geometries, objects; - var programCache, renderLists, renderStates; + var programCache, materials, renderLists, renderStates; var background, morphtargets, bufferRenderer, indexedBufferRenderer; @@ -282,6 +282,7 @@ function WebGLRenderer( parameters ) { objects = new WebGLObjects( _gl, geometries, attributes, info ); morphtargets = new WebGLMorphtargets( _gl ); programCache = new WebGLPrograms( _this, extensions, capabilities ); + materials = new WebGLMaterials(); renderLists = new WebGLRenderLists(); renderStates = new WebGLRenderStates(); @@ -1860,87 +1861,11 @@ function WebGLRenderer( parameters ) { if ( fog && material.fog ) { - refreshUniformsFog( m_uniforms, fog ); + materials.refreshUniformsFog( m_uniforms, fog ); } - if ( material.isMeshBasicMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - - } else if ( material.isMeshLambertMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsLambert( m_uniforms, material ); - - } else if ( material.isMeshToonMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsToon( m_uniforms, material ); - - } else if ( material.isMeshPhongMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsPhong( m_uniforms, material ); - - } else if ( material.isMeshStandardMaterial ) { - - refreshUniformsCommon( m_uniforms, material, environment ); - - if ( material.isMeshPhysicalMaterial ) { - - refreshUniformsPhysical( m_uniforms, material, environment ); - - } else { - - refreshUniformsStandard( m_uniforms, material, environment ); - - } - - } else if ( material.isMeshMatcapMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsMatcap( m_uniforms, material ); - - } else if ( material.isMeshDepthMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsDepth( m_uniforms, material ); - - } else if ( material.isMeshDistanceMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsDistance( m_uniforms, material ); - - } else if ( material.isMeshNormalMaterial ) { - - refreshUniformsCommon( m_uniforms, material ); - refreshUniformsNormal( m_uniforms, material ); - - } else if ( material.isLineBasicMaterial ) { - - refreshUniformsLine( m_uniforms, material ); - - if ( material.isLineDashedMaterial ) { - - refreshUniformsDash( m_uniforms, material ); - - } - - } else if ( material.isPointsMaterial ) { - - refreshUniformsPoints( m_uniforms, material ); - - } else if ( material.isSpriteMaterial ) { - - refreshUniformsSprites( m_uniforms, material ); - - } else if ( material.isShadowMaterial ) { - - m_uniforms.color.value.copy( material.color ); - m_uniforms.opacity.value = material.opacity; - - } + materials.refreshUniforms( m_uniforms, material, environment ); // RectAreaLight Texture // TODO (mrdoob): Find a nicer implementation @@ -1950,12 +1875,6 @@ function WebGLRenderer( parameters ) { WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures ); - if ( material.isShaderMaterial ) { - - material.uniformsNeedUpdate = false; // #15581 - - } - } if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) { @@ -1981,579 +1900,6 @@ function WebGLRenderer( parameters ) { } - // Uniforms (refresh uniforms objects) - - function refreshUniformsCommon( uniforms, material, environment ) { - - uniforms.opacity.value = material.opacity; - - if ( material.color ) { - - uniforms.diffuse.value.copy( material.color ); - - } - - if ( material.emissive ) { - - uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); - - } - - if ( material.map ) { - - uniforms.map.value = material.map; - - } - - if ( material.alphaMap ) { - - uniforms.alphaMap.value = material.alphaMap; - - } - - if ( material.specularMap ) { - - uniforms.specularMap.value = material.specularMap; - - } - - var envMap = material.envMap || environment; - - if ( envMap ) { - - uniforms.envMap.value = envMap; - - uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1; - - uniforms.reflectivity.value = material.reflectivity; - uniforms.refractionRatio.value = material.refractionRatio; - - uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel; - - } - - if ( material.lightMap ) { - - uniforms.lightMap.value = material.lightMap; - uniforms.lightMapIntensity.value = material.lightMapIntensity; - - } - - if ( material.aoMap ) { - - uniforms.aoMap.value = material.aoMap; - uniforms.aoMapIntensity.value = material.aoMapIntensity; - - } - - // uv repeat and offset setting priorities - // 1. color map - // 2. specular map - // 3. normal map - // 4. bump map - // 5. alpha map - // 6. emissive map - - var uvScaleMap; - - if ( material.map ) { - - uvScaleMap = material.map; - - } else if ( material.specularMap ) { - - uvScaleMap = material.specularMap; - - } else if ( material.displacementMap ) { - - uvScaleMap = material.displacementMap; - - } else if ( material.normalMap ) { - - uvScaleMap = material.normalMap; - - } else if ( material.bumpMap ) { - - uvScaleMap = material.bumpMap; - - } else if ( material.roughnessMap ) { - - uvScaleMap = material.roughnessMap; - - } else if ( material.metalnessMap ) { - - uvScaleMap = material.metalnessMap; - - } else if ( material.alphaMap ) { - - uvScaleMap = material.alphaMap; - - } else if ( material.emissiveMap ) { - - uvScaleMap = material.emissiveMap; - - } - - if ( uvScaleMap !== undefined ) { - - // backwards compatibility - if ( uvScaleMap.isWebGLRenderTarget ) { - - uvScaleMap = uvScaleMap.texture; - - } - - if ( uvScaleMap.matrixAutoUpdate === true ) { - - uvScaleMap.updateMatrix(); - - } - - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); - - } - - // uv repeat and offset setting priorities for uv2 - // 1. ao map - // 2. light map - - var uv2ScaleMap; - - if ( material.aoMap ) { - - uv2ScaleMap = material.aoMap; - - } else if ( material.lightMap ) { - - uv2ScaleMap = material.lightMap; - - } - - if ( uv2ScaleMap !== undefined ) { - - // backwards compatibility - if ( uv2ScaleMap.isWebGLRenderTarget ) { - - uv2ScaleMap = uv2ScaleMap.texture; - - } - - if ( uv2ScaleMap.matrixAutoUpdate === true ) { - - uv2ScaleMap.updateMatrix(); - - } - - uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix ); - - } - - } - - function refreshUniformsLine( uniforms, material ) { - - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; - - } - - function refreshUniformsDash( uniforms, material ) { - - uniforms.dashSize.value = material.dashSize; - uniforms.totalSize.value = material.dashSize + material.gapSize; - uniforms.scale.value = material.scale; - - } - - function refreshUniformsPoints( uniforms, material ) { - - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; - uniforms.size.value = material.size * _pixelRatio; - uniforms.scale.value = _height * 0.5; - - if ( material.map ) { - - uniforms.map.value = material.map; - - } - - if ( material.alphaMap ) { - - uniforms.alphaMap.value = material.alphaMap; - - } - - // uv repeat and offset setting priorities - // 1. color map - // 2. alpha map - - var uvScaleMap; - - if ( material.map ) { - - uvScaleMap = material.map; - - } else if ( material.alphaMap ) { - - uvScaleMap = material.alphaMap; - - } - - if ( uvScaleMap !== undefined ) { - - if ( uvScaleMap.matrixAutoUpdate === true ) { - - uvScaleMap.updateMatrix(); - - } - - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); - - } - - } - - function refreshUniformsSprites( uniforms, material ) { - - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; - uniforms.rotation.value = material.rotation; - - if ( material.map ) { - - uniforms.map.value = material.map; - - } - - if ( material.alphaMap ) { - - uniforms.alphaMap.value = material.alphaMap; - - } - - // uv repeat and offset setting priorities - // 1. color map - // 2. alpha map - - var uvScaleMap; - - if ( material.map ) { - - uvScaleMap = material.map; - - } else if ( material.alphaMap ) { - - uvScaleMap = material.alphaMap; - - } - - if ( uvScaleMap !== undefined ) { - - if ( uvScaleMap.matrixAutoUpdate === true ) { - - uvScaleMap.updateMatrix(); - - } - - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); - - } - - } - - 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 ) { - - uniforms.emissiveMap.value = material.emissiveMap; - - } - - } - - function refreshUniformsPhong( uniforms, material ) { - - uniforms.specular.value.copy( material.specular ); - uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) - - if ( material.emissiveMap ) { - - uniforms.emissiveMap.value = material.emissiveMap; - - } - - if ( material.bumpMap ) { - - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - - } - - if ( material.normalMap ) { - - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - - } - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - } - - function refreshUniformsToon( uniforms, material ) { - - uniforms.specular.value.copy( material.specular ); - uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) - - if ( material.gradientMap ) { - - uniforms.gradientMap.value = material.gradientMap; - - } - - if ( material.emissiveMap ) { - - uniforms.emissiveMap.value = material.emissiveMap; - - } - - if ( material.bumpMap ) { - - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - - } - - if ( material.normalMap ) { - - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - - } - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - } - - function refreshUniformsStandard( uniforms, material, environment ) { - - uniforms.roughness.value = material.roughness; - uniforms.metalness.value = material.metalness; - - if ( material.roughnessMap ) { - - uniforms.roughnessMap.value = material.roughnessMap; - - } - - if ( material.metalnessMap ) { - - uniforms.metalnessMap.value = material.metalnessMap; - - } - - if ( material.emissiveMap ) { - - uniforms.emissiveMap.value = material.emissiveMap; - - } - - if ( material.bumpMap ) { - - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - - } - - if ( material.normalMap ) { - - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - - } - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - if ( material.envMap || environment ) { - - //uniforms.envMap.value = material.envMap; // part of uniforms common - uniforms.envMapIntensity.value = material.envMapIntensity; - - } - - } - - function refreshUniformsPhysical( uniforms, material, environment ) { - - refreshUniformsStandard( uniforms, material, environment ); - - uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common - - uniforms.clearcoat.value = material.clearcoat; - uniforms.clearcoatRoughness.value = material.clearcoatRoughness; - if ( material.sheen ) uniforms.sheen.value.copy( material.sheen ); - - if ( material.clearcoatMap ) { - - uniforms.clearcoatMap.value = material.clearcoatMap; - - } - - if ( material.clearcoatRoughnessMap ) { - - uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; - - } - - if ( material.clearcoatNormalMap ) { - - uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); - uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; - - if ( material.side === BackSide ) { - - uniforms.clearcoatNormalScale.value.negate(); - - } - - } - - uniforms.transparency.value = material.transparency; - - } - - function refreshUniformsMatcap( uniforms, material ) { - - if ( material.matcap ) { - - uniforms.matcap.value = material.matcap; - - } - - if ( material.bumpMap ) { - - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - - } - - if ( material.normalMap ) { - - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - - } - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - } - - function refreshUniformsDepth( uniforms, material ) { - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - } - - function refreshUniformsDistance( uniforms, material ) { - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - uniforms.referencePosition.value.copy( material.referencePosition ); - uniforms.nearDistance.value = material.nearDistance; - uniforms.farDistance.value = material.farDistance; - - } - - function refreshUniformsNormal( uniforms, material ) { - - if ( material.bumpMap ) { - - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - - } - - if ( material.normalMap ) { - - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - - } - - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; - - } - - } - // If uniforms are marked as clean, they don't need to be loaded to the GPU. function markUniformsLightsNeedsUpdate( uniforms, value ) { diff --git a/src/renderers/webgl/WebGLMaterials.d.ts b/src/renderers/webgl/WebGLMaterials.d.ts new file mode 100644 index 00000000000000..5eea65c7804b36 --- /dev/null +++ b/src/renderers/webgl/WebGLMaterials.d.ts @@ -0,0 +1,12 @@ +import { Material } from "../../materials/Material"; +import { Texture } from "../../textures/Texture"; +import { IFog } from "../../scenes/Fog"; + +export class WebGLMaterials { + + constructor(); + + refreshUniforms( uniforms: object, material: Material, environment: Texture ); + refreshUniformsFog( uniforms: object, fog: IFog ); + +} diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js new file mode 100644 index 00000000000000..41d1063002271a --- /dev/null +++ b/src/renderers/webgl/WebGLMaterials.js @@ -0,0 +1,670 @@ +import { BackSide } from "../../constants"; + +/** + * @author taphos / https://github.com/taphos + * + * This is a helper which deals with webgl specific logic of builtin materials + * i.e. uniforms refresh before material is being rendered + */ + +function WebGLMaterials() { +} + +WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, environment ) { + + if ( material.isMeshBasicMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + + } else if ( material.isMeshLambertMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsLambert( uniforms, material ); + + } else if ( material.isMeshToonMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsToon( uniforms, material ); + + } else if ( material.isMeshPhongMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsPhong( uniforms, material ); + + } else if ( material.isMeshStandardMaterial ) { + + this.refreshUniformsCommon( uniforms, material, environment ); + + if ( material.isMeshPhysicalMaterial ) { + + this.refreshUniformsPhysical( uniforms, material, environment ); + + } else { + + this.refreshUniformsStandard( uniforms, material, environment ); + + } + + } else if ( material.isMeshMatcapMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsMatcap( uniforms, material ); + + } else if ( material.isMeshDepthMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsDepth( uniforms, material ); + + } else if ( material.isMeshDistanceMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsDistance( uniforms, material ); + + } else if ( material.isMeshNormalMaterial ) { + + this.refreshUniformsCommon( uniforms, material ); + this.refreshUniformsNormal( uniforms, material ); + + } else if ( material.isLineBasicMaterial ) { + + this.refreshUniformsLine( uniforms, material ); + + if ( material.isLineDashedMaterial ) { + + this.refreshUniformsDash( uniforms, material ); + + } + + } else if ( material.isPointsMaterial ) { + + this.refreshUniformsPoints( uniforms, material ); + + } else if ( material.isSpriteMaterial ) { + + this.refreshUniformsSprites( uniforms, material ); + + } else if ( material.isShadowMaterial ) { + + uniforms.color.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + + } + + if ( material.isShaderMaterial ) { + + material.uniformsNeedUpdate = false; // #15581 + + } + +}; + +WebGLMaterials.prototype.refreshUniformsCommon = function ( uniforms, material, environment ) { + + uniforms.opacity.value = material.opacity; + + if ( material.color ) { + + uniforms.diffuse.value.copy( material.color ); + + } + + if ( material.emissive ) { + + uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); + + } + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + if ( material.specularMap ) { + + uniforms.specularMap.value = material.specularMap; + + } + + var envMap = material.envMap || environment; + + if ( envMap ) { + + uniforms.envMap.value = envMap; + + uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1; + + uniforms.reflectivity.value = material.reflectivity; + uniforms.refractionRatio.value = material.refractionRatio; + + uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel; + + } + + if ( material.lightMap ) { + + uniforms.lightMap.value = material.lightMap; + uniforms.lightMapIntensity.value = material.lightMapIntensity; + + } + + if ( material.aoMap ) { + + uniforms.aoMap.value = material.aoMap; + uniforms.aoMapIntensity.value = material.aoMapIntensity; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. specular map + // 3. normal map + // 4. bump map + // 5. alpha map + // 6. emissive map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.specularMap ) { + + uvScaleMap = material.specularMap; + + } else if ( material.displacementMap ) { + + uvScaleMap = material.displacementMap; + + } else if ( material.normalMap ) { + + uvScaleMap = material.normalMap; + + } else if ( material.bumpMap ) { + + uvScaleMap = material.bumpMap; + + } else if ( material.roughnessMap ) { + + uvScaleMap = material.roughnessMap; + + } else if ( material.metalnessMap ) { + + uvScaleMap = material.metalnessMap; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } else if ( material.emissiveMap ) { + + uvScaleMap = material.emissiveMap; + + } + + if ( uvScaleMap !== undefined ) { + + // backwards compatibility + if ( uvScaleMap.isWebGLRenderTarget ) { + + uvScaleMap = uvScaleMap.texture; + + } + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + + // uv repeat and offset setting priorities for uv2 + // 1. ao map + // 2. light map + + var uv2ScaleMap; + + if ( material.aoMap ) { + + uv2ScaleMap = material.aoMap; + + } else if ( material.lightMap ) { + + uv2ScaleMap = material.lightMap; + + } + + if ( uv2ScaleMap !== undefined ) { + + // backwards compatibility + if ( uv2ScaleMap.isWebGLRenderTarget ) { + + uv2ScaleMap = uv2ScaleMap.texture; + + } + + if ( uv2ScaleMap.matrixAutoUpdate === true ) { + + uv2ScaleMap.updateMatrix(); + + } + + uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix ); + + } + +}; + +WebGLMaterials.prototype.refreshUniformsLine = function ( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + +}; + +WebGLMaterials.prototype.refreshUniformsDash = function ( uniforms, material ) { + + uniforms.dashSize.value = material.dashSize; + uniforms.totalSize.value = material.dashSize + material.gapSize; + uniforms.scale.value = material.scale; + +}; + +WebGLMaterials.prototype.refreshUniformsPoints = function ( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.size.value = material.size * _pixelRatio; + uniforms.scale.value = _height * 0.5; + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } + + if ( uvScaleMap !== undefined ) { + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + +}; + +WebGLMaterials.prototype.refreshUniformsSprites = function ( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.rotation.value = material.rotation; + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } + + if ( uvScaleMap !== undefined ) { + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + +}; + +WebGLMaterials.prototype.refreshUniformsFog = function ( 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; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsLambert = function ( uniforms, material ) { + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsPhong = function ( uniforms, material ) { + + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsToon = function ( uniforms, material ) { + + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + + if ( material.gradientMap ) { + + uniforms.gradientMap.value = material.gradientMap; + + } + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsStandard = function ( uniforms, material, environment ) { + + uniforms.roughness.value = material.roughness; + uniforms.metalness.value = material.metalness; + + if ( material.roughnessMap ) { + + uniforms.roughnessMap.value = material.roughnessMap; + + } + + if ( material.metalnessMap ) { + + uniforms.metalnessMap.value = material.metalnessMap; + + } + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + if ( material.envMap || environment ) { + + //uniforms.envMap.value = material.envMap; // part of uniforms common + uniforms.envMapIntensity.value = material.envMapIntensity; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsPhysical = function ( uniforms, material, environment ) { + + this.refreshUniformsStandard( uniforms, material, environment ); + + uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common + + uniforms.clearcoat.value = material.clearcoat; + uniforms.clearcoatRoughness.value = material.clearcoatRoughness; + if ( material.sheen ) uniforms.sheen.value.copy( material.sheen ); + + if ( material.clearcoatMap ) { + + uniforms.clearcoatMap.value = material.clearcoatMap; + + } + + if ( material.clearcoatRoughnessMap ) { + + uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; + + } + + if ( material.clearcoatNormalMap ) { + + uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); + uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; + + if ( material.side === BackSide ) { + + uniforms.clearcoatNormalScale.value.negate(); + + } + + } + + uniforms.transparency.value = material.transparency; + +}; + +WebGLMaterials.prototype.refreshUniformsMatcap = function ( uniforms, material ) { + + if ( material.matcap ) { + + uniforms.matcap.value = material.matcap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsDepth = function ( uniforms, material ) { + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + +}; + +WebGLMaterials.prototype.refreshUniformsDistance = function ( uniforms, material ) { + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + uniforms.referencePosition.value.copy( material.referencePosition ); + uniforms.nearDistance.value = material.nearDistance; + uniforms.farDistance.value = material.farDistance; + +}; + +WebGLMaterials.prototype.refreshUniformsNormal = function ( uniforms, material ) { + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + +}; From 795de77840d9ca1b455d068fda6a5efaeb5f1d36 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 15:06:39 +0300 Subject: [PATCH 02/10] added missing import --- src/renderers/WebGLRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index ac98ec2cfd1ee9..87e7383d7705b9 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -13,7 +13,6 @@ import { UnsignedByteType, LinearEncoding, NoToneMapping, - BackSide } from '../constants.js'; import { MathUtils } from '../math/MathUtils.js'; import { DataTexture } from '../textures/DataTexture.js'; @@ -46,6 +45,7 @@ import { WebGLTextures } from './webgl/WebGLTextures.js'; import { WebGLUniforms } from './webgl/WebGLUniforms.js'; import { WebGLUtils } from './webgl/WebGLUtils.js'; import { WebXRManager } from './webxr/WebXRManager.js'; +import { WebGLMaterials } from "./webgl/WebGLMaterials.js"; function WebGLRenderer( parameters ) { From 8f7ff78333350b7d17aee86f5787e8245bbcf689 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 15:24:53 +0300 Subject: [PATCH 03/10] fix export --- src/renderers/webgl/WebGLMaterials.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 41d1063002271a..34c8081efc4f0a 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -668,3 +668,5 @@ WebGLMaterials.prototype.refreshUniformsNormal = function ( uniforms, material ) } }; + +export { WebGLMaterials }; From 511b249746cc1ab6b2a41606547c2499aa313547 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 15:38:35 +0300 Subject: [PATCH 04/10] WebGLRenderer helpers are exposed to public API --- src/Three.d.ts | 8 +++++++ src/Three.js | 12 ++++++++++ src/renderers/WebGLRenderer.d.ts | 34 ++++++++++++++++++++++++++++ src/renderers/WebGLRenderer.js | 38 ++++++++++++++++---------------- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/src/Three.d.ts b/src/Three.d.ts index 0a35428033da03..9771c69e88d191 100644 --- a/src/Three.d.ts +++ b/src/Three.d.ts @@ -170,6 +170,14 @@ export * from './renderers/webgl/WebGLShadowMap'; export * from './renderers/webgl/WebGLState'; export * from './renderers/webgl/WebGLTextures'; export * from './renderers/webgl/WebGLUniforms'; +export * from './renderers/webgl/WebGLUtils'; +export * from './renderers/webgl/WebGLMaterials'; +export * from './renderers/webgl/WebGLGeometries'; +export * from './renderers/webgl/WebGLAttributes'; +export * from './renderers/webgl/WebGLRenderStates'; +export * from './renderers/webgl/WebGLBackground'; +export * from './renderers/webgl/WebGLAnimation'; +export * from './renderers/webgl/WebGLMorphtargets'; export * from './constants'; export * from './Three.Legacy'; diff --git a/src/Three.js b/src/Three.js index 2b05d270da1762..2dd67df056363e 100644 --- a/src/Three.js +++ b/src/Three.js @@ -154,6 +154,18 @@ export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; export { PMREMGenerator } from './extras/PMREMGenerator.js'; export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; +export { WebGLMaterials } from './renderers/webgl/WebGLMaterials.js'; +export { WebGLPrograms } from './renderers/webgl/WebGLPrograms.js'; +export { WebGLObjects } from './renderers/webgl/WebGLObjects.js'; +export { WebGLGeometries } from './renderers/webgl/WebGLGeometries.js'; +export { WebGLAttributes } from './renderers/webgl/WebGLAttributes.js'; +export { WebGLTextures } from './renderers/webgl/WebGLTextures.js'; +export { WebGLRenderStates } from './renderers/webgl/WebGLRenderStates.js'; +export { WebGLBackground } from './renderers/webgl/WebGLBackground.js'; +export { WebGLBufferRenderer } from './renderers/webgl/WebGLBufferRenderer.js'; +export { WebGLIndexedBufferRenderer } from './renderers/webgl/WebGLIndexedBufferRenderer.js'; +export { WebGLAnimation } from './renderers/webgl/WebGLAnimation.js'; +export { WebGLMorphtargets } from './renderers/webgl/WebGLMorphtargets.js'; export * from './constants.js'; export * from './Three.Legacy.js'; diff --git a/src/renderers/WebGLRenderer.d.ts b/src/renderers/WebGLRenderer.d.ts index f6baa15f50e872..85a36e1aa4ca88 100644 --- a/src/renderers/WebGLRenderer.d.ts +++ b/src/renderers/WebGLRenderer.d.ts @@ -20,6 +20,19 @@ import { RenderTarget } from './webgl/WebGLRenderLists'; import { Geometry } from './../core/Geometry'; import { BufferGeometry } from './../core/BufferGeometry'; import { Texture } from '../textures/Texture'; +import { WebGLMaterials } from './webgl/WebGLMaterials'; +import { WebGLPrograms } from './webgl/WebGLPrograms'; +import { WebGLObjects } from './webgl/WebGLObjects'; +import { WebGLGeometries } from './webgl/WebGLGeometries'; +import { WebGLAttributes } from './webgl/WebGLAttributes'; +import { WebGLTextures } from './webgl/WebGLTextures'; +import { WebGLRenderStates } from './webgl/WebGLRenderStates'; +import { WebGLBackground } from './webgl/WebGLBackground'; +import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer'; +import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer'; +import { WebGLUtils } from './webgl/WebGLUtils'; +import { WebGLAnimation } from './webgl/WebGLAnimation'; +import { WebGLMorphtargets } from './webgl/WebGLMorphtargets'; export interface Renderer { domElement: HTMLCanvasElement; @@ -85,6 +98,27 @@ export interface WebGLRendererParameters { * default is false. */ logarithmicDepthBuffer?: boolean; + + /** + * Custom WebGLRenderer helpers, all null by default + * Should be used for rendering pipeline customization + */ + textures?: WebGLTextures; + attributes?: WebGLAttributes; + geometries?: WebGLGeometries; + objects?: WebGLObjects; + programCache?: WebGLPrograms; + materials?: WebGLMaterials; + renderStates?: WebGLRenderStates; + background?: WebGLBackground; + bufferRenderer?: WebGLBufferRenderer; + indexedBufferRenderer?: WebGLIndexedBufferRenderer; + utils?: WebGLUtils; + renderLists?: WebGLRenderLists; + animation?: WebGLAnimation; + morphtargets?: WebGLMorphtargets; + shadowMap?: WebGLShadowMap; + xr?: WebXRManager; } export interface WebGLDebug { diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 87e7383d7705b9..61c37123b28f91 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -268,28 +268,28 @@ function WebGLRenderer( parameters ) { extensions.get( 'OES_texture_float_linear' ); - utils = new WebGLUtils( _gl, extensions, capabilities ); + utils = parameters.utils !== undefined ? parameters.utils : new WebGLUtils( _gl, extensions, capabilities ); - state = new WebGLState( _gl, extensions, capabilities ); + state = parameters.state !== undefined ? parameters.state : new WebGLState( _gl, extensions, capabilities ); state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() ); state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() ); - info = new WebGLInfo( _gl ); - properties = new WebGLProperties(); - textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); - attributes = new WebGLAttributes( _gl, capabilities ); - geometries = new WebGLGeometries( _gl, attributes, info ); - objects = new WebGLObjects( _gl, geometries, attributes, info ); - morphtargets = new WebGLMorphtargets( _gl ); - programCache = new WebGLPrograms( _this, extensions, capabilities ); - materials = new WebGLMaterials(); - renderLists = new WebGLRenderLists(); - renderStates = new WebGLRenderStates(); + info = parameters.info !== undefined ? parameters.info : new WebGLInfo( _gl ); + properties = parameters.properties !== undefined ? parameters.properties : new WebGLProperties(); + textures = parameters.textures !== undefined ? parameters.textures : new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); + attributes = parameters.attributes !== undefined ? parameters.attributes : new WebGLAttributes( _gl, capabilities ); + geometries = parameters.geometries !== undefined ? parameters.geometries : new WebGLGeometries( _gl, attributes, info ); + objects = parameters.objects !== undefined ? parameters.objects : new WebGLObjects( _gl, geometries, attributes, info ); + morphtargets = parameters.morphtargets !== undefined ? parameters.morphtargets : new WebGLMorphtargets( _gl ); + programCache = parameters.programCache !== undefined ? parameters.programCache : new WebGLPrograms( _this, extensions, capabilities ); + materials = parameters.materials !== undefined ? parameters.materials : new WebGLMaterials(); + renderLists = parameters.renderLists !== undefined ? parameters.renderLists : new WebGLRenderLists(); + renderStates = parameters.renderStates !== undefined ? parameters.renderStates : new WebGLRenderStates(); - background = new WebGLBackground( _this, state, objects, _premultipliedAlpha ); + background = parameters.background !== undefined ? parameters.background : new WebGLBackground( _this, state, objects, _premultipliedAlpha ); - bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities ); - indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities ); + bufferRenderer = parameters.bufferRenderer !== undefined ? parameters.bufferRenderer : new WebGLBufferRenderer( _gl, extensions, info, capabilities ); + indexedBufferRenderer = parameters.indexedBufferRenderer !== undefined ? parameters.indexedBufferRenderer : new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities ); info.programs = programCache.programs; @@ -306,13 +306,13 @@ function WebGLRenderer( parameters ) { // xr - var xr = new WebXRManager( _this, _gl ); + var xr = parameters.xr !== undefined ? parameters.xr : new WebXRManager( _this, _gl ); this.xr = xr; // shadow map - var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); + var shadowMap = parameters.shadowMap !== undefined ? parameters.shadowMap : new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); this.shadowMap = shadowMap; @@ -1100,7 +1100,7 @@ function WebGLRenderer( parameters ) { } - var animation = new WebGLAnimation(); + var animation = parameters.animation !== undefined ? parameters.animation : new WebGLAnimation(); animation.setAnimationLoop( onAnimationFrame ); if ( typeof window !== 'undefined' ) animation.setContext( window ); From 0ec36acdb874494eb95d23376691ce19246023a9 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 15:57:41 +0300 Subject: [PATCH 05/10] WebGLMaterials also requires properties, pixelRatio and screen height --- src/renderers/WebGLRenderer.js | 4 ++-- src/renderers/webgl/WebGLMaterials.d.ts | 5 +++-- src/renderers/webgl/WebGLMaterials.js | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 61c37123b28f91..bbafe58f127c5f 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -282,7 +282,7 @@ function WebGLRenderer( parameters ) { objects = parameters.objects !== undefined ? parameters.objects : new WebGLObjects( _gl, geometries, attributes, info ); morphtargets = parameters.morphtargets !== undefined ? parameters.morphtargets : new WebGLMorphtargets( _gl ); programCache = parameters.programCache !== undefined ? parameters.programCache : new WebGLPrograms( _this, extensions, capabilities ); - materials = parameters.materials !== undefined ? parameters.materials : new WebGLMaterials(); + materials = parameters.materials !== undefined ? parameters.materials : new WebGLMaterials( properties ); renderLists = parameters.renderLists !== undefined ? parameters.renderLists : new WebGLRenderLists(); renderStates = parameters.renderStates !== undefined ? parameters.renderStates : new WebGLRenderStates(); @@ -1865,7 +1865,7 @@ function WebGLRenderer( parameters ) { } - materials.refreshUniforms( m_uniforms, material, environment ); + materials.refreshUniforms( m_uniforms, material, environment, _pixelRatio, _height ); // RectAreaLight Texture // TODO (mrdoob): Find a nicer implementation diff --git a/src/renderers/webgl/WebGLMaterials.d.ts b/src/renderers/webgl/WebGLMaterials.d.ts index 5eea65c7804b36..29a60f28b90e61 100644 --- a/src/renderers/webgl/WebGLMaterials.d.ts +++ b/src/renderers/webgl/WebGLMaterials.d.ts @@ -1,12 +1,13 @@ import { Material } from "../../materials/Material"; import { Texture } from "../../textures/Texture"; import { IFog } from "../../scenes/Fog"; +import { WebGLProperties } from "./WebGLProperties"; export class WebGLMaterials { - constructor(); + constructor( properties: WebGLProperties ); - refreshUniforms( uniforms: object, material: Material, environment: Texture ); + refreshUniforms( uniforms: object, material: Material, environment: Texture, pixelRatio: number, height: number ); refreshUniformsFog( uniforms: object, fog: IFog ); } diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 34c8081efc4f0a..3eb016dbaa9dc6 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -7,10 +7,15 @@ import { BackSide } from "../../constants"; * i.e. uniforms refresh before material is being rendered */ -function WebGLMaterials() { +var _properties; + +function WebGLMaterials( properties ) { + + _properties = properties; + } -WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, environment ) { +WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, environment, pixelRatio, height ) { if ( material.isMeshBasicMaterial ) { @@ -77,7 +82,7 @@ WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, enviro } else if ( material.isPointsMaterial ) { - this.refreshUniformsPoints( uniforms, material ); + this.refreshUniformsPoints( uniforms, material, pixelRatio, height ); } else if ( material.isSpriteMaterial ) { @@ -143,7 +148,7 @@ WebGLMaterials.prototype.refreshUniformsCommon = function ( uniforms, material, uniforms.reflectivity.value = material.reflectivity; uniforms.refractionRatio.value = material.refractionRatio; - uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel; + uniforms.maxMipLevel.value = _properties.get( envMap ).__maxMipLevel; } @@ -280,12 +285,12 @@ WebGLMaterials.prototype.refreshUniformsDash = function ( uniforms, material ) { }; -WebGLMaterials.prototype.refreshUniformsPoints = function ( uniforms, material ) { +WebGLMaterials.prototype.refreshUniformsPoints = function ( uniforms, material, pixelRatio, height ) { uniforms.diffuse.value.copy( material.color ); uniforms.opacity.value = material.opacity; - uniforms.size.value = material.size * _pixelRatio; - uniforms.scale.value = _height * 0.5; + uniforms.size.value = material.size * pixelRatio; + uniforms.scale.value = height * 0.5; if ( material.map ) { From ed283ae13025111888a030be6e92d7c2de37ed21 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 17:00:56 +0300 Subject: [PATCH 06/10] Revert "WebGLRenderer helpers are exposed to public API" This reverts commit 511b2497 --- src/Three.d.ts | 8 ------- src/Three.js | 12 ---------- src/renderers/WebGLRenderer.d.ts | 34 ---------------------------- src/renderers/WebGLRenderer.js | 38 ++++++++++++++++---------------- 4 files changed, 19 insertions(+), 73 deletions(-) diff --git a/src/Three.d.ts b/src/Three.d.ts index 9771c69e88d191..0a35428033da03 100644 --- a/src/Three.d.ts +++ b/src/Three.d.ts @@ -170,14 +170,6 @@ export * from './renderers/webgl/WebGLShadowMap'; export * from './renderers/webgl/WebGLState'; export * from './renderers/webgl/WebGLTextures'; export * from './renderers/webgl/WebGLUniforms'; -export * from './renderers/webgl/WebGLUtils'; -export * from './renderers/webgl/WebGLMaterials'; -export * from './renderers/webgl/WebGLGeometries'; -export * from './renderers/webgl/WebGLAttributes'; -export * from './renderers/webgl/WebGLRenderStates'; -export * from './renderers/webgl/WebGLBackground'; -export * from './renderers/webgl/WebGLAnimation'; -export * from './renderers/webgl/WebGLMorphtargets'; export * from './constants'; export * from './Three.Legacy'; diff --git a/src/Three.js b/src/Three.js index 2dd67df056363e..2b05d270da1762 100644 --- a/src/Three.js +++ b/src/Three.js @@ -154,18 +154,6 @@ export { ImageUtils } from './extras/ImageUtils.js'; export { ShapeUtils } from './extras/ShapeUtils.js'; export { PMREMGenerator } from './extras/PMREMGenerator.js'; export { WebGLUtils } from './renderers/webgl/WebGLUtils.js'; -export { WebGLMaterials } from './renderers/webgl/WebGLMaterials.js'; -export { WebGLPrograms } from './renderers/webgl/WebGLPrograms.js'; -export { WebGLObjects } from './renderers/webgl/WebGLObjects.js'; -export { WebGLGeometries } from './renderers/webgl/WebGLGeometries.js'; -export { WebGLAttributes } from './renderers/webgl/WebGLAttributes.js'; -export { WebGLTextures } from './renderers/webgl/WebGLTextures.js'; -export { WebGLRenderStates } from './renderers/webgl/WebGLRenderStates.js'; -export { WebGLBackground } from './renderers/webgl/WebGLBackground.js'; -export { WebGLBufferRenderer } from './renderers/webgl/WebGLBufferRenderer.js'; -export { WebGLIndexedBufferRenderer } from './renderers/webgl/WebGLIndexedBufferRenderer.js'; -export { WebGLAnimation } from './renderers/webgl/WebGLAnimation.js'; -export { WebGLMorphtargets } from './renderers/webgl/WebGLMorphtargets.js'; export * from './constants.js'; export * from './Three.Legacy.js'; diff --git a/src/renderers/WebGLRenderer.d.ts b/src/renderers/WebGLRenderer.d.ts index 85a36e1aa4ca88..f6baa15f50e872 100644 --- a/src/renderers/WebGLRenderer.d.ts +++ b/src/renderers/WebGLRenderer.d.ts @@ -20,19 +20,6 @@ import { RenderTarget } from './webgl/WebGLRenderLists'; import { Geometry } from './../core/Geometry'; import { BufferGeometry } from './../core/BufferGeometry'; import { Texture } from '../textures/Texture'; -import { WebGLMaterials } from './webgl/WebGLMaterials'; -import { WebGLPrograms } from './webgl/WebGLPrograms'; -import { WebGLObjects } from './webgl/WebGLObjects'; -import { WebGLGeometries } from './webgl/WebGLGeometries'; -import { WebGLAttributes } from './webgl/WebGLAttributes'; -import { WebGLTextures } from './webgl/WebGLTextures'; -import { WebGLRenderStates } from './webgl/WebGLRenderStates'; -import { WebGLBackground } from './webgl/WebGLBackground'; -import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer'; -import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer'; -import { WebGLUtils } from './webgl/WebGLUtils'; -import { WebGLAnimation } from './webgl/WebGLAnimation'; -import { WebGLMorphtargets } from './webgl/WebGLMorphtargets'; export interface Renderer { domElement: HTMLCanvasElement; @@ -98,27 +85,6 @@ export interface WebGLRendererParameters { * default is false. */ logarithmicDepthBuffer?: boolean; - - /** - * Custom WebGLRenderer helpers, all null by default - * Should be used for rendering pipeline customization - */ - textures?: WebGLTextures; - attributes?: WebGLAttributes; - geometries?: WebGLGeometries; - objects?: WebGLObjects; - programCache?: WebGLPrograms; - materials?: WebGLMaterials; - renderStates?: WebGLRenderStates; - background?: WebGLBackground; - bufferRenderer?: WebGLBufferRenderer; - indexedBufferRenderer?: WebGLIndexedBufferRenderer; - utils?: WebGLUtils; - renderLists?: WebGLRenderLists; - animation?: WebGLAnimation; - morphtargets?: WebGLMorphtargets; - shadowMap?: WebGLShadowMap; - xr?: WebXRManager; } export interface WebGLDebug { diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index bbafe58f127c5f..545629c59fe08d 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -268,28 +268,28 @@ function WebGLRenderer( parameters ) { extensions.get( 'OES_texture_float_linear' ); - utils = parameters.utils !== undefined ? parameters.utils : new WebGLUtils( _gl, extensions, capabilities ); + utils = new WebGLUtils( _gl, extensions, capabilities ); - state = parameters.state !== undefined ? parameters.state : new WebGLState( _gl, extensions, capabilities ); + state = new WebGLState( _gl, extensions, capabilities ); state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() ); state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() ); - info = parameters.info !== undefined ? parameters.info : new WebGLInfo( _gl ); - properties = parameters.properties !== undefined ? parameters.properties : new WebGLProperties(); - textures = parameters.textures !== undefined ? parameters.textures : new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); - attributes = parameters.attributes !== undefined ? parameters.attributes : new WebGLAttributes( _gl, capabilities ); - geometries = parameters.geometries !== undefined ? parameters.geometries : new WebGLGeometries( _gl, attributes, info ); - objects = parameters.objects !== undefined ? parameters.objects : new WebGLObjects( _gl, geometries, attributes, info ); - morphtargets = parameters.morphtargets !== undefined ? parameters.morphtargets : new WebGLMorphtargets( _gl ); - programCache = parameters.programCache !== undefined ? parameters.programCache : new WebGLPrograms( _this, extensions, capabilities ); - materials = parameters.materials !== undefined ? parameters.materials : new WebGLMaterials( properties ); - renderLists = parameters.renderLists !== undefined ? parameters.renderLists : new WebGLRenderLists(); - renderStates = parameters.renderStates !== undefined ? parameters.renderStates : new WebGLRenderStates(); + info = new WebGLInfo( _gl ); + properties = new WebGLProperties(); + textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); + attributes = new WebGLAttributes( _gl, capabilities ); + geometries = new WebGLGeometries( _gl, attributes, info ); + objects = new WebGLObjects( _gl, geometries, attributes, info ); + morphtargets = new WebGLMorphtargets( _gl ); + programCache = new WebGLPrograms( _this, extensions, capabilities ); + materials = new WebGLMaterials(); + renderLists = new WebGLRenderLists(); + renderStates = new WebGLRenderStates(); - background = parameters.background !== undefined ? parameters.background : new WebGLBackground( _this, state, objects, _premultipliedAlpha ); + background = new WebGLBackground( _this, state, objects, _premultipliedAlpha ); - bufferRenderer = parameters.bufferRenderer !== undefined ? parameters.bufferRenderer : new WebGLBufferRenderer( _gl, extensions, info, capabilities ); - indexedBufferRenderer = parameters.indexedBufferRenderer !== undefined ? parameters.indexedBufferRenderer : new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities ); + bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities ); + indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities ); info.programs = programCache.programs; @@ -306,13 +306,13 @@ function WebGLRenderer( parameters ) { // xr - var xr = parameters.xr !== undefined ? parameters.xr : new WebXRManager( _this, _gl ); + var xr = new WebXRManager( _this, _gl ); this.xr = xr; // shadow map - var shadowMap = parameters.shadowMap !== undefined ? parameters.shadowMap : new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); + var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); this.shadowMap = shadowMap; @@ -1100,7 +1100,7 @@ function WebGLRenderer( parameters ) { } - var animation = parameters.animation !== undefined ? parameters.animation : new WebGLAnimation(); + var animation = new WebGLAnimation(); animation.setAnimationLoop( onAnimationFrame ); if ( typeof window !== 'undefined' ) animation.setContext( window ); From de5143943cadc49297fc61b0e271364b1dbaaaac Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 17:14:04 +0300 Subject: [PATCH 07/10] fix materials initialization --- src/renderers/WebGLRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 545629c59fe08d..0a2f4bcac53773 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -282,7 +282,7 @@ function WebGLRenderer( parameters ) { objects = new WebGLObjects( _gl, geometries, attributes, info ); morphtargets = new WebGLMorphtargets( _gl ); programCache = new WebGLPrograms( _this, extensions, capabilities ); - materials = new WebGLMaterials(); + materials = new WebGLMaterials( properties ); renderLists = new WebGLRenderLists(); renderStates = new WebGLRenderStates(); From b0550ecd1a9b20fbb9d213653cf86494d2f02d37 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 19:33:45 +0300 Subject: [PATCH 08/10] "sealed" private functions --- src/renderers/webgl/WebGLMaterials.js | 102 +++++++++++++------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 3eb016dbaa9dc6..cd64cca4a7bf91 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -19,74 +19,74 @@ WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, enviro if ( material.isMeshBasicMaterial ) { - this.refreshUniformsCommon( uniforms, material ); + refreshUniformsCommon( uniforms, material ); } else if ( material.isMeshLambertMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsLambert( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsLambert( uniforms, material ); } else if ( material.isMeshToonMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsToon( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsToon( uniforms, material ); } else if ( material.isMeshPhongMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsPhong( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsPhong( uniforms, material ); } else if ( material.isMeshStandardMaterial ) { - this.refreshUniformsCommon( uniforms, material, environment ); + refreshUniformsCommon( uniforms, material, environment ); if ( material.isMeshPhysicalMaterial ) { - this.refreshUniformsPhysical( uniforms, material, environment ); + refreshUniformsPhysical( uniforms, material, environment ); } else { - this.refreshUniformsStandard( uniforms, material, environment ); + refreshUniformsStandard( uniforms, material, environment ); } } else if ( material.isMeshMatcapMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsMatcap( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsMatcap( uniforms, material ); } else if ( material.isMeshDepthMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsDepth( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsDepth( uniforms, material ); } else if ( material.isMeshDistanceMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsDistance( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsDistance( uniforms, material ); } else if ( material.isMeshNormalMaterial ) { - this.refreshUniformsCommon( uniforms, material ); - this.refreshUniformsNormal( uniforms, material ); + refreshUniformsCommon( uniforms, material ); + refreshUniformsNormal( uniforms, material ); } else if ( material.isLineBasicMaterial ) { - this.refreshUniformsLine( uniforms, material ); + refreshUniformsLine( uniforms, material ); if ( material.isLineDashedMaterial ) { - this.refreshUniformsDash( uniforms, material ); + refreshUniformsDash( uniforms, material ); } } else if ( material.isPointsMaterial ) { - this.refreshUniformsPoints( uniforms, material, pixelRatio, height ); + refreshUniformsPoints( uniforms, material, pixelRatio, height ); } else if ( material.isSpriteMaterial ) { - this.refreshUniformsSprites( uniforms, material ); + refreshUniformsSprites( uniforms, material ); } else if ( material.isShadowMaterial ) { @@ -103,7 +103,7 @@ WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, enviro }; -WebGLMaterials.prototype.refreshUniformsCommon = function ( uniforms, material, environment ) { +function refreshUniformsCommon( uniforms, material, environment ) { uniforms.opacity.value = material.opacity; @@ -268,24 +268,24 @@ WebGLMaterials.prototype.refreshUniformsCommon = function ( uniforms, material, } -}; +} -WebGLMaterials.prototype.refreshUniformsLine = function ( uniforms, material ) { +function refreshUniformsLine( uniforms, material ) { uniforms.diffuse.value.copy( material.color ); uniforms.opacity.value = material.opacity; -}; +} -WebGLMaterials.prototype.refreshUniformsDash = function ( uniforms, material ) { +function refreshUniformsDash( uniforms, material ) { uniforms.dashSize.value = material.dashSize; uniforms.totalSize.value = material.dashSize + material.gapSize; uniforms.scale.value = material.scale; -}; +} -WebGLMaterials.prototype.refreshUniformsPoints = function ( uniforms, material, pixelRatio, height ) { +function refreshUniformsPoints( uniforms, material, pixelRatio, height ) { uniforms.diffuse.value.copy( material.color ); uniforms.opacity.value = material.opacity; @@ -332,9 +332,9 @@ WebGLMaterials.prototype.refreshUniformsPoints = function ( uniforms, material, } -}; +} -WebGLMaterials.prototype.refreshUniformsSprites = function ( uniforms, material ) { +function refreshUniformsSprites( uniforms, material ) { uniforms.diffuse.value.copy( material.color ); uniforms.opacity.value = material.opacity; @@ -380,7 +380,7 @@ WebGLMaterials.prototype.refreshUniformsSprites = function ( uniforms, material } -}; +} WebGLMaterials.prototype.refreshUniformsFog = function ( uniforms, fog ) { @@ -399,7 +399,7 @@ WebGLMaterials.prototype.refreshUniformsFog = function ( uniforms, fog ) { }; -WebGLMaterials.prototype.refreshUniformsLambert = function ( uniforms, material ) { +function refreshUniformsLambert( uniforms, material ) { if ( material.emissiveMap ) { @@ -407,9 +407,9 @@ WebGLMaterials.prototype.refreshUniformsLambert = function ( uniforms, material } -}; +} -WebGLMaterials.prototype.refreshUniformsPhong = function ( uniforms, material ) { +function refreshUniformsPhong( uniforms, material ) { uniforms.specular.value.copy( material.specular ); uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) @@ -444,9 +444,9 @@ WebGLMaterials.prototype.refreshUniformsPhong = function ( uniforms, material ) } -}; +} -WebGLMaterials.prototype.refreshUniformsToon = function ( uniforms, material ) { +function refreshUniformsToon( uniforms, material ) { uniforms.specular.value.copy( material.specular ); uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) @@ -487,9 +487,9 @@ WebGLMaterials.prototype.refreshUniformsToon = function ( uniforms, material ) { } -}; +} -WebGLMaterials.prototype.refreshUniformsStandard = function ( uniforms, material, environment ) { +function refreshUniformsStandard( uniforms, material, environment ) { uniforms.roughness.value = material.roughness; uniforms.metalness.value = material.metalness; @@ -543,11 +543,11 @@ WebGLMaterials.prototype.refreshUniformsStandard = function ( uniforms, material } -}; +} -WebGLMaterials.prototype.refreshUniformsPhysical = function ( uniforms, material, environment ) { +function refreshUniformsPhysical( uniforms, material, environment ) { - this.refreshUniformsStandard( uniforms, material, environment ); + refreshUniformsStandard( uniforms, material, environment ); uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common @@ -582,9 +582,9 @@ WebGLMaterials.prototype.refreshUniformsPhysical = function ( uniforms, material uniforms.transparency.value = material.transparency; -}; +} -WebGLMaterials.prototype.refreshUniformsMatcap = function ( uniforms, material ) { +function refreshUniformsMatcap( uniforms, material ) { if ( material.matcap ) { @@ -616,9 +616,9 @@ WebGLMaterials.prototype.refreshUniformsMatcap = function ( uniforms, material ) } -}; +} -WebGLMaterials.prototype.refreshUniformsDepth = function ( uniforms, material ) { +function refreshUniformsDepth( uniforms, material ) { if ( material.displacementMap ) { @@ -628,9 +628,9 @@ WebGLMaterials.prototype.refreshUniformsDepth = function ( uniforms, material ) } -}; +} -WebGLMaterials.prototype.refreshUniformsDistance = function ( uniforms, material ) { +function refreshUniformsDistance( uniforms, material ) { if ( material.displacementMap ) { @@ -644,9 +644,9 @@ WebGLMaterials.prototype.refreshUniformsDistance = function ( uniforms, material uniforms.nearDistance.value = material.nearDistance; uniforms.farDistance.value = material.farDistance; -}; +} -WebGLMaterials.prototype.refreshUniformsNormal = function ( uniforms, material ) { +function refreshUniformsNormal( uniforms, material ) { if ( material.bumpMap ) { @@ -672,6 +672,6 @@ WebGLMaterials.prototype.refreshUniformsNormal = function ( uniforms, material ) } -}; +} export { WebGLMaterials }; From 2758d9e88ef41ccad6d7e3313de5453bacbeb1a0 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Tue, 5 May 2020 20:11:38 +0300 Subject: [PATCH 09/10] moved all code into constructor --- src/renderers/webgl/WebGLMaterials.js | 717 +++++++++++++------------- 1 file changed, 359 insertions(+), 358 deletions(-) diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index cd64cca4a7bf91..4fc48746afcf0a 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -7,671 +7,672 @@ import { BackSide } from "../../constants"; * i.e. uniforms refresh before material is being rendered */ -var _properties; - function WebGLMaterials( properties ) { - _properties = properties; - -} + function refreshUniforms( uniforms, material, environment, pixelRatio, height ) { -WebGLMaterials.prototype.refreshUniforms = function ( uniforms, material, environment, pixelRatio, height ) { + if ( material.isMeshBasicMaterial ) { - if ( material.isMeshBasicMaterial ) { + refreshUniformsCommon( uniforms, material ); - refreshUniformsCommon( uniforms, material ); + } else if ( material.isMeshLambertMaterial ) { - } else if ( material.isMeshLambertMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsLambert( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsLambert( uniforms, material ); + } else if ( material.isMeshToonMaterial ) { - } else if ( material.isMeshToonMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsToon( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsToon( uniforms, material ); + } else if ( material.isMeshPhongMaterial ) { - } else if ( material.isMeshPhongMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsPhong( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsPhong( uniforms, material ); + } else if ( material.isMeshStandardMaterial ) { - } else if ( material.isMeshStandardMaterial ) { + refreshUniformsCommon( uniforms, material, environment ); - refreshUniformsCommon( uniforms, material, environment ); + if ( material.isMeshPhysicalMaterial ) { - if ( material.isMeshPhysicalMaterial ) { + refreshUniformsPhysical( uniforms, material, environment ); - refreshUniformsPhysical( uniforms, material, environment ); + } else { - } else { + refreshUniformsStandard( uniforms, material, environment ); - refreshUniformsStandard( uniforms, material, environment ); + } - } + } else if ( material.isMeshMatcapMaterial ) { - } else if ( material.isMeshMatcapMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsMatcap( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsMatcap( uniforms, material ); + } else if ( material.isMeshDepthMaterial ) { - } else if ( material.isMeshDepthMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsDepth( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsDepth( uniforms, material ); + } else if ( material.isMeshDistanceMaterial ) { - } else if ( material.isMeshDistanceMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsDistance( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsDistance( uniforms, material ); + } else if ( material.isMeshNormalMaterial ) { - } else if ( material.isMeshNormalMaterial ) { + refreshUniformsCommon( uniforms, material ); + refreshUniformsNormal( uniforms, material ); - refreshUniformsCommon( uniforms, material ); - refreshUniformsNormal( uniforms, material ); + } else if ( material.isLineBasicMaterial ) { - } else if ( material.isLineBasicMaterial ) { + refreshUniformsLine( uniforms, material ); - refreshUniformsLine( uniforms, material ); + if ( material.isLineDashedMaterial ) { - if ( material.isLineDashedMaterial ) { + refreshUniformsDash( uniforms, material ); - refreshUniformsDash( uniforms, material ); + } - } + } else if ( material.isPointsMaterial ) { - } else if ( material.isPointsMaterial ) { + refreshUniformsPoints( uniforms, material, pixelRatio, height ); - refreshUniformsPoints( uniforms, material, pixelRatio, height ); + } else if ( material.isSpriteMaterial ) { - } else if ( material.isSpriteMaterial ) { + refreshUniformsSprites( uniforms, material ); - refreshUniformsSprites( uniforms, material ); + } else if ( material.isShadowMaterial ) { - } else if ( material.isShadowMaterial ) { + uniforms.color.value.copy( material.color ); + uniforms.opacity.value = material.opacity; - uniforms.color.value.copy( material.color ); - uniforms.opacity.value = material.opacity; + } - } + if ( material.isShaderMaterial ) { - if ( material.isShaderMaterial ) { + material.uniformsNeedUpdate = false; // #15581 - material.uniformsNeedUpdate = false; // #15581 + } } -}; + function refreshUniformsCommon( uniforms, material, environment ) { -function refreshUniformsCommon( uniforms, material, environment ) { + uniforms.opacity.value = material.opacity; - uniforms.opacity.value = material.opacity; + if ( material.color ) { - if ( material.color ) { + uniforms.diffuse.value.copy( material.color ); - uniforms.diffuse.value.copy( material.color ); + } - } + if ( material.emissive ) { + + uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); - if ( material.emissive ) { + } - uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); + if ( material.map ) { - } + uniforms.map.value = material.map; - if ( material.map ) { + } - uniforms.map.value = material.map; + if ( material.alphaMap ) { - } + uniforms.alphaMap.value = material.alphaMap; - if ( material.alphaMap ) { + } - uniforms.alphaMap.value = material.alphaMap; + if ( material.specularMap ) { - } + uniforms.specularMap.value = material.specularMap; - if ( material.specularMap ) { + } - uniforms.specularMap.value = material.specularMap; + var envMap = material.envMap || environment; - } + if ( envMap ) { - var envMap = material.envMap || environment; + uniforms.envMap.value = envMap; - if ( envMap ) { + uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1; - uniforms.envMap.value = envMap; + uniforms.reflectivity.value = material.reflectivity; + uniforms.refractionRatio.value = material.refractionRatio; - uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1; + uniforms.maxMipLevel.value = properties.get( envMap ).__maxMipLevel; - uniforms.reflectivity.value = material.reflectivity; - uniforms.refractionRatio.value = material.refractionRatio; + } - uniforms.maxMipLevel.value = _properties.get( envMap ).__maxMipLevel; + if ( material.lightMap ) { - } + uniforms.lightMap.value = material.lightMap; + uniforms.lightMapIntensity.value = material.lightMapIntensity; - if ( material.lightMap ) { + } - uniforms.lightMap.value = material.lightMap; - uniforms.lightMapIntensity.value = material.lightMapIntensity; + if ( material.aoMap ) { - } + uniforms.aoMap.value = material.aoMap; + uniforms.aoMapIntensity.value = material.aoMapIntensity; - if ( material.aoMap ) { + } - uniforms.aoMap.value = material.aoMap; - uniforms.aoMapIntensity.value = material.aoMapIntensity; + // uv repeat and offset setting priorities + // 1. color map + // 2. specular map + // 3. normal map + // 4. bump map + // 5. alpha map + // 6. emissive map - } + var uvScaleMap; - // uv repeat and offset setting priorities - // 1. color map - // 2. specular map - // 3. normal map - // 4. bump map - // 5. alpha map - // 6. emissive map + if ( material.map ) { - var uvScaleMap; + uvScaleMap = material.map; - if ( material.map ) { + } else if ( material.specularMap ) { - uvScaleMap = material.map; + uvScaleMap = material.specularMap; - } else if ( material.specularMap ) { + } else if ( material.displacementMap ) { - uvScaleMap = material.specularMap; + uvScaleMap = material.displacementMap; - } else if ( material.displacementMap ) { + } else if ( material.normalMap ) { - uvScaleMap = material.displacementMap; + uvScaleMap = material.normalMap; - } else if ( material.normalMap ) { + } else if ( material.bumpMap ) { - uvScaleMap = material.normalMap; + uvScaleMap = material.bumpMap; - } else if ( material.bumpMap ) { + } else if ( material.roughnessMap ) { - uvScaleMap = material.bumpMap; + uvScaleMap = material.roughnessMap; - } else if ( material.roughnessMap ) { + } else if ( material.metalnessMap ) { - uvScaleMap = material.roughnessMap; + uvScaleMap = material.metalnessMap; - } else if ( material.metalnessMap ) { + } else if ( material.alphaMap ) { - uvScaleMap = material.metalnessMap; + uvScaleMap = material.alphaMap; - } else if ( material.alphaMap ) { + } else if ( material.emissiveMap ) { - uvScaleMap = material.alphaMap; + uvScaleMap = material.emissiveMap; - } else if ( material.emissiveMap ) { + } - uvScaleMap = material.emissiveMap; + if ( uvScaleMap !== undefined ) { - } + // backwards compatibility + if ( uvScaleMap.isWebGLRenderTarget ) { - if ( uvScaleMap !== undefined ) { + uvScaleMap = uvScaleMap.texture; - // backwards compatibility - if ( uvScaleMap.isWebGLRenderTarget ) { + } - uvScaleMap = uvScaleMap.texture; + if ( uvScaleMap.matrixAutoUpdate === true ) { - } + uvScaleMap.updateMatrix(); - if ( uvScaleMap.matrixAutoUpdate === true ) { + } - uvScaleMap.updateMatrix(); + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); } - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + // uv repeat and offset setting priorities for uv2 + // 1. ao map + // 2. light map - } + var uv2ScaleMap; - // uv repeat and offset setting priorities for uv2 - // 1. ao map - // 2. light map + if ( material.aoMap ) { - var uv2ScaleMap; + uv2ScaleMap = material.aoMap; - if ( material.aoMap ) { + } else if ( material.lightMap ) { - uv2ScaleMap = material.aoMap; + uv2ScaleMap = material.lightMap; - } else if ( material.lightMap ) { + } - uv2ScaleMap = material.lightMap; + if ( uv2ScaleMap !== undefined ) { - } + // backwards compatibility + if ( uv2ScaleMap.isWebGLRenderTarget ) { - if ( uv2ScaleMap !== undefined ) { + uv2ScaleMap = uv2ScaleMap.texture; - // backwards compatibility - if ( uv2ScaleMap.isWebGLRenderTarget ) { + } - uv2ScaleMap = uv2ScaleMap.texture; + if ( uv2ScaleMap.matrixAutoUpdate === true ) { - } + uv2ScaleMap.updateMatrix(); - if ( uv2ScaleMap.matrixAutoUpdate === true ) { + } - uv2ScaleMap.updateMatrix(); + uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix ); } - uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix ); - } -} + function refreshUniformsLine( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; -function refreshUniformsLine( uniforms, material ) { + } - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; + function refreshUniformsDash( uniforms, material ) { -} + uniforms.dashSize.value = material.dashSize; + uniforms.totalSize.value = material.dashSize + material.gapSize; + uniforms.scale.value = material.scale; -function refreshUniformsDash( uniforms, material ) { + } - uniforms.dashSize.value = material.dashSize; - uniforms.totalSize.value = material.dashSize + material.gapSize; - uniforms.scale.value = material.scale; + function refreshUniformsPoints( uniforms, material, pixelRatio, height ) { -} + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.size.value = material.size * pixelRatio; + uniforms.scale.value = height * 0.5; -function refreshUniformsPoints( uniforms, material, pixelRatio, height ) { + if ( material.map ) { - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; - uniforms.size.value = material.size * pixelRatio; - uniforms.scale.value = height * 0.5; + uniforms.map.value = material.map; - if ( material.map ) { + } - uniforms.map.value = material.map; + if ( material.alphaMap ) { - } + uniforms.alphaMap.value = material.alphaMap; - if ( material.alphaMap ) { + } - uniforms.alphaMap.value = material.alphaMap; + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map - } + var uvScaleMap; - // uv repeat and offset setting priorities - // 1. color map - // 2. alpha map + if ( material.map ) { - var uvScaleMap; + uvScaleMap = material.map; - if ( material.map ) { + } else if ( material.alphaMap ) { - uvScaleMap = material.map; + uvScaleMap = material.alphaMap; - } else if ( material.alphaMap ) { + } - uvScaleMap = material.alphaMap; + if ( uvScaleMap !== undefined ) { - } + if ( uvScaleMap.matrixAutoUpdate === true ) { - if ( uvScaleMap !== undefined ) { + uvScaleMap.updateMatrix(); - if ( uvScaleMap.matrixAutoUpdate === true ) { + } - uvScaleMap.updateMatrix(); + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); } - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); - } -} + function refreshUniformsSprites( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.rotation.value = material.rotation; -function refreshUniformsSprites( uniforms, material ) { + if ( material.map ) { - uniforms.diffuse.value.copy( material.color ); - uniforms.opacity.value = material.opacity; - uniforms.rotation.value = material.rotation; + uniforms.map.value = material.map; - if ( material.map ) { + } - uniforms.map.value = material.map; + if ( material.alphaMap ) { - } + uniforms.alphaMap.value = material.alphaMap; - if ( material.alphaMap ) { + } - uniforms.alphaMap.value = material.alphaMap; + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map - } + var uvScaleMap; - // uv repeat and offset setting priorities - // 1. color map - // 2. alpha map + if ( material.map ) { - var uvScaleMap; + uvScaleMap = material.map; - if ( material.map ) { + } else if ( material.alphaMap ) { - uvScaleMap = material.map; + uvScaleMap = material.alphaMap; - } else if ( material.alphaMap ) { + } - uvScaleMap = material.alphaMap; + if ( uvScaleMap !== undefined ) { - } + if ( uvScaleMap.matrixAutoUpdate === true ) { - if ( uvScaleMap !== undefined ) { + uvScaleMap.updateMatrix(); - if ( uvScaleMap.matrixAutoUpdate === true ) { + } - uvScaleMap.updateMatrix(); + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); } - uniforms.uvTransform.value.copy( uvScaleMap.matrix ); - } -} + function refreshUniformsFog( uniforms, fog ) { -WebGLMaterials.prototype.refreshUniformsFog = function ( uniforms, fog ) { + uniforms.fogColor.value.copy( fog.color ); - uniforms.fogColor.value.copy( fog.color ); + if ( fog.isFog ) { - if ( fog.isFog ) { + uniforms.fogNear.value = fog.near; + uniforms.fogFar.value = fog.far; - uniforms.fogNear.value = fog.near; - uniforms.fogFar.value = fog.far; + } else if ( fog.isFogExp2 ) { - } else if ( fog.isFogExp2 ) { + uniforms.fogDensity.value = fog.density; - uniforms.fogDensity.value = fog.density; + } } -}; + function refreshUniformsLambert( uniforms, material ) { -function refreshUniformsLambert( uniforms, material ) { + if ( material.emissiveMap ) { - if ( material.emissiveMap ) { + uniforms.emissiveMap.value = material.emissiveMap; - uniforms.emissiveMap.value = material.emissiveMap; + } } -} + function refreshUniformsPhong( uniforms, material ) { -function refreshUniformsPhong( uniforms, material ) { + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) - uniforms.specular.value.copy( material.specular ); - uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + if ( material.emissiveMap ) { - if ( material.emissiveMap ) { + uniforms.emissiveMap.value = material.emissiveMap; - uniforms.emissiveMap.value = material.emissiveMap; + } - } + if ( material.bumpMap ) { - if ( material.bumpMap ) { + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + } - } + if ( material.normalMap ) { - if ( material.normalMap ) { + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + } - } + if ( material.displacementMap ) { - if ( material.displacementMap ) { + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } } -} + function refreshUniformsToon( uniforms, material ) { -function refreshUniformsToon( uniforms, material ) { + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) - uniforms.specular.value.copy( material.specular ); - uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + if ( material.gradientMap ) { - if ( material.gradientMap ) { + uniforms.gradientMap.value = material.gradientMap; - uniforms.gradientMap.value = material.gradientMap; + } - } + if ( material.emissiveMap ) { - if ( material.emissiveMap ) { + uniforms.emissiveMap.value = material.emissiveMap; - uniforms.emissiveMap.value = material.emissiveMap; + } - } + if ( material.bumpMap ) { - if ( material.bumpMap ) { + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + } - } + if ( material.normalMap ) { - if ( material.normalMap ) { + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + } - } + if ( material.displacementMap ) { - if ( material.displacementMap ) { + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } } -} + function refreshUniformsStandard( uniforms, material, environment ) { -function refreshUniformsStandard( uniforms, material, environment ) { + uniforms.roughness.value = material.roughness; + uniforms.metalness.value = material.metalness; - uniforms.roughness.value = material.roughness; - uniforms.metalness.value = material.metalness; + if ( material.roughnessMap ) { - if ( material.roughnessMap ) { + uniforms.roughnessMap.value = material.roughnessMap; - uniforms.roughnessMap.value = material.roughnessMap; + } - } + if ( material.metalnessMap ) { - if ( material.metalnessMap ) { + uniforms.metalnessMap.value = material.metalnessMap; - uniforms.metalnessMap.value = material.metalnessMap; + } - } + if ( material.emissiveMap ) { - if ( material.emissiveMap ) { + uniforms.emissiveMap.value = material.emissiveMap; - uniforms.emissiveMap.value = material.emissiveMap; + } - } + if ( material.bumpMap ) { - if ( material.bumpMap ) { + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + } - } + if ( material.normalMap ) { - if ( material.normalMap ) { + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + } - } + if ( material.displacementMap ) { - if ( material.displacementMap ) { + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } - } + if ( material.envMap || environment ) { - if ( material.envMap || environment ) { + //uniforms.envMap.value = material.envMap; // part of uniforms common + uniforms.envMapIntensity.value = material.envMapIntensity; - //uniforms.envMap.value = material.envMap; // part of uniforms common - uniforms.envMapIntensity.value = material.envMapIntensity; + } } -} + function refreshUniformsPhysical( uniforms, material, environment ) { -function refreshUniformsPhysical( uniforms, material, environment ) { + refreshUniformsStandard( uniforms, material, environment ); - refreshUniformsStandard( uniforms, material, environment ); + uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common - uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common + uniforms.clearcoat.value = material.clearcoat; + uniforms.clearcoatRoughness.value = material.clearcoatRoughness; + if ( material.sheen ) uniforms.sheen.value.copy( material.sheen ); - uniforms.clearcoat.value = material.clearcoat; - uniforms.clearcoatRoughness.value = material.clearcoatRoughness; - if ( material.sheen ) uniforms.sheen.value.copy( material.sheen ); + if ( material.clearcoatMap ) { - if ( material.clearcoatMap ) { + uniforms.clearcoatMap.value = material.clearcoatMap; - uniforms.clearcoatMap.value = material.clearcoatMap; + } - } + if ( material.clearcoatRoughnessMap ) { - if ( material.clearcoatRoughnessMap ) { + uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; - uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; + } - } + if ( material.clearcoatNormalMap ) { - if ( material.clearcoatNormalMap ) { + uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); + uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; - uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); - uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; + if ( material.side === BackSide ) { - if ( material.side === BackSide ) { + uniforms.clearcoatNormalScale.value.negate(); - uniforms.clearcoatNormalScale.value.negate(); + } } + uniforms.transparency.value = material.transparency; + } - uniforms.transparency.value = material.transparency; + function refreshUniformsMatcap( uniforms, material ) { -} + if ( material.matcap ) { -function refreshUniformsMatcap( uniforms, material ) { + uniforms.matcap.value = material.matcap; - if ( material.matcap ) { + } - uniforms.matcap.value = material.matcap; + if ( material.bumpMap ) { - } + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - if ( material.bumpMap ) { + } - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + if ( material.normalMap ) { - } + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - if ( material.normalMap ) { + } - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + if ( material.displacementMap ) { - } + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } } -} + function refreshUniformsDepth( uniforms, material ) { -function refreshUniformsDepth( uniforms, material ) { + if ( material.displacementMap ) { - if ( material.displacementMap ) { + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } } -} + function refreshUniformsDistance( uniforms, material ) { + + if ( material.displacementMap ) { -function refreshUniformsDistance( uniforms, material ) { + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - if ( material.displacementMap ) { + } - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + uniforms.referencePosition.value.copy( material.referencePosition ); + uniforms.nearDistance.value = material.nearDistance; + uniforms.farDistance.value = material.farDistance; } - uniforms.referencePosition.value.copy( material.referencePosition ); - uniforms.nearDistance.value = material.nearDistance; - uniforms.farDistance.value = material.farDistance; + function refreshUniformsNormal( uniforms, material ) { -} + if ( material.bumpMap ) { -function refreshUniformsNormal( uniforms, material ) { + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; - if ( material.bumpMap ) { + } - uniforms.bumpMap.value = material.bumpMap; - uniforms.bumpScale.value = material.bumpScale; - if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1; + if ( material.normalMap ) { - } + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) uniforms.normalScale.value.negate(); - if ( material.normalMap ) { + } - uniforms.normalMap.value = material.normalMap; - uniforms.normalScale.value.copy( material.normalScale ); - if ( material.side === BackSide ) uniforms.normalScale.value.negate(); + if ( material.displacementMap ) { - } + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; - if ( material.displacementMap ) { - - uniforms.displacementMap.value = material.displacementMap; - uniforms.displacementScale.value = material.displacementScale; - uniforms.displacementBias.value = material.displacementBias; + } } + return { + refreshUniforms: refreshUniforms, + refreshUniformsFog: refreshUniformsFog + }; + } export { WebGLMaterials }; From 9c27acebf97605027a38ea06d0262a3523396100 Mon Sep 17 00:00:00 2001 From: Filipp Keks Date: Wed, 6 May 2020 11:15:11 +0300 Subject: [PATCH 10/10] fix import, taphos nomore :'( --- src/renderers/webgl/WebGLMaterials.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index 4fc48746afcf0a..d23d957e096ce0 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -1,7 +1,7 @@ -import { BackSide } from "../../constants"; +import { BackSide } from "../../constants.js"; /** - * @author taphos / https://github.com/taphos + * @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