SL-10854 part 2

Clamp ambient to keep shadows dark.

Apply min with shadow value after we've pow'd by light gamma consistently between forward and deferred.
master
Graham Linden 2019-04-05 09:19:46 -07:00
parent fa6f770a89
commit 09bb0336f1
4 changed files with 19 additions and 52 deletions

View File

@ -196,9 +196,7 @@ void main()
float da = dot(norm.xyz, light_dir.xyz);
float final_da = da;
final_da = min(final_da, shadow);
final_da = max(final_da, 0.0f);
final_da = min(final_da, 1.0f);
final_da = clamp(final_da, 0.0f, 1.0f);
final_da = pow(final_da, 1.0/1.3);
vec4 color = vec4(0,0,0,0);
@ -209,9 +207,10 @@ void main()
float ambient = abs(da);
ambient *= 0.5;
ambient *= ambient;
ambient = 1.0 - max(0.9, ambient);
ambient = max(0.9, ambient); // keeps shadows dark
ambient = 1.0 - ambient;
vec3 sun_contrib = final_da * sunlit;
vec3 sun_contrib = min(final_da, shadow) * sunlit;
color.rgb *= ambient;
color.rgb += sun_contrib;

View File

@ -296,16 +296,18 @@ void main()
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
float da = dot(norm.xyz, light_dir.xyz);
da = clamp(da, 0.0, 1.0);
da = pow(da, 1.0 / 1.3);
float final_da = da;
final_da = clamp(final_da, 0.0, 1.0);
final_da = pow(final_da, 1.0 / 1.3);
float ambient = abs(da);
ambient *= 0.5;
ambient *= ambient;
ambient = 1.0 - max(0.9, ambient);
ambient = max(0.9, ambient);
ambient = 1.0 - ambient;
float final_da = min(da, shadow);
vec3 sun_contrib = final_da * sunlit;
vec3 sun_contrib = min(final_da, shadow) * sunlit;
col.rgb = amblit;
col.rgb *= ambient;

View File

@ -46,52 +46,18 @@ 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 shadow = cs;
float cs = shadow2D(shadowMap, stc.xyz).x;
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)

View File

@ -94,6 +94,7 @@ void main()
vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir;
float light_gamma = 1.0/1.3;
float scol = 1.0;
vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
@ -102,12 +103,10 @@ void main()
vec4 diffuse = texture2DRect(diffuseRect, tc);
scol = max(scol_ambocc.r, diffuse.a);
//scol = pow(scol, light_gamma);
float final_da = da;
final_da = min(final_da, scol);
final_da = clamp(final_da, 0.0, 1.0);
float light_gamma = 1.0/1.3;
final_da = pow(final_da, light_gamma);
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
@ -126,9 +125,10 @@ void main()
float ambient = abs(da);
ambient *= 0.5;
ambient *= ambient;
ambient = 1.0 - max(0.9, ambient);
ambient = max(0.9, ambient);
ambient = 1.0 - ambient;
vec3 sun_contrib = final_da * sunlit;
vec3 sun_contrib = min(scol, final_da) * sunlit;
col.rgb = amblit;
col.rgb *= ambient;