Some questions about shadow maping

Hello !

I have started implementing shadow mapping a few days ago. I have managed to implement it.

I use a fake shadow mapping with the same result as the original one: I render with a color in the second pass and with another color in the third pass.

The problem is I have artifacts at the edge of the self shadows. I have looked at Paul Baker’s tutorial and he also has artifacts when drawing with different colors per pass (but they are not visible when true lighting is done)

I have an idea how to get rid of those artifacts, but it requires a vertex program.

Here is my vertex program (in cg) which is not meant to solve the artifact problem, but merely to make shadow mapping work with a vertex shader:

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

};

OUT_Struct main(float4 position : POSITION,
float4 color:COLOR,
uniform float4x4 modelViewProj,
float4 texCoord:TEXCOORD0,
uniform float dark
)
{

OUT_Struct OUT;

// Transform position from object space to clip space

OUT.position = mul(modelViewProj, position);

if (dark > 0.5) //dark is set to 1 when
//I do the dim light pass
//I shift all the geometry to
// reproduce the effect of glPolygonOffset
{

 OUT.position.z = OUT.position.z + 0.01;

}

OUT.color = color;//float4(0.8, 0.0, 0.0, 1.0);

OUT.texCoord = texCoord;

return OUT;

}

When I enable that vertex program the
geometry is rendered as it is without it, but the shadows are gone.

I think the problem is related to the depth texture, but I don’t know how.

Could you give me a clue how to implement shadow mapping with vertex shaders ?

I also have another problem: how can shadow mapping be applied to textured objects (since the depth texture is bound) … ?

Thank you

would you post the FP program?
I’ve implemented ShadowMap with Cg,the demo can be download at http://von_kypck.nease.net/download/ActionDesignor.rar.
but sorry for the comment in shader files not in English, maybe it can help you:-)

Thank you.

I have managed to write a functional shader. I am at the begining with cg programming so it may be ugly …

Here is the code:

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;

float4 eye_space_pos = mul(glstate.matrix.modelview[0], position );

//this is 1 when rendered from the light’s
//point of view. It should shrink the object
//so that there are no self shadowing
//artifacts. This is an experiment of mine…

if (light > 0.5)
{
position -= 0.02 * float4(normal,0);
}

// Transform position from object space to clip space

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

OUT.color = color;

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

}

//this is when rendered with the dim light
//is is supposed to replace the polygon offset
//I use when rendering the dim light.
//However, the polygon offset seems to be
//functional, even if I do not do something
//“in that direction” in the vertex program
//That’s strange…

if (dark > 0.8)
{

 OUT.position.z = OUT.position.z + 0.001;

}

return OUT;

}

You could help me by telling me a way to filter the shadows to make them feel less blocky and how to remove the artifacts when self shadowing…

Thank you

if your model is close, the better way to avoid artifacts is to render the model with glCullFace(GL_FRONT).

he lorenzot !
your download site link is dead !
could you please give a new one, so I could have a look at you job with cg.

thanks you

just remove the final “.” from the url, and then the link is valid. come on now =P