Browse Source

Revert "Make MeshStandardMaterialCommon"

This reverts commit 225dabdabcb38240f3e9e8d385bc939968ec9275.
Takahiro 8 years ago
parent
commit
ecd9515ce2

+ 0 - 1
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';

+ 122 - 6
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: <hex>,
  *  roughness: <float>,
  *  metalness: <float>,
+ *  opacity: <float>,
+ *
+ *  map: new THREE.Texture( <Image> ),
+ *
+ *  lightMap: new THREE.Texture( <Image> ),
+ *  lightMapIntensity: <float>
+ *
+ *  aoMap: new THREE.Texture( <Image> ),
+ *  aoMapIntensity: <float>
+ *
+ *  emissive: <hex>,
+ *  emissiveIntensity: <float>
+ *  emissiveMap: new THREE.Texture( <Image> ),
+ *
+ *  bumpMap: new THREE.Texture( <Image> ),
+ *  bumpScale: <float>,
+ *
+ *  normalMap: new THREE.Texture( <Image> ),
+ *  normalScale: <Vector2>,
+ *
+ *  displacementMap: new THREE.Texture( <Image> ),
+ *  displacementScale: <float>,
+ *  displacementBias: <float>,
  *
  *  roughnessMap: new THREE.Texture( <Image> ),
  *
  *  metalnessMap: new THREE.Texture( <Image> ),
+ *
+ *  alphaMap: new THREE.Texture( <Image> ),
+ *
+ *  envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
+ *  envMapIntensity: <float>
+ *
+ *  refractionRatio: <float>,
+ *
+ *  wireframe: <boolean>,
+ *  wireframeLinewidth: <float>,
+ *
+ *  skinning: <bool>,
+ *  morphTargets: <bool>,
+ *  morphNormals: <bool>
  * }
  */
 
 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;
 
 };

+ 0 - 159
src/materials/MeshStandardMaterialCommon.js

@@ -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: <hex>,
- *  opacity: <float>,
- *
- *  map: new THREE.Texture( <Image> ),
- *
- *  lightMap: new THREE.Texture( <Image> ),
- *  lightMapIntensity: <float>
- *
- *  aoMap: new THREE.Texture( <Image> ),
- *  aoMapIntensity: <float>
- *
- *  emissive: <hex>,
- *  emissiveIntensity: <float>
- *  emissiveMap: new THREE.Texture( <Image> ),
- *
- *  bumpMap: new THREE.Texture( <Image> ),
- *  bumpScale: <float>,
- *
- *  normalMap: new THREE.Texture( <Image> ),
- *  normalScale: <Vector2>,
- *
- *  displacementMap: new THREE.Texture( <Image> ),
- *  displacementScale: <float>,
- *  displacementBias: <float>,
- *
- *  alphaMap: new THREE.Texture( <Image> ),
- *
- *  envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
- *  envMapIntensity: <float>
- *
- *  refractionRatio: <float>,
- *
- *  wireframe: <boolean>,
- *  wireframeLinewidth: <float>,
- *
- *  skinning: <bool>,
- *  morphTargets: <bool>,
- *  morphNormals: <bool>
- * }
- */
-
-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 };

+ 122 - 6
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: <hex>,
  *  glossiness: <float>,
  *  specular2: <hex>,
+ *  opacity: <float>,
+ *
+ *  map: new THREE.Texture( <Image> ),
+ *
+ *  lightMap: new THREE.Texture( <Image> ),
+ *  lightMapIntensity: <float>
+ *
+ *  aoMap: new THREE.Texture( <Image> ),
+ *  aoMapIntensity: <float>
+ *
+ *  emissive: <hex>,
+ *  emissiveIntensity: <float>
+ *  emissiveMap: new THREE.Texture( <Image> ),
+ *
+ *  bumpMap: new THREE.Texture( <Image> ),
+ *  bumpScale: <float>,
+ *
+ *  normalMap: new THREE.Texture( <Image> ),
+ *  normalScale: <Vector2>,
+ *
+ *  displacementMap: new THREE.Texture( <Image> ),
+ *  displacementScale: <float>,
+ *  displacementBias: <float>,
  *
  *  glossinessMap: new THREE.Texture( <Image> ),
  *
  *  specular2Map: new THREE.Texture( <Image> ),
+ *
+ *  alphaMap: new THREE.Texture( <Image> ),
+ *
+ *  envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
+ *  envMapIntensity: <float>
+ *
+ *  refractionRatio: <float>,
+ *
+ *  wireframe: <boolean>,
+ *  wireframeLinewidth: <float>,
+ *
+ *  skinning: <bool>,
+ *  morphTargets: <bool>,
+ *  morphNormals: <bool>
  * }
  */
 
 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;
 
 };

+ 8 - 4
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 ) {
 

+ 5 - 5
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 );
 

+ 1 - 1
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 );

+ 1 - 1
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