summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2019-01-29 09:12:58 -0800
committerGraham Linden <graham@lindenlab.com>2019-01-29 09:12:58 -0800
commit8cb026377e1f790ba333870e2d613e0b55a4311c (patch)
tree079d31c1cbb528873feff5df2aa66d9280d98703
parent431a26c118ec0dea154a2fb2c93ae96ae41b3d7b (diff)
SL-10415
Tweak application of shadow bias to balance between shadow acne and Peter-panning by using light_dir z value, per-split bias multiplier, and better jitter noise method. Also tweak impl of spot shadow sampling func to work around issues with Intel HD shader compiler which crashes with Intel HD 3000 driver 4459 due to shadow map array access with index using math (kwality).
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl63
1 files changed, 28 insertions, 35 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
index 70568bc75f..747f1dacdd 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
@@ -48,44 +48,28 @@ uniform float shadow_bias;
uniform float spot_shadow_bias;
uniform float spot_shadow_offset;
-
+uniform float sun_up_factor;
uniform mat4 inv_proj;
uniform vec2 screen_res;
vec3 decode_normal(vec2 enc);
-float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc)
-{
- stc.xyz /= stc.w;
- stc.z += shadow_bias;
-
- stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here
-
- float cs = shadow2D(shadowMap, stc.xyz).x;
- float shadow = cs;
-
- shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x;
- shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x;
- shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x;
- shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x;
-
- return shadow*0.2;
-}
-
-float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen)
+float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir)
{
stc.xyz /= stc.w;
- stc.z += shadow_bias * bias_scale;
-
- stc.x = floor(stc.x*pos_screen.x + fract(stc.y*pos_screen.y*0.666666666))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here
+ stc.z += max(0.5, light_dir.z) * shadow_bias * 8.0 * bias_mul;
+
+ stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*3.14159))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here
float cs = shadow2D(shadowMap, stc.xyz).x;
- float shadow = cs;
+ float shadow = cs * 4.0;
+
shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x;
shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x;
shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x;
shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x;
- return shadow*0.2;
+
+ return shadow*0.125;
}
float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen)
@@ -111,10 +95,10 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen)
{
float dp_sun = max(0.0, dot(sun_dir.xyz, norm));
float dp_moon = max(0.0, dot(moon_dir.xyz, norm));
- float dp_directional_light = max(dp_sun,dp_moon);
+ float dp_directional_light = (sun_up_factor > 0) ? dp_sun : dp_moon;
dp_directional_light = clamp(dp_directional_light, 0.0, 1.0);
- vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir;
+ vec3 light_dir = (sun_up_factor > 0) ? sun_dir : moon_dir;
vec3 offset = light_dir * (1.0-dp_directional_light);
vec3 shadow_pos = pos.xyz + (offset * shadow_bias);
@@ -141,7 +125,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen)
float w = 1.0;
w -= max(spos.z-far_split.z, 0.0)/transition_domain.z;
- shadow += pcfShadowLegacy(shadowMap3, lpos)*w;
+ shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen, light_dir)*w;
weight += w;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}
@@ -153,7 +137,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen)
float w = 1.0;
w -= max(spos.z-far_split.y, 0.0)/transition_domain.y;
w -= max(near_split.z-spos.z, 0.0)/transition_domain.z;
- shadow += pcfShadowLegacy(shadowMap2, lpos)*w;
+ shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen, light_dir)*w;
weight += w;
}
@@ -164,7 +148,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen)
float w = 1.0;
w -= max(spos.z-far_split.x, 0.0)/transition_domain.x;
w -= max(near_split.y-spos.z, 0.0)/transition_domain.y;
- shadow += pcfShadowLegacy(shadowMap1, lpos)*w;
+ shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen, light_dir)*w;
weight += w;
}
@@ -175,14 +159,15 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen)
float w = 1.0;
w -= max(near_split.x-spos.z, 0.0)/transition_domain.x;
- shadow += pcfShadowLegacy(shadowMap0, lpos)*w;
+ shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w;
weight += w;
}
shadow /= weight;
}
- return min(dp_directional_light, shadow);
+ shadow = min(dp_directional_light, shadow);
+ return shadow;
}
float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen)
@@ -201,11 +186,19 @@ float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen)
float weight = 0.0;
{
- lpos = shadow_matrix[4 + index]*spos;
float w = 1.0;
w -= max(spos.z-far_split.z, 0.0)/transition_domain.z;
-
- shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w;
+
+ if (index == 0)
+ {
+ lpos = shadow_matrix[4]*spos;
+ shadow += pcfSpotShadow(shadowMap4, lpos, 0.8, spos.xy)*w;
+ }
+ else
+ {
+ lpos = shadow_matrix[5]*spos;
+ shadow += pcfSpotShadow(shadowMap5, lpos, 0.8, spos.xy)*w;
+ }
weight += w;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}