Add clamp to keep speccolor non-negative.

Make spot shadowing more consistent.
meow-7.2.2
Graham Linden 2019-03-25 14:52:23 -07:00
parent 9c8cc0037a
commit d99e2e119f
3 changed files with 13 additions and 14 deletions

View File

@ -135,13 +135,14 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
float sa = nh;
float fres = pow(1 - dot(h, npos), 5)*0.4+0.5;
float gtdenom = 2 * nh;
float gtdenom = abs(2 * nh);
float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh));
if (nh > 0.0)
if (gtdenom > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
vec3 speccol = lit*scol*light_col.rgb*spec.rgb;
speccol = max(speccol, vec3(0));
col += speccol;
float cur_glare = max(speccol.r, speccol.g);

View File

@ -154,10 +154,8 @@ void main()
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
shadow = max(shd.b, shd.a) + shadow_fade;
shadow = clamp(shadow, 0.0, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
@ -255,8 +253,9 @@ void main()
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
vec3 speccol = dlit*scol*spec.rgb*shadow;
speccol = max(speccol, vec3(0));
col += speccol;
}
}

View File

@ -154,10 +154,8 @@ void main()
if (proj_shadow_idx >= 0)
{
vec4 shd = texture2DRect(lightMap, frag.xy);
float sh[2];
sh[0] = shd.b;
sh[1] = shd.a;
shadow = min(sh[proj_shadow_idx]+shadow_fade, 1.0);
shadow = max(shd.b, shd.a) + shadow_fade;
shadow = min(shadow, 1.0);
}
vec3 norm = texture2DRect(normalMap, frag.xy).xyz;
@ -254,8 +252,9 @@ void main()
if (nh > 0.0)
{
float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*da);
col += dlit*scol*spec.rgb*shadow;
//col += spec.rgb;
vec3 speccol = dlit*scol*spec.rgb*shadow;
speccol = max(speccol, vec3(0));
col += speccol;
}
}