summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl63
1 files changed, 35 insertions, 28 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
index 747f1dacdd..70568bc75f 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
@@ -48,28 +48,44 @@ 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 pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir)
+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)
{
stc.xyz /= stc.w;
- 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
+ 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
float cs = shadow2D(shadowMap, stc.xyz).x;
- float shadow = cs * 4.0;
-
+ 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.125;
+ return shadow*0.2;
}
float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen)
@@ -95,10 +111,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 = (sun_up_factor > 0) ? dp_sun : dp_moon;
+ float dp_directional_light = max(dp_sun,dp_moon);
dp_directional_light = clamp(dp_directional_light, 0.0, 1.0);
- vec3 light_dir = (sun_up_factor > 0) ? sun_dir : moon_dir;
+ vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir;
vec3 offset = light_dir * (1.0-dp_directional_light);
vec3 shadow_pos = pos.xyz + (offset * shadow_bias);
@@ -125,7 +141,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 += pcfShadow(shadowMap3, lpos, 0.25, pos_screen, light_dir)*w;
+ shadow += pcfShadowLegacy(shadowMap3, lpos)*w;
weight += w;
shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);
}
@@ -137,7 +153,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 += pcfShadow(shadowMap2, lpos, 0.5, pos_screen, light_dir)*w;
+ shadow += pcfShadowLegacy(shadowMap2, lpos)*w;
weight += w;
}
@@ -148,7 +164,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 += pcfShadow(shadowMap1, lpos, 0.75, pos_screen, light_dir)*w;
+ shadow += pcfShadowLegacy(shadowMap1, lpos)*w;
weight += w;
}
@@ -159,15 +175,14 @@ 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 += pcfShadow(shadowMap0, lpos, 1.0, pos_screen, light_dir)*w;
+ shadow += pcfShadowLegacy(shadowMap0, lpos)*w;
weight += w;
}
shadow /= weight;
}
- shadow = min(dp_directional_light, shadow);
- return shadow;
+ return min(dp_directional_light, shadow);
}
float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen)
@@ -186,19 +201,11 @@ 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;
-
- 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;
- }
+
+ shadow += pcfSpotShadow((index == 0) ? shadowMap4 : 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);
}