浏览代码

Fixed specular light vs black texture bug in Phong shader.

alteredq 14 年之前
父节点
当前提交
fd0fb85c8e
共有 4 个文件被更改,包括 8 次插入5 次删除
  1. 0 0
      build/Three.js
  2. 0 0
      build/custom/ThreeWebGL.js
  3. 1 1
      examples/webgl_materials.html
  4. 7 4
      src/renderers/WebGLShaders.js

文件差异内容过多而无法显示
+ 0 - 0
build/Three.js


文件差异内容过多而无法显示
+ 0 - 0
build/custom/ThreeWebGL.js


+ 1 - 1
examples/webgl_materials.html

@@ -77,7 +77,7 @@
 				//materials.push( new THREE.MeshBasicMaterial( { color: 0xff0000, blending: THREE.SubtractiveBlending } ) );
 
 				materials.push( new THREE.MeshLambertMaterial( { color: 0xdddddd, shading: THREE.SmoothShading } ) );
-				materials.push( new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.SmoothShading } ) );
+				materials.push( new THREE.MeshPhongMaterial( { ambient: 0x030303, color: 0xdddddd, specular: 0x009900, shininess: 30, shading: THREE.SmoothShading, map: THREE.ImageUtils.loadTexture( "textures/planets/earth_specular_2048.jpg" ) } ) );
 				materials.push( new THREE.MeshNormalMaterial( { shading: THREE.SmoothShading } ) );
 				materials.push( new THREE.MeshBasicMaterial( { color: 0xffaa00, wireframe: true } ) );
 

+ 7 - 4
src/renderers/WebGLShaders.js

@@ -391,21 +391,24 @@ THREE.ShaderChunk = {
 
 	"#endif",
 
-	"vec4 totalLight = vec4( ambient, opacity );",
+	"vec4 totalDiffuse = vec4( vec3( 0.0 ), opacity );",
+	"vec4 totalSpecular = vec4( ambient, opacity );",
 
 	"#if MAX_DIR_LIGHTS > 0",
 
-		"totalLight += dirDiffuse + dirSpecular;",
+		"totalDiffuse += dirDiffuse;",
+		"totalSpecular += dirSpecular;",
 
 	"#endif",
 
 	"#if MAX_POINT_LIGHTS > 0",
 
-		"totalLight += pointDiffuse + pointSpecular;",
+		"totalDiffuse += pointDiffuse;",
+		"totalSpecular += pointSpecular;",
 
 	"#endif",
 
-	"gl_FragColor = gl_FragColor * totalLight;"
+	"gl_FragColor = gl_FragColor * totalDiffuse + totalSpecular;"
 
 	].join("\n"),
 

部分文件因为文件数量过多而无法显示