ソースを参照

ensure that lightMap is modulated by surface color and then added to resulting fragColor.

Ben Houston 10 年 前
コミット
fd500a63e9

+ 9 - 1
src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl

@@ -1,5 +1,13 @@
 #ifdef USE_LIGHTMAP
 
-	gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );
+	#if defined( PHONG )
+
+		gl_FragColor += diffuseColor * texture2D( lightMap, vUv2 );
+
+	#else 
+		
+		gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );
+
+	#endif
 
 #endif

+ 10 - 10
src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl

@@ -33,7 +33,7 @@ vec3 viewPosition = normalize( vViewPosition );
 
 		lVector = normalize( lVector );
 
-				// diffuse
+		// diffuse
 
 		float dotProduct = dot( normal, lVector );
 
@@ -50,7 +50,7 @@ vec3 viewPosition = normalize( vViewPosition );
 
 		#endif
 
-		pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;
+		pointDiffuse += pointLightColor[ i ] * pointDiffuseWeight * lDistance;
 
 				// specular
 
@@ -89,7 +89,7 @@ vec3 viewPosition = normalize( vViewPosition );
 
 			spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );
 
-					// diffuse
+			// diffuse
 
 			float dotProduct = dot( normal, lVector );
 
@@ -106,9 +106,9 @@ vec3 viewPosition = normalize( vViewPosition );
 
 			#endif
 
-			spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;
+			spotDiffuse += spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;
 
-					// specular
+			// specular
 
 			vec3 spotHalfVector = normalize( lVector + viewPosition );
 			float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );
@@ -135,7 +135,7 @@ vec3 viewPosition = normalize( vViewPosition );
 		vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
 		vec3 dirVector = normalize( lDirection.xyz );
 
-				// diffuse
+		// diffuse
 
 		float dotProduct = dot( normal, dirVector );
 
@@ -152,7 +152,7 @@ vec3 viewPosition = normalize( vViewPosition );
 
 		#endif
 
-		dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;
+		dirDiffuse += directionalLightColor[ i ] * dirDiffuseWeight;
 
 		// specular
 
@@ -208,7 +208,7 @@ vec3 viewPosition = normalize( vViewPosition );
 
 		vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );
 
-		hemiDiffuse += diffuse * hemiColor;
+		hemiDiffuse += hemiColor;
 
 		// specular (sky light)
 
@@ -269,10 +269,10 @@ vec3 totalSpecular = vec3( 0.0 );
 
 #ifdef METAL
 
-	gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );
+	gl_FragColor.xyz = diffuseColor * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );
 
 #else
 
-	gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
+	gl_FragColor.xyz = diffuseColor * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;
 
 #endif

+ 6 - 0
src/renderers/shaders/ShaderChunk/map_fragment.glsl

@@ -9,5 +9,11 @@
 	#endif
 
 	gl_FragColor = gl_FragColor * texelColor;
+	
+	#if defined( PHONG )
+
+		diffuseColor *= texelColor.xyz;
+
+	#endif
 
 #endif

+ 2 - 1
src/renderers/shaders/ShaderLib.js

@@ -186,7 +186,7 @@ THREE.ShaderLib = {
 			"void main() {",
 
 			"	gl_FragColor = vec4( vec3( 1.0 ), opacity );",
-
+	
 				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
 				THREE.ShaderChunk[ "map_fragment" ],
 				THREE.ShaderChunk[ "alphamap_fragment" ],
@@ -319,6 +319,7 @@ THREE.ShaderLib = {
 			"void main() {",
 
 			"	gl_FragColor = vec4( vec3( 1.0 ), opacity );",
+			"   vec3 diffuseColor = diffuse;",
 
 				THREE.ShaderChunk[ "logdepthbuf_fragment" ],
 				THREE.ShaderChunk[ "map_fragment" ],