shadow mapping coordiantes

Started by
0 comments, last by Dragon_Strike 17 years ago
im having some trouble projecting my shadowmap onto geoemtry... so far i would kjust like to render the texture coordinates for the shadowmap onto the terrain... but i get all black values...

	glActiveTexture(GL_TEXTURE3);
	DepthFBO.Begin();

		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));

		float lightproj_matrix[16];
		float lightmodel_matrix[16];

		glGetFloatv(GL_MODELVIEW_MATRIX, lightmodel_matrix);	
		glGetFloatv(GL_PROJECTION_MATRIX, lightproj_matrix);	

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

	DepthFBO.End();

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

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

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

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

			Terrain->Render();

		Terrain->Shader->disable;

	MainFBO.End();


//"Shader"

//VERTEX

varying vec4 lightProj;

uniform mat4 lightprojmatrix;
uniform mat4 lightmodelviewmatrix;

void main()
{
        /* removed code */

	gl_Position =  gl_ModelViewProjectionMatrix * vec4(WorldPos, 1.0);
	
	lightProj = lightprojmatrix * lightmodelviewmatrix * vec4(WorldPos, 1.0);
	
}

// FRAGMENT

#version 110

uniform sampler2D TextureMap;
uniform sampler2D ShadowMap;

varying vec4 lightProj;

void main()
{	
	vec3 pos = (lightProj.xyz/lightProj.w)*0.5+0.5;
	
	gl_FragColor = vec4(pos,1.0);
}



i suspect im doin something wrong with the lights matrices.. but i dont know what... if i use the current modelprojection matrix it looks just fine... only when i try to use the lights it gets black..
Advertisement
i tried another code.. still doesnt work correctly.. 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...??

This topic is closed to new replies.

Advertisement