Bladeren bron

WebGLDeferredRenderer: optimized spotlight shader.

alteredq 12 jaren geleden
bovenliggende
commit
96fd7a947f
1 gewijzigde bestanden met toevoegingen van 18 en 25 verwijderingen
  1. 18 25
      examples/js/ShaderDeferred.js

+ 18 - 25
examples/js/ShaderDeferred.js

@@ -604,46 +604,39 @@ THREE.ShaderDeferred = {
 				"float rho = dot( lightDirectionVS, lightVector );",
 				"float rho = dot( lightDirectionVS, lightVector );",
 				"float rhoMax = cos( lightAngle * 0.5 );",
 				"float rhoMax = cos( lightAngle * 0.5 );",
 
 
-				"if ( rho > rhoMax ) {",
+				"if ( rho <= rhoMax ) discard;",
 
 
-					"float theta = rhoMax + 0.0001;",
-					"float phi = rhoMax + 0.05;",
-					"float falloff = 4.0;",
+				"float theta = rhoMax + 0.0001;",
+				"float phi = rhoMax + 0.05;",
+				"float falloff = 4.0;",
 
 
-					"float spot = 0.0;",
+				"float spot = 0.0;",
 
 
-					"if ( rho >= phi ) {",
+				"if ( rho >= phi ) {",
 
 
-						"spot = 1.0;",
+					"spot = 1.0;",
 
 
-					"} else if ( rho <= theta ) {",
+				"} else if ( rho <= theta ) {",
 
 
-						"spot = 0.0;",
+					"spot = 0.0;",
 
 
-					"} else { ",
-
-						"spot = pow( ( rho - theta ) / ( phi - theta ), falloff );",
-
-					"}",
+				"} else { ",
 
 
+					"spot = pow( ( rho - theta ) / ( phi - theta ), falloff );",
 
 
-					THREE.DeferredShaderChunk[ "computeDiffuse" ],
-
-					"diffuse *= spot;",
-
-					THREE.DeferredShaderChunk[ "computeSpecular" ],
+				"}",
 
 
-					// combine
+				THREE.DeferredShaderChunk[ "computeDiffuse" ],
 
 
-					"const float attenuation = 1.0;",
+				"diffuse *= spot;",
 
 
-					THREE.DeferredShaderChunk[ "combine" ],
+				THREE.DeferredShaderChunk[ "computeSpecular" ],
 
 
-					"return;",
+				// combine
 
 
-				"}",
+				"const float attenuation = 1.0;",
 
 
-				"gl_FragColor = vec4( 0.0 );",
+				THREE.DeferredShaderChunk[ "combine" ],
 
 
 			"}"
 			"}"