Skip to main content
gamedev.net
🔒 Locked

Shadow map beginner [SOLVED]

Started by mobeen 3 replies 1.2k views
Original Post
mobeen
mobeen
Hi all, I am trying to do basic shadowmapping using FBO and Cg. I have assigned simple colors to my geometry to make things simple. My Scene Descroption: The scene contains a sphere placed on a plane of size 20x20 units from -10 - 10 in [X,Z]. My Problem: The shadow does not look nice. I dont know why i get the weird shadow on the sphere and the plane. See this image My Approach: For every object, i calculate the texture matrix as below T = Bias.Lproj.Lview.Omodel; where, T -> Texture Matrix Lproj -> Light projection matrix Lview -> Light view matrix Omodel -> Object's model matrix This was given here. And then pass this matrix to the vertex shader where the projected texture coordinates are calculated as given below.

struct V_In{
   float4 position: POSITION;
   half4 Color    : COLOR0;
};

struct V_Out{
   half4 Position : POSITION;	//clip space position
   half4 Color    : COLOR0; 
   half4 texCoordProj : TEXCOORD0;
};

struct F_Out{
   half4 Color:COLOR;			//per fragment color
};

V_Out vertex_main(V_In I, uniform float4x4 textureMatrix){
  V_Out O;	     
  O.Position = mul(glstate.matrix.mvp, I.position); 
  O.texCoordProj = mul(textureMatrix , I.position);  
  O.Color =  I.Color; 
  return O;
}

F_Out fragment_main( V_Out In, uniform sampler2D shadowMap){
  F_Out f;  
  float4 shadowColor = tex2Dproj(shadowMap , In.texCoordProj);
  f.Color = In.Color*shadowColor;
  return f;
}



One more thing when i move my light at or below the plane level, the shadows become like this Can anyone tell me what is it that i m doing wrong? Thanks, Mobeen [Edited by - mobeen on March 4, 2009 4:09:59 AM]
Proud to be a PAKISTANI.
cherryyosh
cherryyosh
The top image looks like your getting self shadowing, try culling the back face.

The bottom is shadow acne, you need to set a bias when getting the shadows 'glPolygonOffset( 1.0, 4096.0 ); glEnable( GL_POLYGON_OFFSET_FILL )' and/or increase the shadow's precision. I found out that GL_RGBA with GL_FLOAT by default only uses 8bit precision. Raising this to even 16F (GL_RGBA16F_ARB) GREATLY improved the quality..
mobeen
mobeen
Quote:
The top image looks like your getting self shadowing, try culling the back face.

I am already culling the front faces during the shadow rendering pass as shown below
AttachFBO();   glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT );		   glMatrixMode(GL_PROJECTION);		    glLoadMatrixf(lightProjectionMatrix);   glMatrixMode(GL_MODELVIEW);   glLoadMatrixf(lightViewMatrix);				   glViewport(0, 0, width, height);   glCullFace(GL_FRONT);   DrawScene();DetachFBO();	


Quote:

The bottom is shadow acne, you need to set a bias when getting the shadows 'glPolygonOffset( 1.0, 4096.0 ); glEnable( GL_POLYGON_OFFSET_FILL )' and/or increase the shadow's precision. I found out that GL_RGBA with GL_FLOAT by default only uses 8bit precision. Raising this to even 16F (GL_RGBA16F_ARB) GREATLY improved the quality..

Thanks that removed the artifact.

I m still getting the self shadowing on the plane and the sphere. Anything else?
Proud to be a PAKISTANI.
cherryyosh
cherryyosh
Quote:
Original post by mobeen
Quote:
The top image looks like your getting self shadowing, try culling the back face.

I am already culling the front faces during the shadow rendering pass as shown below
*** Source Snippet Removed ***

Quote:

The bottom is shadow acne, you need to set a bias when getting the shadows 'glPolygonOffset( 1.0, 4096.0 ); glEnable( GL_POLYGON_OFFSET_FILL )' and/or increase the shadow's precision. I found out that GL_RGBA with GL_FLOAT by default only uses 8bit precision. Raising this to even 16F (GL_RGBA16F_ARB) GREATLY improved the quality..

Thanks that removed the artifact.

I m still getting the self shadowing on the plane and the sphere. Anything else?


Sorry, never had that visible of self shadowing so I cannot help there =/
mobeen
mobeen
Hi all,
Actually the problem was with setting up of the texture parameter for the depthmap texture. I had it initially set to
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

changing this to
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

removed the artifact.
Here is the final snapshot

Thanks again to all those who helped.
Take care,
Mobeen
Proud to be a PAKISTANI.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.