Explorar el Código

fix deferred rendering broken by outgoing light refactor.

Ben Houston hace 10 años
padre
commit
fcb425ebe1
Se han modificado 1 ficheros con 8 adiciones y 5 borrados
  1. 8 5
      examples/js/ShaderDeferred.js

+ 8 - 5
examples/js/ShaderDeferred.js

@@ -187,7 +187,8 @@ THREE.ShaderDeferred = {
 
 				"const float opacity = 1.0;",
 
-				"gl_FragColor = vec4( diffuse, opacity );",
+				"vec3 outgoingLight = vec3( 0.0 );",	// outgoing light does not have an alpha, the surface does
+				"vec4 diffuseColor = vec4( diffuse, opacity );",
 
 				THREE.ShaderChunk[ "map_fragment" ],
 				THREE.ShaderChunk[ "alphatest_fragment" ],
@@ -195,6 +196,8 @@ THREE.ShaderDeferred = {
 				THREE.ShaderChunk[ "lightmap_fragment" ],
 				THREE.ShaderChunk[ "color_fragment" ],
 
+				"outgoingLight = diffuseColor.rgb;",
+
 				"#ifdef USE_ENVMAP",
 
 					"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
@@ -230,15 +233,15 @@ THREE.ShaderDeferred = {
 
 					"if ( combine == 1 ) {",
 
-						"gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );",
+						"outgoingLight = mix( outgoingLight, cubeColor.xyz, specularStrength * reflectivity );",
 
 					"} else if ( combine == 2 ) {",
 
-						"gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;",
+						"outgoingLight += cubeColor.xyz * specularStrength * reflectivity;",
 
 					"} else {",
 
-						"gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
+						"outgoingLight = mix( outgoingLight.xyz, diffuseColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
 
 					"}",
 
@@ -267,7 +270,7 @@ THREE.ShaderDeferred = {
 
 				// diffuse color
 
-				"gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
+				"gl_FragColor.x = vec3_to_float( compressionScale * outgoingLight.xyz );",
 
 				// specular color