|
@@ -36,10 +36,16 @@
|
|
|
}
|
|
|
|
|
|
vec3 gridSamplingDisk[ 20 ];
|
|
|
- int gridSamplingInitialized = 0;
|
|
|
+ bool gridSamplingInitialized = false;
|
|
|
|
|
|
void initGridSamplingDisk(){
|
|
|
-
|
|
|
+
|
|
|
+ if( gridSamplingInitialized ){
|
|
|
+
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
gridSamplingDisk[0] = vec3(1, 1, 1);
|
|
|
gridSamplingDisk[1] = vec3(1, -1, 1);
|
|
|
gridSamplingDisk[2] = vec3(-1, -1, 1);
|
|
@@ -60,68 +66,9 @@
|
|
|
gridSamplingDisk[17] = vec3(0, -1, 1);
|
|
|
gridSamplingDisk[18] = vec3(0, -1, -1);
|
|
|
gridSamplingDisk[19] = vec3(0, 1, -1);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- float getCubeShadowMapFloat( const in int cubeIndex, in vec3 baseDirection ){
|
|
|
-
|
|
|
- vec4 data = vec4( 0, 0, 0, 0 );
|
|
|
-
|
|
|
- // This loop may seem silly and unnecessary, but we can't use @cubeIndex to access @shadowCube
|
|
|
- // directly, since its bounds are unknown to the compiler. The compiler
|
|
|
- // knows the bounds of the loop variable 'i' so we CAN use that to index
|
|
|
- // into @shadowCube. The alternative to this is to send the samplerCube directly
|
|
|
- // to this function as a parameter, but come drivers don't allow that.
|
|
|
-
|
|
|
- for( int i = 0; i < MAX_SHADOWS; i++ ) {
|
|
|
-
|
|
|
- if( i == cubeIndex ){
|
|
|
-
|
|
|
- data = textureCube(shadowCube[ i ], baseDirection);
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- float dist = unpack1K( data );
|
|
|
- return dist;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- float sampleCubeShadowMapPCF( const in int cubeIndex, in vec3 baseDirection, in float curDistance, in float texSize, float softness ){
|
|
|
-
|
|
|
- if( gridSamplingInitialized == 0 ){
|
|
|
-
|
|
|
- initGridSamplingDisk();
|
|
|
- gridSamplingInitialized = 1;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // radius of PCF depending on distance from the light source
|
|
|
- float diskRadius = softness;
|
|
|
- float numSamples = 0.0;
|
|
|
- float shadowFactor = 0.0;
|
|
|
-
|
|
|
- float dist = getCubeShadowMapFloat( cubeIndex, baseDirection );
|
|
|
- if ( curDistance >= dist )
|
|
|
- shadowFactor += 1.0;
|
|
|
- numSamples += 1.0;
|
|
|
+ gridSamplingInitialized = true;
|
|
|
|
|
|
- // evaluate each sampling direction
|
|
|
- for( int i = 0; i < 20; i++ ){
|
|
|
-
|
|
|
- vec3 offset = gridSamplingDisk[ i ] * diskRadius * texSize;
|
|
|
- dist = getCubeShadowMapFloat( cubeIndex, vec3( baseDirection + offset ) );
|
|
|
- if ( curDistance >= dist )
|
|
|
- shadowFactor += 1.0;
|
|
|
- numSamples += 1.0;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- shadowFactor /= numSamples;
|
|
|
- return shadowFactor;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#endif
|