瀏覽代碼

Forward shader of pbr renderer does not sample shadow maps if the light intensity is close to zero, improving performance a lot.

clementlandrin 1 年之前
父節點
當前提交
c77d50db25
共有 1 個文件被更改,包括 24 次插入8 次删除
  1. 24 8
      h3d/shader/pbr/DefaultForward.hx

+ 24 - 8
h3d/shader/pbr/DefaultForward.hx

@@ -242,8 +242,12 @@ class DefaultForward extends hxsl.Shader {
 			F0 = mix(pbrSpecularColor, albedoGamma, metalness);
 
 			// Dir Light With Shadow
-			@unroll for( l in 0 ... DIR_SHADOW_COUNT )
-				lightAccumulation += evaluateDirLight(l) * evaluateDirShadow(l);
+			@unroll for( l in 0 ... DIR_SHADOW_COUNT ) {
+				var c = evaluateDirLight(l);
+				if ( dot(c, c) > 1e-6 )
+					c *= evaluateDirShadow(l);
+				lightAccumulation += c;
+			}
 			// Dir Light
 			var start = DIR_SHADOW_COUNT;
 			if ( CASCADE_COUNT > 0 )
@@ -252,22 +256,34 @@ class DefaultForward extends hxsl.Shader {
 				lightAccumulation += evaluateDirLight(l);
 
 			// Point Light With Shadow
-			@unroll for( l in 0 ... POINT_SHADOW_COUNT )
-				lightAccumulation += evaluatePointLight(l) * evaluatePointShadow(l);
+			@unroll for( l in 0 ... POINT_SHADOW_COUNT ) {
+				var c = evaluatePointLight(l);
+				if ( dot(c, c) > 1e-6 )
+					c *= evaluatePointShadow(l);
+				lightAccumulation += c;
+			}
 			// Point Light
 			@unroll for( l in POINT_SHADOW_COUNT ... pointLightCount + POINT_SHADOW_COUNT )
 				lightAccumulation += evaluatePointLight(l);
 
 			// Spot Light With Shadow
-			@unroll for( l in 0 ... SPOT_SHADOW_COUNT )
-				lightAccumulation += evaluateSpotLight(l) * evaluateSpotShadow(l);
+			@unroll for( l in 0 ... SPOT_SHADOW_COUNT ) {
+				var c = evaluateSpotLight(l);
+				if ( dot(c, c) > 1e-6 )
+					c *= evaluateSpotShadow(l);
+				lightAccumulation += c;
+			}
 			// Spot Light
 			@unroll for( l in SPOT_SHADOW_COUNT ... spotLightCount + SPOT_SHADOW_COUNT )
 				lightAccumulation += evaluateSpotLight(l);
 
 			// Cascade shadows
-			if ( CASCADE_COUNT > 0 )
-				lightAccumulation += evaluateCascadeLight() * evaluateCascadeShadow();
+			if ( CASCADE_COUNT > 0 ) {
+				var c = evaluateCascadeLight();
+				if ( dot(c, c) > 1e-6 )
+					c *= evaluateCascadeShadow();
+				lightAccumulation += c;
+			}
 
 			// Indirect only support the main env from the scene at the moment
 			if( USE_INDIRECT )