Browse Source

fix bug in Physical with reflectivity not always defined.

Ben Houston 9 years ago
parent
commit
6d356c1d69

+ 11 - 3
examples/webgl_materials_physical_variations.html

@@ -88,11 +88,19 @@
 
 				var geometry = new THREE.SphereBufferGeometry( sphereRadius, 32, 16 );
 
-	
-				for( var alpha = 0; alpha <= 1.0; alpha += stepSize ) {
+				var localReflectionCube;
+				
+				for( var alpha = 0, alphaIndex = 0; alpha <= 1.0; alpha += stepSize, alphaIndex ++ ) {
 
 					var roughness = 1.0 - alpha;
 
+					if( alphaIndex % 2 === 0 ) {
+						localReflectionCube = null;
+					}
+					else {
+						localReflectionCube = reflectionCube;
+					}
+
 					for( var beta = 0; beta <= 1.0; beta += stepSize ) {
 
 						var metalness = beta;
@@ -102,7 +110,7 @@
 							// basic monochromatic energy preservation
 							var diffuseColor = new THREE.Color( gamma, 0, 0 ).multiplyScalar( 1 - 0.08 );
 
-							var material = new THREE.MeshPhysicalMaterial( { map: imgTexture, bumpMap: imgTexture, bumpScale: bumpScale, color: diffuseColor, metalness: metalness, roughness: roughness, shading: THREE.SmoothShading, envMap: reflectionCube } )
+							var material = new THREE.MeshPhysicalMaterial( { map: imgTexture, bumpMap: imgTexture, bumpScale: bumpScale, color: diffuseColor, metalness: metalness, roughness: roughness, shading: THREE.SmoothShading, envMap: localReflectionCube } )
 
 							var mesh = new THREE.Mesh( geometry, material );
 

+ 4 - 1
src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl

@@ -1,6 +1,9 @@
+#if defined( PHYSICAL ) || defined( USE_ENVMAP )
+	uniform float reflectivity;
+#endif
+
 #ifdef USE_ENVMAP
 
-	uniform float reflectivity;
 	#ifdef ENVMAP_TYPE_CUBE
 		uniform samplerCube envMap;
 	#else