Sign in to follow this  
MARS_999

Shadowmap Help

Recommended Posts

I am trying to do some shadowmapping and so far am not successful in getting it to work. I start with a black texture and it shows up white? My first question is do I need to be use these functions at all?
glGetFloatv();
glLoadMatrix();

I am under the assumption from reading that all I need to do is setup the texture to accept the depth buffer(Z Buffer) values and render the scene from the light's position and then re-render the scene from the eye position? So I am confused and also I am not doing anything with the texture matrix? Do I need to? I dont' see why I would have to? Thanks for any help.

Share this post


Link to post
Share on other sites
thanks phantom, but All I want to do is take the values from the depth buffer and put them into a texture and look at them as a seperate texture. Am I going to have to get all the matrixes and do texture coordinate generation ect... or is there some simple way to just grab the values use the arb_shadow extension and get the shadow results in a texture?

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
just copy the depth buffer to a texture and display it like a normal texture mapped to a quad


I have a question still, apparently my glCopyTexSubImage isn't working cause my texture is all white? This maybe be a stupid question but do I need to enable texturing first to use the glCopyTexSubImage or glTexSubImage functions?

Here is my code in my update function


{
glPolygonOffset(2, 2);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//I just threw in some camera values to make up where my light might be
gluLookAt(128, 50, 128, 0, 0, 0, 0, 1, 0);

//Use viewport the same size as the shadow map
glViewport(0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

glEnable(GL_POLYGON_OFFSET_FILL);

if(vbo_enabled)
DrawTerrainVBO();
else
DrawTerrainVertexArray();

// Copy the Z buffer to the shadow map:
glBindTexture(GL_TEXTURE_2D, shadowmapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameterf(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glDisable(GL_POLYGON_OFFSET_FILL);
}


Share this post


Link to post
Share on other sites
Quote:
Original post by skow
Do you create a texture in 'shadowmapTexture' to copy over? You can't just pass it an unsigned int, without first TexGening.

Thanks for the reply but yes I have a array 512x512 setup for the texture. Not sure but do I need to flush my polygons I draw with glFlush()? and then rerender the actual scene? I am only rendering the polygons with the first pass no lighting, no textures, no color ect...

Share this post


Link to post
Share on other sites
I fixed it. Been a long time since I looked at my texture code, but I am using gluBuild2DMipmaps and forgot to take out the GL_LINEAR_MIPMAP_LINEAR parameter to the glTexParam function. Still not getting anywhere with my shadowmap getting read from the depth buffer? This should be so simple, I should just have to do these steps...
1. setup texture
2. clear buffers
3. move camera to lightposition
4. render geometry
5. call glCopyTexSubImage2D to move depth buffer values into a shadow map texture?
6. clear buffers again
7. set camera to eye position
8. render again with texture, lighting ect...


Now if I am missing anything please feel free to help.... I am not using no texture coordinate generation I just want to get a greyscle image of the depth buffer so I can apply that image over my mesh with my fragment program....

Hope this clears up any confusion on what I am trying to do.

Share this post


Link to post
Share on other sites
Well I got my code done, but am not seeing anything different, all white on my texture. I am using a fragment program to do my texturing and lighting. I just want to make a shadowmap and place it into a texture and then use that texture in my fragment program. Here is my code, hoepfully someone can point out my mistakes. Thanks


void SetupShadowMap(void)
{
glGenTextures(1, &shadowmapTexture);
glBindTexture(GL_TEXTURE_2D, shadowmapTexture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, SHADOWMAP_SIZE, SHADOWMAP_SIZE, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
}

void GenerateShadowMap(void)
{
GLint viewport[4];
GLfloat lightPos[4];

glGetLightfv( GL_LIGHT0, GL_POSITION, lightPos );
glGetIntegerv( GL_VIEWPORT, viewport );

glViewport( 0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE );

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluPerspective( 75.0, 1.0, .025, 1000.0);
glMatrixMode( GL_MODELVIEW );

glPushMatrix();
glLoadIdentity();

gluLookAt(lightPosition[0], lightPosition[1], lightPosition[2], look_x, look_y, look_z, 0.0, 1.0, 0.0);

if(vbo_enabled)
DrawTerrainVBO(true);
else
DrawTerrainVertexArray(true);

glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );

glCullFace(GL_FRONT);

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, shadowmapTexture);

glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, SHADOWMAP_SIZE, SHADOWMAP_SIZE, 0 );

glViewport( viewport[0], viewport[1], viewport[2], viewport[3] );

glCullFace(GL_BACK);
}

void GenerateShadowMapTextureMatrix(void)
{
GLfloat tmpMatrix[16];

glPushMatrix();
glLoadIdentity();
glTranslatef( 0.5, 0.5, 0.0 );
glScalef( 0.5, 0.5, 1.0 );
gluPerspective( 75.0, 1.0, .025, 1000.0);
gluLookAt(lightPosition[0], lightPosition[1], lightPosition[2], look_x, look_y, look_z, 0.0, 1.0, 0.0);

glGetFloatv( GL_MODELVIEW_MATRIX, tmpMatrix );
glPopMatrix();

SwapMatrix(tmpMatrix);

glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glEnable( GL_TEXTURE_GEN_Q );

glTexGenfv( GL_S, GL_OBJECT_PLANE, &tmpMatrix[0]);
glTexGenfv( GL_T, GL_OBJECT_PLANE, &tmpMatrix[4]);
glTexGenfv( GL_R, GL_OBJECT_PLANE, &tmpMatrix[8]);
glTexGenfv( GL_Q, GL_OBJECT_PLANE, &tmpMatrix[12]);

glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
}

void DrawShadowMap(void)
{
GenerateShadowMap();
GenerateShadowMapTextureMatrix();
}




I call DrawShadowMap() for the first pass and call DrawTerrainVBO(true); again for the second pass.

Thanks for any help

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