Flickering Terrain shadows

MisterMayhem

04-11-2009 16:46:29

I've been spinning my wheels on this one for awhile now. I appreciate the help I've received in other threads, but it's not enough to get me through this issue.

Surely everyone who uses ETM notices the shadow flicker, and either has fixed it, or wants to fix it. I'm one of those who wants to fix it. I suspect you need to use a custom shader for the shadow generation, but I can't figure out how to do that. I read the Ogre documentation and tried things that seem to suggest what I'm trying to do, but my attempts just don't work. It would be nice if there is a solution that is quite similar for all our applications.

I'd appreciate some help in documenting the solution in this thread.

MisterMayhem

01-02-2010 20:42:34

Finally got this working after hours and hours, and many attempts.

I created the following vertex program in VSLodMorph2.cg:
void terrain_shadow_vp(
float4 position : POSITION,
float delta : BLENDWEIGHT,

out float4 oPosition : POSITION,
out float2 oUv1 : TEXCOORD0,
out float4 color : COLOR,
uniform float4x4 worldViewProj,
uniform float4x4 shadowViewProj,
uniform float morphFactor
)
{
position.y = position.y + (delta.x * morphFactor);
oPosition = mul(worldViewProj, position);
oUv1 = mul(shadowViewProj, position).xy;
color = float4(1, 1, 1, 1);
}


With the following program declaration:
vertex_program ET/Programs/VSLodMorphShadow2 cg
{
source VSLodMorph2.cg
entry_point terrain_shadow_vp
profiles vs_1_1 arbvp1

default_params
{
param_named_auto morphFactor custom 77
param_named_auto worldViewProj worldviewproj_matrix
param_named_auto shadowViewProj texture_viewproj_matrix
}
}


And the following in the first pass of the material:
shadow_receiver_vertex_program_ref ET/Programs/VSLodMorphShadow2
{
}


Finally the flickering and depth issues with the shadows are history!