Browse Source

Examples: Use loop unroll in PCSS demo. (#22646)

Michael Herzog 3 years ago
parent
commit
094730f334
1 changed files with 10 additions and 6 deletions
  1. 10 6
      examples/webgl_shadowmap_pcss.html

+ 10 - 6
examples/webgl_shadowmap_pcss.html

@@ -29,7 +29,6 @@
 				#define NUM_SAMPLES 17
 				#define NUM_SAMPLES 17
 				#define NUM_RINGS 11
 				#define NUM_RINGS 11
 				#define BLOCKER_SEARCH_NUM_SAMPLES NUM_SAMPLES
 				#define BLOCKER_SEARCH_NUM_SAMPLES NUM_SAMPLES
-				#define PCF_NUM_SAMPLES NUM_SAMPLES
 
 
 				vec2 poissonDisk[NUM_SAMPLES];
 				vec2 poissonDisk[NUM_SAMPLES];
 
 
@@ -75,15 +74,20 @@
 
 
 				float PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius ) {
 				float PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius ) {
 					float sum = 0.0;
 					float sum = 0.0;
-					for( int i = 0; i < PCF_NUM_SAMPLES; i ++ ) {
-						float depth = unpackRGBAToDepth( texture2D( shadowMap, uv + poissonDisk[ i ] * filterRadius ) );
+					float depth;
+					#pragma unroll_loop_start
+					for( int i = 0; i < 17; i ++ ) {
+						depth = unpackRGBAToDepth( texture2D( shadowMap, uv + poissonDisk[ i ] * filterRadius ) );
 						if( zReceiver <= depth ) sum += 1.0;
 						if( zReceiver <= depth ) sum += 1.0;
 					}
 					}
-					for( int i = 0; i < PCF_NUM_SAMPLES; i ++ ) {
-						float depth = unpackRGBAToDepth( texture2D( shadowMap, uv + -poissonDisk[ i ].yx * filterRadius ) );
+					#pragma unroll_loop_end
+					#pragma unroll_loop_start
+					for( int i = 0; i < 17; i ++ ) {
+						depth = unpackRGBAToDepth( texture2D( shadowMap, uv + -poissonDisk[ i ].yx * filterRadius ) );
 						if( zReceiver <= depth ) sum += 1.0;
 						if( zReceiver <= depth ) sum += 1.0;
 					}
 					}
-					return sum / ( 2.0 * float( PCF_NUM_SAMPLES ) );
+					#pragma unroll_loop_end
+					return sum / ( 2.0 * float( 17 ) );
 				}
 				}
 
 
 				float PCSS ( sampler2D shadowMap, vec4 coords ) {
 				float PCSS ( sampler2D shadowMap, vec4 coords ) {