|
|
@@ -166,7 +166,7 @@ float GetDiffuseVolumetric(vec3 worldPos)
|
|
|
// https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model
|
|
|
float GetSpecular(vec3 normal, vec3 eyeVec, vec3 lightDir, float specularPower)
|
|
|
{
|
|
|
- vec3 halfVec = normalize(normalize(eyeVec) + lightDir);
|
|
|
+ vec3 halfVec = normalize(normalize(eyeVec) + lightDir);
|
|
|
return pow(max(dot(normal, halfVec), 0.0), specularPower);
|
|
|
}
|
|
|
|
|
|
@@ -184,23 +184,23 @@ float GetIntensity(vec3 color)
|
|
|
#endif
|
|
|
|
|
|
#ifdef VSM_SHADOW
|
|
|
-float ReduceLightBleeding(float min, float p_max)
|
|
|
-{
|
|
|
- return clamp((p_max - min) / (1.0 - min), 0.0, 1.0);
|
|
|
+float ReduceLightBleeding(float min, float p_max)
|
|
|
+{
|
|
|
+ return clamp((p_max - min) / (1.0 - min), 0.0, 1.0);
|
|
|
}
|
|
|
|
|
|
-float Chebyshev(vec2 Moments, float depth)
|
|
|
-{
|
|
|
- //One-tailed inequality valid if depth > Moments.x
|
|
|
- float p = float(depth <= Moments.x);
|
|
|
- //Compute variance.
|
|
|
- float Variance = Moments.y - (Moments.x * Moments.x);
|
|
|
+float Chebyshev(vec2 Moments, float depth)
|
|
|
+{
|
|
|
+ //One-tailed inequality valid if depth > Moments.x
|
|
|
+ float p = float(depth <= Moments.x);
|
|
|
+ //Compute variance.
|
|
|
+ float Variance = Moments.y - (Moments.x * Moments.x);
|
|
|
|
|
|
float minVariance = cVSMShadowParams.x;
|
|
|
Variance = max(Variance, minVariance);
|
|
|
- //Compute probabilistic upper bound.
|
|
|
- float d = depth - Moments.x;
|
|
|
- float p_max = Variance / (Variance + d*d);
|
|
|
+ //Compute probabilistic upper bound.
|
|
|
+ float d = depth - Moments.x;
|
|
|
+ float p_max = Variance / (Variance + d*d);
|
|
|
// Prevent light bleeding
|
|
|
p_max = ReduceLightBleeding(cVSMShadowParams.y, p_max);
|
|
|
|
|
|
@@ -239,7 +239,7 @@ float GetShadow(vec4 shadowPos)
|
|
|
textureProj(sShadowMap, vec4(shadowPos.xy + offsets.xy, shadowPos.zw)));
|
|
|
#endif
|
|
|
#elif defined(VSM_SHADOW)
|
|
|
- vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg;
|
|
|
+ vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg;
|
|
|
return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z / shadowPos.w);
|
|
|
#endif
|
|
|
}
|
|
|
@@ -260,7 +260,7 @@ float GetShadow(highp vec4 shadowPos)
|
|
|
);
|
|
|
return cShadowIntensity.y + dot(inLight, vec4(cShadowIntensity.x));
|
|
|
#elif defined(VSM_SHADOW)
|
|
|
- vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg;
|
|
|
+ vec2 samples = texture2D(sShadowMap, shadowPos.xy / shadowPos.w).rg;
|
|
|
return cShadowIntensity.y + cShadowIntensity.x * Chebyshev(samples, shadowPos.z / shadowPos.w);
|
|
|
#endif
|
|
|
}
|
|
|
@@ -307,7 +307,7 @@ float GetDirShadow(const vec4 iShadowPos[NUMCASCADES], float depth)
|
|
|
shadowPos = iShadowPos[2];
|
|
|
else
|
|
|
shadowPos = iShadowPos[3];
|
|
|
-
|
|
|
+
|
|
|
return GetDirShadowFade(GetShadow(shadowPos), depth);
|
|
|
}
|
|
|
#else
|