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