From ecd9515ce2cb687df3cbbc9ff9211f5aa9e4b6c9 Mon Sep 17 00:00:00 2001 From: Takahiro Date: Sun, 9 Apr 2017 21:06:45 +0900 Subject: [PATCH] Revert "Make MeshStandardMaterialCommon" This reverts commit 225dabdabcb38240f3e9e8d385bc939968ec9275. --- src/materials/Materials.js | 1 - src/materials/MeshStandardMaterial.js | 128 +++++++++++++- src/materials/MeshStandardMaterialCommon.js | 159 ------------------ src/materials/MeshStandardMaterialSG.js | 128 +++++++++++++- src/renderers/WebGLRenderer.js | 12 +- .../lights_physical_pars_fragment.glsl | 10 +- .../shaders/ShaderChunk/lights_template.glsl | 2 +- .../shaders/ShaderLib/meshphysical_frag.glsl | 2 +- 8 files changed, 259 insertions(+), 183 deletions(-) delete mode 100644 src/materials/MeshStandardMaterialCommon.js diff --git a/src/materials/Materials.js b/src/materials/Materials.js index 474bdeee45..f0cdc27601 100644 --- a/src/materials/Materials.js +++ b/src/materials/Materials.js @@ -4,7 +4,6 @@ export { RawShaderMaterial } from './RawShaderMaterial.js'; export { ShaderMaterial } from './ShaderMaterial.js'; export { PointsMaterial } from './PointsMaterial.js'; export { MeshPhysicalMaterial } from './MeshPhysicalMaterial.js'; -export { MeshStandardMaterialCommon } from './MeshStandardMaterialCommon.js'; export { MeshStandardMaterial } from './MeshStandardMaterial.js'; export { MeshStandardMaterialSG } from './MeshStandardMaterialSG.js'; export { MeshPhongMaterial } from './MeshPhongMaterial.js'; diff --git a/src/materials/MeshStandardMaterial.js b/src/materials/MeshStandardMaterial.js index 0cbdf0f9cd..b0420fc8db 100644 --- a/src/materials/MeshStandardMaterial.js +++ b/src/materials/MeshStandardMaterial.js @@ -1,4 +1,4 @@ -import { MeshStandardMaterialCommon } from './MeshStandardMaterialCommon'; +import { Material } from './Material'; import { Vector2 } from '../math/Vector2'; import { Color } from '../math/Color'; @@ -6,52 +6,168 @@ import { Color } from '../math/Color'; * @author WestLangley / http://github.com/WestLangley * * parameters = { + * color: , * roughness: , * metalness: , + * opacity: , + * + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , * * roughnessMap: new THREE.Texture( ), * * metalnessMap: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * envMapIntensity: + * + * refractionRatio: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: * } */ function MeshStandardMaterial( parameters ) { - MeshStandardMaterialCommon.call( this ); + Material.call( this ); - this.defines[ 'STANDARD' ] = ''; + this.defines = { 'STANDARD': '' }; this.type = 'MeshStandardMaterial'; + this.color = new Color( 0xffffff ); // diffuse this.roughness = 0.5; this.metalness = 0.5; + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + this.roughnessMap = null; this.metalnessMap = null; + this.alphaMap = null; + + this.envMap = null; + this.envMapIntensity = 1.0; + + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + this.setValues( parameters ); } -MeshStandardMaterial.prototype = Object.create( MeshStandardMaterialCommon.prototype ); +MeshStandardMaterial.prototype = Object.create( Material.prototype ); MeshStandardMaterial.prototype.constructor = MeshStandardMaterial; MeshStandardMaterial.prototype.isMeshStandardMaterial = true; MeshStandardMaterial.prototype.copy = function ( source ) { - MeshStandardMaterialCommon.prototype.copy.call( this, source ); + Material.prototype.copy.call( this, source ); - this.defines[ 'STANDARD' ] = ''; + this.defines = { 'STANDARD': '' }; + this.color.copy( source.color ); this.roughness = source.roughness; this.metalness = source.metalness; + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + this.roughnessMap = source.roughnessMap; this.metalnessMap = source.metalnessMap; + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapIntensity = source.envMapIntensity; + + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + return this; }; diff --git a/src/materials/MeshStandardMaterialCommon.js b/src/materials/MeshStandardMaterialCommon.js deleted file mode 100644 index c61ab0abe7..0000000000 --- a/src/materials/MeshStandardMaterialCommon.js +++ /dev/null @@ -1,159 +0,0 @@ -import { Material } from './Material'; -import { Vector2 } from '../math/Vector2'; -import { Color } from '../math/Color'; - -/** - * @author WestLangley / http://github.com/WestLangley - * @author takahiro / http://github.com/takahirox - * - * parameters = { - * color: , - * opacity: , - * - * map: new THREE.Texture( ), - * - * lightMap: new THREE.Texture( ), - * lightMapIntensity: - * - * aoMap: new THREE.Texture( ), - * aoMapIntensity: - * - * emissive: , - * emissiveIntensity: - * emissiveMap: new THREE.Texture( ), - * - * bumpMap: new THREE.Texture( ), - * bumpScale: , - * - * normalMap: new THREE.Texture( ), - * normalScale: , - * - * displacementMap: new THREE.Texture( ), - * displacementScale: , - * displacementBias: , - * - * alphaMap: new THREE.Texture( ), - * - * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), - * envMapIntensity: - * - * refractionRatio: , - * - * wireframe: , - * wireframeLinewidth: , - * - * skinning: , - * morphTargets: , - * morphNormals: - * } - */ - -function MeshStandardMaterialCommon( parameters ) { - - Material.call( this ); - - this.defines = { 'STANDARD_COMMON': '' }; - - this.type = 'MeshStandardMaterialCommon'; - - this.color = new Color( 0xffffff ); // diffuse - - this.map = null; - - this.lightMap = null; - this.lightMapIntensity = 1.0; - - this.aoMap = null; - this.aoMapIntensity = 1.0; - - this.emissive = new Color( 0x000000 ); - this.emissiveIntensity = 1.0; - this.emissiveMap = null; - - this.bumpMap = null; - this.bumpScale = 1; - - this.normalMap = null; - this.normalScale = new Vector2( 1, 1 ); - - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; - - this.alphaMap = null; - - this.envMap = null; - this.envMapIntensity = 1.0; - - this.refractionRatio = 0.98; - - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; - - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; - - this.setValues( parameters ); - -} - -MeshStandardMaterialCommon.prototype = Object.create( Material.prototype ); -MeshStandardMaterialCommon.prototype.constructor = MeshStandardMaterialCommon; - -MeshStandardMaterialCommon.prototype.isMeshStandardMaterialCommon = true; - -MeshStandardMaterialCommon.prototype.copy = function ( source ) { - - Material.prototype.copy.call( this, source ); - - this.defines = { 'STANDARD_COMMON': '' }; - - this.color.copy( source.color ); - - this.map = source.map; - - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; - - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; - - this.emissive.copy( source.emissive ); - this.emissiveMap = source.emissiveMap; - this.emissiveIntensity = source.emissiveIntensity; - - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; - - this.normalMap = source.normalMap; - this.normalScale.copy( source.normalScale ); - - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; - - this.alphaMap = source.alphaMap; - - this.envMap = source.envMap; - this.envMapIntensity = source.envMapIntensity; - - this.refractionRatio = source.refractionRatio; - - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; - - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; - - return this; - -}; - - -export { MeshStandardMaterialCommon }; diff --git a/src/materials/MeshStandardMaterialSG.js b/src/materials/MeshStandardMaterialSG.js index 56a938a397..c58a286d9d 100644 --- a/src/materials/MeshStandardMaterialSG.js +++ b/src/materials/MeshStandardMaterialSG.js @@ -1,4 +1,4 @@ -import { MeshStandardMaterialCommon } from './MeshStandardMaterialCommon'; +import { Material } from './Material'; import { Vector2 } from '../math/Vector2'; import { Color } from '../math/Color'; @@ -6,52 +6,168 @@ import { Color } from '../math/Color'; * @author takahiro / http://github.com/takahirox * * parameters = { + * color: , * glossiness: , * specular2: , + * opacity: , + * + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , * * glossinessMap: new THREE.Texture( ), * * specular2Map: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * envMapIntensity: + * + * refractionRatio: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: * } */ function MeshStandardMaterialSG( parameters ) { - MeshStandardMaterialCommon.call( this ); + Material.call( this ); - this.defines[ 'STANDARD_SG' ] = ''; + this.defines = { 'STANDARD': '', 'STANDARD_SG': '' }; this.type = 'MeshStandardMaterialSG'; + this.color = new Color( 0xffffff ); // diffuse this.glossiness = 0.5; this.specular2 = new Color ( 0x000000 ); + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + this.glossinessMap = null; this.specular2Map = null; + this.alphaMap = null; + + this.envMap = null; + this.envMapIntensity = 1.0; + + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + this.setValues( parameters ); } -MeshStandardMaterialSG.prototype = Object.create( MeshStandardMaterialCommon.prototype ); +MeshStandardMaterialSG.prototype = Object.create( Material.prototype ); MeshStandardMaterialSG.prototype.constructor = MeshStandardMaterialSG; MeshStandardMaterialSG.prototype.isMeshStandardMaterialSG = true; MeshStandardMaterialSG.prototype.copy = function ( source ) { - MeshStandardMaterialCommon.prototype.copy.call( this, source ); + Material.prototype.copy.call( this, source ); - this.defines[ 'STANDARD_SG' ] = ''; + this.defines = { 'STANDARD': '' }; + this.color.copy( source.color ); this.glossiness = source.glossiness; this.speculars.copy( source.specular2 ); + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + this.glossinessMap = source.glossinessMap; this.specular2Map = source.specular2Map; + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapIntensity = source.envMapIntensity; + + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + return this; }; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 1bfb158047..3524808b30 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -622,7 +622,8 @@ function WebGLRenderer( parameters ) { _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal ); if ( ! material.isMeshPhongMaterial && - ! material.isMeshStandardMaterialCommon && + ! material.isMeshStandardMaterial && + ! material.isMeshStandardMaterialSG && ! material.isMeshNormalMaterial && material.shading === FlatShading ) { @@ -1722,7 +1723,8 @@ function WebGLRenderer( parameters ) { if ( material.isShaderMaterial || material.isMeshPhongMaterial || - material.isMeshStandardMaterialCommon || + material.isMeshStandardMaterial || + material.isMeshStandardMaterialSG || material.envMap ) { var uCamPos = p_uniforms.map.cameraPosition; @@ -1739,7 +1741,8 @@ function WebGLRenderer( parameters ) { if ( material.isMeshPhongMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || - material.isMeshStandardMaterialCommon || + material.isMeshStandardMaterial || + material.isMeshStandardMaterialSG || material.isShaderMaterial || material.skinning ) { @@ -1835,7 +1838,8 @@ function WebGLRenderer( parameters ) { if ( material.isMeshBasicMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial || - material.isMeshStandardMaterialCommon || + material.isMeshStandardMaterial || + material.isMeshStandardMaterialSG || material.isMeshNormalMaterial || material.isMeshDepthMaterial ) { diff --git a/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl b/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl index 87321d50d9..f1457cf900 100644 --- a/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl +++ b/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl @@ -4,7 +4,7 @@ struct PhysicalMaterial { float specularRoughness; vec3 specularColor; - #ifndef STANDARD_COMMON + #ifndef STANDARD float clearCoat; float clearCoatRoughness; #endif @@ -56,7 +56,7 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC #endif - #ifndef STANDARD_COMMON + #ifndef STANDARD float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL ); #else float clearCoatDHR = 0.0; @@ -65,7 +65,7 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC reflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness ); reflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor ); - #ifndef STANDARD_COMMON + #ifndef STANDARD reflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness ); @@ -81,7 +81,7 @@ void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricCo void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { - #ifndef STANDARD_COMMON + #ifndef STANDARD float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); float dotNL = dotNV; float clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL ); @@ -91,7 +91,7 @@ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 clearCo reflectedLight.indirectSpecular += ( 1.0 - clearCoatDHR ) * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness ); - #ifndef STANDARD_COMMON + #ifndef STANDARD reflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness ); diff --git a/src/renderers/shaders/ShaderChunk/lights_template.glsl b/src/renderers/shaders/ShaderChunk/lights_template.glsl index dc5b179fa8..219e7956e4 100644 --- a/src/renderers/shaders/ShaderChunk/lights_template.glsl +++ b/src/renderers/shaders/ShaderChunk/lights_template.glsl @@ -138,7 +138,7 @@ IncidentLight directLight; // TODO, replace 8 with the real maxMIPLevel vec3 radiance = getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_BlinnShininessExponent( material ), 8 ); - #ifndef STANDARD_COMMON + #ifndef STANDARD vec3 clearCoatRadiance = getLightProbeIndirectRadiance( /*specularLightProbe,*/ geometry, Material_ClearCoat_BlinnShininessExponent( material ), 8 ); #else vec3 clearCoatRadiance = vec3( 0.0 ); diff --git a/src/renderers/shaders/ShaderLib/meshphysical_frag.glsl b/src/renderers/shaders/ShaderLib/meshphysical_frag.glsl index 75d737b0ec..0c02c74550 100644 --- a/src/renderers/shaders/ShaderLib/meshphysical_frag.glsl +++ b/src/renderers/shaders/ShaderLib/meshphysical_frag.glsl @@ -13,7 +13,7 @@ uniform vec3 emissive; uniform float opacity; -#ifndef STANDARD_COMMON +#ifndef STANDARD uniform float clearCoat; uniform float clearCoatRoughness; #endif -- GitLab