Skip to content

Commit 08adeec

Browse files
WestLangleymrdoob
authored andcommitted
Unify MeshPhysicalMaterial and MeshStandardMaterial
1 parent 2901f76 commit 08adeec

21 files changed

+46
-234
lines changed

src/materials/MeshPhysicalMaterial.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ THREE.MeshPhysicalMaterial = function ( parameters ) {
1010

1111
THREE.MeshStandardMaterial.call( this );
1212

13+
this.defines = { 'PHYSICAL': '' };
14+
1315
this.type = 'MeshPhysicalMaterial';
1416

1517
this.reflectivity = 0.5; // maps to F0 = 0.04
@@ -25,6 +27,8 @@ THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
2527

2628
THREE.MeshStandardMaterial.prototype.copy.call( this, source );
2729

30+
this.defines = { 'PHYSICAL': '' };
31+
2832
this.reflectivity = source.reflectivity;
2933

3034
return this;

src/materials/MeshStandardMaterial.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ THREE.MeshStandardMaterial = function ( parameters ) {
6262

6363
THREE.Material.call( this );
6464

65+
this.defines = { 'STANDARD': '' };
66+
6567
this.type = 'MeshStandardMaterial';
6668

6769
this.color = new THREE.Color( 0xffffff ); // diffuse
@@ -128,6 +130,8 @@ THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
128130

129131
THREE.Material.prototype.copy.call( this, source );
130132

133+
this.defines = { 'STANDARD': '' };
134+
131135
this.color.copy( source.color );
132136
this.roughness = source.roughness;
133137
this.metalness = source.metalness;

src/renderers/shaders/ShaderChunk/aomap_fragment.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
reflectedLight.indirectDiffuse *= ambientOcclusion;
66

7-
#if defined( USE_ENVMAP ) && defined( STANDARD )
7+
#if defined( USE_ENVMAP ) && defined( PHYSICAL )
88

99
float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
1010

src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#if NUM_CLIPPING_PLANES > 0
22

3-
#if ! defined( STANDARD ) && ! defined( PHONG )
3+
#if ! defined( PHYSICAL ) && ! defined( PHONG )
44
varying vec3 vViewPosition;
55
#endif
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG )
1+
#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )
22
varying vec3 vViewPosition;
33
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG )
1+
#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )
22
vViewPosition = - mvPosition.xyz;
33
#endif
44

src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#if defined( USE_ENVMAP ) || defined( STANDARD )
1+
#if defined( USE_ENVMAP ) || defined( PHYSICAL )
22
uniform float reflectivity;
33
uniform float envMapIntenstiy;
44
#endif
55

66
#ifdef USE_ENVMAP
77

8-
#if ! defined( STANDARD ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )
8+
#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )
99
varying vec3 vWorldPosition;
1010
#endif
1111

@@ -16,7 +16,7 @@
1616
#endif
1717
uniform float flipEnvMap;
1818

19-
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( STANDARD )
19+
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )
2020
uniform float refractionRatio;
2121
#else
2222
varying vec3 vReflect;

src/renderers/shaders/ShaderChunk/lights_pars.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
161161
#endif
162162

163163

164-
#if defined( USE_ENVMAP ) && defined( STANDARD )
164+
#if defined( USE_ENVMAP ) && defined( PHYSICAL )
165165

166166
vec3 getLightProbeIndirectIrradiance( /*const in SpecularLightProbe specularLightProbe,*/ const in GeometricContext geometry, const in int maxMIPLevel ) {
167167

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
PhysicalMaterial material;
22
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
33
material.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );
4-
material.specularColor = mix( vec3( 0.16 * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
4+
#ifdef STANDARD
5+
material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
6+
#else
7+
material.specularColor = mix( vec3( 0.16 * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
8+
#endif

src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ struct PhysicalMaterial {
44
float specularRoughness;
55
vec3 specularColor;
66

7+
#ifndef STANDARD
8+
// future
9+
#endif
10+
711
};
812

913
void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {

src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/renderers/shaders/ShaderChunk/lights_template.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ IncidentLight directLight;
109109

110110
#endif
111111

112-
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
112+
#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )
113113

114114
// TODO, replace 8 with the real maxMIPLevel
115115
irradiance += getLightProbeIndirectIrradiance( /*lightProbe,*/ geometry, 8 );

src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )
1+
#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )
22

33
#ifdef USE_SKINNING
44

src/renderers/shaders/ShaderLib.js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,36 +98,6 @@ THREE.ShaderLib = {
9898

9999
] ),
100100

101-
vertexShader: THREE.ShaderChunk[ 'meshstandard_vert' ],
102-
fragmentShader: THREE.ShaderChunk[ 'meshstandard_frag' ]
103-
104-
},
105-
106-
'physical': {
107-
108-
uniforms: THREE.UniformsUtils.merge( [
109-
110-
THREE.UniformsLib[ 'common' ],
111-
THREE.UniformsLib[ 'aomap' ],
112-
THREE.UniformsLib[ 'lightmap' ],
113-
THREE.UniformsLib[ 'emissivemap' ],
114-
THREE.UniformsLib[ 'bumpmap' ],
115-
THREE.UniformsLib[ 'normalmap' ],
116-
THREE.UniformsLib[ 'displacementmap' ],
117-
THREE.UniformsLib[ 'roughnessmap' ],
118-
THREE.UniformsLib[ 'metalnessmap' ],
119-
THREE.UniformsLib[ 'fog' ],
120-
THREE.UniformsLib[ 'lights' ],
121-
122-
{
123-
"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
124-
"roughness": { type: "1f", value: 0.5 },
125-
"metalness": { type: "1f", value: 0 },
126-
"envMapIntensity" : { type: "1f", value: 1 } // temporary
127-
}
128-
129-
] ),
130-
131101
vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
132102
fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
133103

@@ -240,3 +210,21 @@ THREE.ShaderLib = {
240210
}
241211

242212
};
213+
214+
THREE.ShaderLib[ 'physical' ] = {
215+
216+
uniforms: THREE.UniformsUtils.merge( [
217+
218+
THREE.ShaderLib[ 'standard' ].uniforms,
219+
220+
{
221+
// future
222+
}
223+
224+
] ),
225+
226+
vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
227+
fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
228+
229+
};
230+

src/renderers/shaders/ShaderLib/meshphysical_frag.glsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define STANDARD
21
#define PHYSICAL
32

43
uniform vec3 diffuse;

src/renderers/shaders/ShaderLib/meshphysical_vert.glsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define STANDARD
21
#define PHYSICAL
32

43
varying vec3 vViewPosition;

src/renderers/shaders/ShaderLib/meshstandard_frag.glsl

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/renderers/shaders/ShaderLib/meshstandard_vert.glsl

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/renderers/webgl/WebGLPrograms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
88
MeshBasicMaterial: 'basic',
99
MeshLambertMaterial: 'lambert',
1010
MeshPhongMaterial: 'phong',
11-
MeshStandardMaterial: 'standard',
11+
MeshStandardMaterial: 'physical',
1212
MeshPhysicalMaterial: 'physical',
1313
LineBasicMaterial: 'basic',
1414
LineDashedMaterial: 'dashed',

0 commit comments

Comments
 (0)