summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2019-04-04 17:19:59 -0700
committerGraham Linden <graham@lindenlab.com>2019-04-04 17:19:59 -0700
commitc699ee9a7f102aa541dcc102e8fa1de2d6c55bde (patch)
treedef96651f72240631470b900e63858f79349ee53 /indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
parente4c281c134994a32cc006d7036aa811f9ed33799 (diff)
SL-10854
Clamp ambient contrib to get darker shadows. New PCF sampling func.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl43
1 files changed, 37 insertions, 6 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
index 6ff49c7dac..2d2d00cb51 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl
@@ -46,21 +46,52 @@ uniform mat4 inv_proj;
uniform vec2 screen_res;
uniform int sun_up_factor;
+const float sample_count = 5;
+
+float cGoldenAngle = 2.39996323f;
+
float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir)
{
stc.xyz /= stc.w;
+ stc.z += shadow_bias * bias_mul * 4.0;
+
+ float shadow = 0.0;
+ float cs = shadow2D(shadowMap, stc.xyz).x;
+ float initialTheta = cGoldenAngle*fract((pos_screen.y+pos_screen.x)*shadow_res.y);
+ float theta = initialTheta;
+ int i;
+ for (i = 0; i < sample_count; i++)
+ {
+ float r = float(i) / float(sample_count);
+ float weight = sqrt(1.0 - r);
+ r = sqrt(r);
+ vec2 sampleOffset;
+ sampleOffset.x = cos(theta);
+ sampleOffset.y = sin(theta);
+ sampleOffset *= r * 2.0;
+ float s = shadow2D(shadowMap, stc.xyz + vec3(sampleOffset, 0)).x;
+ shadow += weight * s;
+ theta += cGoldenAngle;
+ }
+ shadow /= float(sample_count);
+ shadow += cs;
+ shadow *= 0.5;
+ return shadow;
+}
+
+float pcfShadowOld(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir)
+{
+ stc.xyz /= stc.w;
+
+ float cs = shadow2D(shadowMap, stc.xyz).x;
stc.z += shadow_bias * bias_mul * 2.0;
stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/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)