|
@@ -7,25 +7,6 @@
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-#ifdef USEDEPTHSTENCILTEXTURE
|
|
|
- float computeShadowFromDepthTextureCube(vec3 lightPosition, samplerCubeShadow shadowSampler, float darkness, vec2 depthValues)
|
|
|
- {
|
|
|
- vec4 directionToLight = vec4(vPositionW - lightPosition, 1.0);
|
|
|
- directionToLight.w = length(directionToLight.xyz);
|
|
|
- directionToLight.w = (directionToLight.w + depthValues.x) / (depthValues.y);
|
|
|
- directionToLight.w = clamp(directionToLight.w, 0., 1.0);
|
|
|
-
|
|
|
- directionToLight.xyz = normalize(directionToLight.xyz);
|
|
|
- directionToLight.y = -directionToLight.y;
|
|
|
-
|
|
|
- float shadow = textureCube(shadowSampler, directionToLight);
|
|
|
- if (shadow < 1.0)
|
|
|
- {
|
|
|
- return shadow * (1. - darkness) + darkness;
|
|
|
- }
|
|
|
- return 1.0;
|
|
|
- }
|
|
|
-#else
|
|
|
float computeShadowCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, vec2 depthValues)
|
|
|
{
|
|
|
vec3 directionToLight = vPositionW - lightPosition;
|
|
@@ -48,9 +29,8 @@
|
|
|
}
|
|
|
return 1.0;
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
- float computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, float mapSize, float darkness, vec2 depthValues)
|
|
|
+ float computeShadowWithPoissonSamplingCube(vec3 lightPosition, samplerCube shadowSampler, float mapSize, float darkness, vec2 depthValues)
|
|
|
{
|
|
|
vec3 directionToLight = vPositionW - lightPosition;
|
|
|
float depth = length(directionToLight);
|
|
@@ -85,6 +65,26 @@
|
|
|
return min(1.0, visibility + darkness);
|
|
|
}
|
|
|
|
|
|
+#ifdef WEBGL2
|
|
|
+ float computeShadowWithPCFCube(vec3 lightPosition, samplerCubeShadow shadowSampler, float darkness, vec2 depthValues)
|
|
|
+ {
|
|
|
+ vec4 directionToLight = vec4(vPositionW - lightPosition, 1.0);
|
|
|
+ directionToLight.w = length(directionToLight.xyz);
|
|
|
+ directionToLight.w = (directionToLight.w + depthValues.x) / (depthValues.y);
|
|
|
+ directionToLight.w = clamp(directionToLight.w, 0., 1.0);
|
|
|
+
|
|
|
+ directionToLight.xyz = normalize(directionToLight.xyz);
|
|
|
+ directionToLight.y = -directionToLight.y;
|
|
|
+
|
|
|
+ float shadow = textureCube(shadowSampler, directionToLight);
|
|
|
+ if (shadow < 1.0)
|
|
|
+ {
|
|
|
+ return shadow * (1. - darkness) + darkness;
|
|
|
+ }
|
|
|
+ return 1.0;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
float computeShadowWithESMCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, float depthScale, vec2 depthValues)
|
|
|
{
|
|
|
vec3 directionToLight = vPositionW - lightPosition;
|
|
@@ -126,27 +126,6 @@
|
|
|
return esm;
|
|
|
}
|
|
|
|
|
|
-#ifdef USEDEPTHSTENCILTEXTURE
|
|
|
- float computeShadowFromDepthTexture(vec4 vPositionFromLight, float depthMetric, sampler2DShadow shadowSampler, float darkness, float frustumEdgeFalloff)
|
|
|
- {
|
|
|
- vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
|
|
|
- //vec3 uvDepth = vec3(0.5 * clipSpace.xyz + vec3(0.5));
|
|
|
- vec3 uvDepth = vec3(0.5 * clipSpace.xy + vec2(0.5), depthMetric);
|
|
|
-
|
|
|
- if (uvDepth.x < 0. || uvDepth.x > 1.0 || uvDepth.y < 0. || uvDepth.y > 1.0)
|
|
|
- {
|
|
|
- return 1.0;
|
|
|
- }
|
|
|
-
|
|
|
- float shadow = texture2D(shadowSampler, uvDepth);
|
|
|
- if (shadow < 1.0)
|
|
|
- {
|
|
|
- shadow = shadow * (1. - darkness) + darkness;
|
|
|
- return computeFallOff(shadow, clipSpace.xy, frustumEdgeFalloff);
|
|
|
- }
|
|
|
- return 1.0;
|
|
|
- }
|
|
|
-#else
|
|
|
float computeShadow(vec4 vPositionFromLight, float depthMetric, sampler2D shadowSampler, float darkness, float frustumEdgeFalloff)
|
|
|
{
|
|
|
vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
|
|
@@ -171,9 +150,8 @@
|
|
|
}
|
|
|
return 1.;
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
- float computeShadowWithPCF(vec4 vPositionFromLight, float depthMetric, sampler2D shadowSampler, float mapSize, float darkness, float frustumEdgeFalloff)
|
|
|
+ float computeShadowWithPoissonSampling(vec4 vPositionFromLight, float depthMetric, sampler2D shadowSampler, float mapSize, float darkness, float frustumEdgeFalloff)
|
|
|
{
|
|
|
vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
|
|
|
vec2 uv = 0.5 * clipSpace.xy + vec2(0.5);
|
|
@@ -210,6 +188,28 @@
|
|
|
return computeFallOff(min(1.0, visibility + darkness), clipSpace.xy, frustumEdgeFalloff);
|
|
|
}
|
|
|
|
|
|
+#ifdef WEBGL2
|
|
|
+ float computeShadowWithPCF(vec4 vPositionFromLight, float depthMetric, sampler2DShadow shadowSampler, float darkness, float frustumEdgeFalloff)
|
|
|
+ {
|
|
|
+ vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
|
|
|
+ //vec3 uvDepth = vec3(0.5 * clipSpace.xyz + vec3(0.5));
|
|
|
+ vec3 uvDepth = vec3(0.5 * clipSpace.xy + vec2(0.5), depthMetric);
|
|
|
+
|
|
|
+ if (uvDepth.x < 0. || uvDepth.x > 1.0 || uvDepth.y < 0. || uvDepth.y > 1.0)
|
|
|
+ {
|
|
|
+ return 1.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ float shadow = texture2D(shadowSampler, uvDepth);
|
|
|
+ if (shadow < 1.0)
|
|
|
+ {
|
|
|
+ shadow = shadow * (1. - darkness) + darkness;
|
|
|
+ return computeFallOff(shadow, clipSpace.xy, frustumEdgeFalloff);
|
|
|
+ }
|
|
|
+ return 1.0;
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
float computeShadowWithESM(vec4 vPositionFromLight, float depthMetric, sampler2D shadowSampler, float darkness, float depthScale, float frustumEdgeFalloff)
|
|
|
{
|
|
|
vec3 clipSpace = vPositionFromLight.xyz / vPositionFromLight.w;
|