|
@@ -1,6 +1,5 @@
|
|
|
#ifdef USE_SHADOWMAP
|
|
|
|
|
|
- uniform int isShadowCube[ MAX_SHADOWS ];
|
|
|
uniform samplerCube shadowCube[ MAX_SHADOWS ];
|
|
|
uniform sampler2D shadowMap[ MAX_SHADOWS ];
|
|
|
uniform vec2 shadowMapSize[ MAX_SHADOWS ];
|
|
@@ -8,10 +7,7 @@
|
|
|
uniform float shadowDarkness[ MAX_SHADOWS ];
|
|
|
uniform float shadowBias[ MAX_SHADOWS ];
|
|
|
|
|
|
- uniform vec3 shadowLightPosition[ MAX_SHADOWS ];
|
|
|
-
|
|
|
varying vec4 vShadowCoord[ MAX_SHADOWS ];
|
|
|
- varying vec4 vWPosition[ MAX_SHADOWS ];
|
|
|
|
|
|
float unpackDepth( const in vec4 rgba_depth ) {
|
|
|
|
|
@@ -21,25 +17,25 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- vec4 pack1K (float depth) {
|
|
|
+ vec4 pack1K ( float depth ) {
|
|
|
|
|
|
depth /= 1000.0;
|
|
|
- const vec4 bitSh = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
|
|
|
- const vec4 bitMsk = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
|
|
|
- vec4 res = fract(depth * bitSh);
|
|
|
+ const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
|
|
|
+ const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
|
|
|
+ vec4 res = fract( depth * bitSh );
|
|
|
res -= res.xxyz * bitMsk;
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
- float unpack1K (vec4 color) {
|
|
|
+ float unpack1K ( vec4 color ) {
|
|
|
|
|
|
- const vec4 bitSh = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
|
|
|
- return dot(color, bitSh) * 1000.0;
|
|
|
+ const vec4 bitSh = vec4( 1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 );
|
|
|
+ return dot( color, bitSh ) * 1000.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
- vec3 gridSamplingDisk[20];
|
|
|
+ vec3 gridSamplingDisk[ 20 ];
|
|
|
int gridSamplingInitialized = 0;
|
|
|
|
|
|
void initGridSamplingDisk(){
|
|
@@ -67,17 +63,35 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- float getCubeMapFloat(in samplerCube cube, in vec3 baseDirection){
|
|
|
-
|
|
|
- vec4 data = textureCube(cube, baseDirection);
|
|
|
+ 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(in samplerCube cube, in vec3 baseDirection, in float curDistance, in float texSize, float softness){
|
|
|
+ float sampleCubeShadowMapPCF( const in int cubeIndex, in vec3 baseDirection, in float curDistance, in float texSize, float softness ){
|
|
|
|
|
|
- if( gridSamplingInitialized == 0){
|
|
|
+ if( gridSamplingInitialized == 0 ){
|
|
|
|
|
|
initGridSamplingDisk();
|
|
|
gridSamplingInitialized = 1;
|
|
@@ -89,17 +103,17 @@
|
|
|
float numSamples = 0.0;
|
|
|
float shadowFactor = 0.0;
|
|
|
|
|
|
- float dist = getCubeMapFloat(cube, baseDirection);
|
|
|
- if ( curDistance >= dist)
|
|
|
+ float dist = getCubeShadowMapFloat( cubeIndex, baseDirection );
|
|
|
+ if ( curDistance >= dist )
|
|
|
shadowFactor += 1.0;
|
|
|
numSamples += 1.0;
|
|
|
|
|
|
// evaluate each sampling direction
|
|
|
- for(int i=0; i<20; i++){
|
|
|
-
|
|
|
- vec3 offset = gridSamplingDisk[i] * diskRadius * texSize;
|
|
|
- dist = getCubeMapFloat(cube, vec3(baseDirection + offset));
|
|
|
- if ( curDistance >= dist)
|
|
|
+ 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;
|
|
|
|
|
@@ -107,6 +121,7 @@
|
|
|
|
|
|
shadowFactor /= numSamples;
|
|
|
return shadowFactor;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
#endif
|