|
@@ -117,11 +117,14 @@ void main(void)
|
|
#define PI 3.1415926535897932384626433832795
|
|
#define PI 3.1415926535897932384626433832795
|
|
|
|
|
|
uniform mat4 shadowViewProjection;
|
|
uniform mat4 shadowViewProjection;
|
|
|
|
+uniform mat4 lightWorld;
|
|
|
|
|
|
uniform vec3 cameraPosition;
|
|
uniform vec3 cameraPosition;
|
|
uniform vec3 sunDirection;
|
|
uniform vec3 sunDirection;
|
|
uniform vec3 sunColor;
|
|
uniform vec3 sunColor;
|
|
|
|
|
|
|
|
+uniform vec2 depthValues;
|
|
|
|
+
|
|
uniform float scatteringCoefficient;
|
|
uniform float scatteringCoefficient;
|
|
uniform float scatteringPower;
|
|
uniform float scatteringPower;
|
|
|
|
|
|
@@ -154,12 +157,15 @@ void main(void)
|
|
for (int i = 0; i < int(NB_STEPS); i++)
|
|
for (int i = 0; i < int(NB_STEPS); i++)
|
|
{
|
|
{
|
|
vec4 worldInShadowCameraSpace = shadowViewProjection * vec4(currentPosition, 1.0);
|
|
vec4 worldInShadowCameraSpace = shadowViewProjection * vec4(currentPosition, 1.0);
|
|
|
|
+ float depthMetric = (worldInShadowCameraSpace.z + depthValues.x) / (depthValues.y);
|
|
|
|
+ float shadowPixelDepth = clamp(depthMetric, 0.0, 1.0);
|
|
|
|
+
|
|
worldInShadowCameraSpace.xyz /= worldInShadowCameraSpace.w;
|
|
worldInShadowCameraSpace.xyz /= worldInShadowCameraSpace.w;
|
|
worldInShadowCameraSpace.xyz = 0.5 * worldInShadowCameraSpace.xyz + vec3(0.5);
|
|
worldInShadowCameraSpace.xyz = 0.5 * worldInShadowCameraSpace.xyz + vec3(0.5);
|
|
|
|
|
|
float shadowMapValue = texture2D(shadowMapSampler, worldInShadowCameraSpace.xy).r;
|
|
float shadowMapValue = texture2D(shadowMapSampler, worldInShadowCameraSpace.xy).r;
|
|
|
|
|
|
- if (shadowMapValue > worldInShadowCameraSpace.z)
|
|
|
|
|
|
+ if (shadowMapValue > shadowPixelDepth)
|
|
accumFog += sunColor * computeScattering(dot(rayDirection, sunDirection));
|
|
accumFog += sunColor * computeScattering(dot(rayDirection, sunDirection));
|
|
|
|
|
|
currentPosition += stepL;
|
|
currentPosition += stepL;
|