Sign in to follow this  

Shadowmapping & Graphical Errors

Recommended Posts

i've now implemented shadow mapping into my project and i'm not that impressed by it. this has several reasons: 1. to self shadow the terrain, i must check wether the pixel is the front of the mesh or the back ( from pos of the light ) this results in that crappy effect, that a triangle is shadowed or not ( and the in between state looks much more ****** ) you can see it here. it's in wireframe mode, because you can clearly see that type of "bug" 2. i've encountered some other graphical errors as well, it can't describe it well, so just look here or a here on the screens you can also see the Shadowmap, wich has been drawed to a quad. this is the shader code ( perhaps there are some errors (?)
// these are the shadow values, set in the project
Effect->SetFloat("ShadowOffset", 0.015f);
Effect->SetFloat("AmbientShadowValue", 0.1f);
Effect->SetFloat("ShadowIntensity", 0.4f);

// vertexshader
VS_OUTPUT VS(float4 Pos: POSITION, float3 Normal: NORMAL, float2 Tex0 : TEXCOORD0)
	N = mul(Normal, matRotation);
	tempFloat = saturate(dot(N, (float3)vecLightDir));
      Out.Pos	 = mul(Pos, matWorldViewProjection);
	Out.Tex0 = Tex0; 
	// Shadow stuff
	LightViewPortCoordinates = mul(Pos, matWorldLightViewProjection);
	Out.ShadowTex.x = 0.5f*LightViewPortCoordinates.x + 0.5f;
	Out.ShadowTex.y = 0.5f  - 0.5f*LightViewPortCoordinates.y;
	Out.LightSpacePixelDepth.x = tempFloat;
	Out.LightSpacePixelDepth.y = LightViewPortCoordinates.z - ShadowOffset;

	return Out;

// sampler
sampler LightDepthMapSampler = sampler_state
	texture = (LightDepthMapTexture);

// Pixelshader
float4 PS(float2 Tex0 : TEXCOORD0, float2 ShadowTex : TEXCOORD1, float2 LightSpacePixelDepth : TEXCOORD2) : COLOR 
    tempFloat = step(0.0f, tex2D(LightDepthMapSampler, ShadowTex).z - LightSpacePixelDepth.y);

    tempFloat *= ShadowIntensity*LightSpacePixelDepth.x;
    tempFloat += AmbientShadowValue;

    return tempFloat*tex2D(SkinSampler, Tex0);

i'm now playing with the shadow values, perhaps i find a setting wich eliminates or dimmers the graphic errors. but if you have any more tipps, i would be very gratefull if you share them with me :)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this