Browse Source

WebGLDeferredRenderer: closer look to forward renderer.

Make specular term multiplicative when specular color is zero.
alteredq 12 years ago
parent
commit
7649278955
1 changed files with 14 additions and 1 deletions
  1. 14 1
      examples/js/ShaderDeferred.js

+ 14 - 1
examples/js/ShaderDeferred.js

@@ -176,6 +176,8 @@ THREE.ShaderDeferred = {
 
 				"}",
 
+				"gl_FragColor.y *= additiveSpecular;",
+
 				// shininess
 
 				"gl_FragColor.z = wrapAround * shininess;",
@@ -449,6 +451,7 @@ THREE.ShaderDeferred = {
 				"vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
 				"float shininess = abs( colorMap.z );",
 				"float wrapAround = sign( colorMap.z );",
+				"float additiveSpecular = sign( colorMap.y );",
 
 				// light
 
@@ -492,7 +495,17 @@ THREE.ShaderDeferred = {
 				// combine
 
 				"vec3 light = lightIntensity * lightColor;",
-				"gl_FragColor = vec4( light * ( albedo * diffuse + specular ), attenuation );",
+
+				"if ( additiveSpecular < 0.0 ) {",
+
+					"gl_FragColor = vec4( light * ( albedo * diffuse + specular ), attenuation );",
+
+				"} else {",
+
+					"gl_FragColor = vec4( light * albedo * ( diffuse + specular ), attenuation );",
+
+				"}",
+
 
 			"}"