shadow mapping problem

dunno if this is an advanced question… sopelase move it if its not…

im havin trouble projection my shadowmap onto my geoemtry…

right now all i want to do is to make it visible… (no real shadow calculations)

sooo first ive rendered the scene depth to a FBO… this is ok ive rendred the FBO and it looks as it should…

but when i try to project the FBO onto the geoemtry it gets all black… what am i doing wrong?

glActiveTexture(GL_TEXTURE3);
DepthFBO.Begin();

gluLookAt( 500,500,500, // Look from the light's position
           0.0f, -0.0f, 0.0f,   
           0.0f, 1.0f, 0.0f ); 

glGetFloatv(GL_MODELVIEW_MATRIX, lightproj_matrix);	
glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glTranslatef( 0.5f, 0.5f, 0.5f );                      // Offset
glScalef( 0.5f, 0.5f, 0.5f );                          // Bias
gluPerspective( 45.0, (GLdouble)1024 / 786, 0.1, 5000.0 );
glMultMatrixf( lightproj_matrix ); 
glMatrixMode( GL_MODELVIEW );

Terrain->DepthShader->use();
Terrain->Render();
Terrain->DepthShader->disable;
DepthFBO.End();


glActiveTexture(GL_TEXTURE2);
MainFBO.Begin();
m_Cam->Update();

Terrain->Shader->use();
Terrain->Shader->sendUniform("ShadowMap", 3);	

Terrain->Shader->sendUniform("lightprojmatrix", lightproj_matrix, false,4);

	Terrain->Render();

Terrain->Shader->disable;

MainFBO.End();

and the shader code…

//VERTEX SHADER
gl_Position = gl_ModelViewProjectionMatrix * vec4(WorldPos, 1.0);

lightProj = lightprojmatrix * vec4(WorldPos, 1.0);
     //lightProj= gl_TextureMatrix[0]* vec4(WorldPos, 1.0); // TRIED BOTH VARIATIONS

  // if i project using the current models matrix i get greyscale colours.. even if its wrong.. but atleast its not black which is the case with the previous 2...

//lightProj = gl_ModelViewProjectionMatrix * vec4(WorldPos, 1.0);
}

// FRAGMENT

void main()
{
vec2 pos = lightProj.xy/lightProj.w;
vec4 shadmap = texture2D(ShadowMap, gl_TexCoord[0].st);

gl_FragColor = shadmap;

}

the only thing i can think of as incorrect is the retreived lightprojectamtrix…

What’s the internal format of texture.
What’s the type of ShadowMap in fragment shader?
Why do you do this:

glActiveTexture(GL_TEXTURE3);
DepthFBO.Begin();

I don’t see where do you bind texture to unit #3, but you use that unit in shader (uniform “ShadowMap” is set to 3).

I got the feeling that you didn’t fully understand how FBO/shaders/multitexturing works…

there is a great tutorial here for shadow maps…

he doesn’t use FBOs per se, but same sort of stuff…
http://www.paulsprojects.net/tutorials/smt/smt.html

ut.

the FBOs and depthmap works just fine… the FBO is binded to the currect texture in Begin() what doesnt seem to work is the textureprojection of the depthmap onto the geoemtry…

i tried another code… but same results… this time i just want to get the texturecoordiantes as colors onto the terrain… i get some colors but its wrong

   	glActiveTexture(GL_TEXTURE3);
	DepthFBO.Begin();

		gluPerspective(45.0f, (GLfloat)1024/(GLfloat)768, 1.0f, 1000.0f);
		gluLookAt( 500,200,500, // Look from the light's position
				0.0f, -0.0f, 0.0f,   
				0.0f, 1.0f, 0.0f ); 
		m_Cam->Frustum.setCamDef(vec3(500,200,500), vec3(0.0,0.0,0.0), vec3(0.0,1.0,0.0));

		Terrain->DepthShader->use();
		Terrain->Render();
		Terrain->DepthShader->disable;

	DepthFBO.End();

	glActiveTexture(GL_TEXTURE2);
	MainFBO.Begin();
		m_Cam->Update();

		glMatrixMode(GL_TEXTURE);
		{
			glLoadIdentity();
			glTranslatef(0.5f, 0.5f, 0.5f);
			glScalef(0.5f, 0.5f, 0.5f);
			gluPerspective(45.0f, (GLfloat)1024/(GLfloat)768, 1.0f, 1000.0f);
			gluLookAt( 500,200,500, 
				0.0f, -0.0f, 0.0f,  
				0.0f, 1.0f, 0.0f );
		}
		glMatrixMode(GL_MODELVIEW);
		

		Terrain->Shader->use();
		Terrain->Shader->sendUniform("TextureMap", 1);
		Terrain->Shader->sendUniform("ShadowMap", 3);

			if (WireFrame)
				glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
			else
				glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

			Terrain->Render();

		Terrain->Shader->disable;

	MainFBO.End();
// VERTEX

lightProj = gl_TextureMatrix[0] * vec4(WorldPos, 1.0);

//FRAGMENT 

	vec3 pos = (lightProj.xyz/lightProj.w);

	gl_FragColor = pos.xyzz;

		}

http://img95.imageshack.us/img95/5038/shadowcoordgk3.jpg

EDIT::

actually it seems i get the same results even if i dont multiply by hte texturematrix in the vertex shader…??

Originally posted by UT666:
[b] there is a great tutorial here for shadow maps…

he doesn’t use FBOs per se, but same sort of stuff…
http://www.paulsprojects.net/tutorials/smt/smt.html

ut. [/b]
that tutorial is all good… but it doesnt use shaders…