// Get shadow value to "red" component
vec4 shadowShade.r=shadow2D(shadowMap, shadowUV.xyz + vec3( 0, 0, 0)).r;
// Copy value to green, blue and set alpha
shadowShade.g=shadowShade.b=shadowShade.r;
shadowShade.a=1.0;
// Calculate attenuation
att = 1.0 / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist +
gl_LightSource[0].quadraticAttenuation * dist * dist);
// Put it all together
color += att * (texture2D(tex,gl_TexCoord[0].st) * NdotL)+ambient;
color *= shadowShade;
// Calculate specular value
halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += att * (gl_FrontMaterial.specular*shadowShade) * (gl_LightSource[0].specular*shadowShade) * pow(NdotHV,gl_FrontMaterial.shininess);
gl_FragColor = color;
Ambient shadows in glsl
Hello!
I've got a shadowmap which range from 0-1 per fragment. If I multiply that shadowmap with my existing light model I get nice shadows, but the shadowed pixels become darker than the ambient... not good. I've asked google on this topic but haven't been able to get a good answer. How do I get ambient shadows?
my fragment program looks like this, sort of...
Easier to illustrate the problem with a picture
Thanks in advance!
Hello,
I would add ambient to shadow before multiplying with the material...
[edit :]
I mean change :
shadowShade.g=shadowShade.b=shadowShade.r;
shadowShade.a=1.0;
with :
shadowShade = vec4(ambient_light.r + shadowShade.r,
ambient_light.g + shadowShade.r,
ambient_light.b + shadowShade.r,
1.0);
and do the rest the same way
I would add ambient to shadow before multiplying with the material...
[edit :]
I mean change :
shadowShade.g=shadowShade.b=shadowShade.r;
shadowShade.a=1.0;
with :
shadowShade = vec4(ambient_light.r + shadowShade.r,
ambient_light.g + shadowShade.r,
ambient_light.b + shadowShade.r,
1.0);
and do the rest the same way
Thanks, but the result is about the same. The shadow gets a little bit lighter but it is still darker than the ambient component.
Ambient lighting should not be effected by shadows, and therefore should not be modulated by the shadow value (and specular should be). What you have right now is
color = shadowValue*(ambient + diffuse) + specular
when what you want iscolor = ambient + shadowValue*(diffuse + specular)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement