PDA

View Full Version : Shadow map artifacts. Need help



flamz
02-04-2004, 03:12 PM
I'm getting some really nasty artifacts, caused most probaly by z-fighthing, with my shadow map implementation.

Here's a screen shot that shows the problem.
http://www.ndgclan.net/journal/luc.html

Basically, I am rendering the shadow map in a p-buffer then using glCopyTexSubImage2D to copy the DEPTH_COMPONENT to a texture. I am then binding this texture and texture matrix and blending it on top of the diffuse pass.

It looks like z-fighiting to me, but I tried to use a glPolygonOffset to try to tweak it and tried different pixel formats for the pbuffer and I am unable to get better results.

Also, when I play with the projection matrix (near/far plane) when rendering the shadow map, this affects the look of the artifacts but I still can't figure out how to get a smooth shadow on the edges of curved surfaces like the one showed in the screen shot.

Any tips would be greatly appreciated.

cheers,
Flamz

JustHanging
02-05-2004, 01:45 AM
Hi,

A fast fix would be drawing backfaces to the shadow map and still applying some polygon offset on them, but...

The way you accumulate you lighting is wrong. It seems like you draw the scene once with all the lights on and then draw all the shadows on top of it. But that doesn't give you the correct result, obviously in the area that's shadowed from the other light there should still be light from the other one.

What you should do is draw one light at the time, shadowed by it's shadow map, and add them all together using blending or multitexturing. If you want ambient light, you'll have to add that too in a seperate pass. You should have no ambient light enabled when drawing the shadowed lights, then there'll be no light on the edges of the shadow (because the surface isn't facing the light) and the artifacts won't be visible.

-Ilkka

fuxiulian
02-05-2004, 01:56 AM
My solution to this problem was to shrink the object a little using a vertex program. It is not however a general solution, as it doesn't work well with objects that have sharp angles.

Here is my shader in CG:




struct OUT_Struct
{
float4 position : POSITION;
float4 color : COLOR;
float4 texCoord:TEXCOORD0;

};

OUT_Struct main(float4 position : POSITION,
float4 color:COLOR,
float3 normal:NORMAL,


uniform float light,
uniform float dark,
uniform float4 eye,
uniform float generateTex
)
{

OUT_Struct OUT;

// Transform position from object space to clip space
float4 eye_space_pos = mul(glstate.matrix.modelview[0], position );

if (light > 0.5)//I set light to 1 when
//rendering from the light's point of view
{
position -= 0.05 * float4(normal,0);
}

OUT.position = mul(glstate.matrix.mvp, position);

OUT.color = color;

if (generateTex > 0.5)
//this is for automatic texture generation
{
OUT.texCoord.x = dot(glstate.texgen[0].eye.s,eye_space_pos);
OUT.texCoord.y = dot(glstate.texgen[0].eye.t,eye_space_pos);
OUT.texCoord.z = dot(glstate.texgen[0].eye.r,eye_space_pos);
OUT.texCoord.w = dot(glstate.texgen[0].eye.q,eye_space_pos);

}

return OUT;

}


I realize that my shader may be an example of badly written code, but I'm a beginner in CG so be gentle.

I got rid of these artifacts when using this shader.

Chris Lux
02-10-2004, 02:08 AM
i dont think that there is an error. these artifacts appear. BUT in the picture is something wrong. you use 2 light sources, so in the area which is shadowed by source 1 can be light from source 2, wich doesnt happen at your picture. you schadow everything black, where shadow is regardless if there can be light. so these artifacts appear amplified, because the edges are so very nitocable.

another hint is to disable ambient lighting or use the ambient color für the shadowed areas.

these artifacts appear and cant be avoided, only if done right they wont attract attention. if you imagine where the shadow must start, at this location will the artifacts appear, because the shadowed region begins there, you must adapt you lighting to your shadowing and consider where the shadows have influence and where in shadowed regions can be lighted objects from other lightsources (multipass rendering).

HTH

Alessandro_dup1
02-10-2004, 05:03 AM
Yes, it seems an incorrect lighting.

dorbie
02-10-2004, 01:07 PM
Your problem is the lighting. You need to modulate the direct illumination result by their respective shadow test with separate tests for each light. This way the light will tend to blend towards blackness or towards ambient (ambient is not modulated by shadow) towards the shadow regions making this much less of an issue. If it's still a problem you could use Cass Everett's silhouette poly split to make sure you have vertices closer to the silhouette that will produce better silhouette fading before the shadow hull is entered.

Start with a single light and get that working with the lighting contribution tending to zero at teh edge of the shadow, (I don't think you have that working yet). Then you can do pultiple lights as multiple passes.

[This message has been edited by dorbie (edited 02-10-2004).]