Ambient shadows in glsl

Started by
4 comments, last by Kalidor 17 years, 7 months ago
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...

// 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;



Easier to illustrate the problem with a picture Thanks in advance!
_____________________________
www.OddGames.comwww.OddGames.com/daniel
Advertisement
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
_____My little engine : I.E.
Thanks, but the result is about the same. The shadow gets a little bit lighter but it is still darker than the ambient component.
_____________________________
www.OddGames.comwww.OddGames.com/daniel
Would something like "final color = max (color, ambient)" work?
Ah thanks, that sounds like it could work. I'll try it out when I get home from work. :))
_____________________________
www.OddGames.comwww.OddGames.com/daniel
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 is
color = ambient + shadowValue*(diffuse + specular)

This topic is closed to new replies.

Advertisement