Jump to content
  • Advertisement
Sign in to follow this  
el capitan

GLSL shadow mapping problem

This topic is 4885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems while trying to project the shadow map onto the terrain. Although I can render the depth buffer from the lights point of view as illustrated in the lower left corner of the screenshot I can't project it onto the terrain for some reason. As you can see there are some black artifacts present. I have no idea what they are or where they come from as they seem to be completely random. I have followed two shady "tutorials" http://www.deor.org/~gulgi/shadowmappingdoc.html http://www.ampoff.org/modules.php?name=Forums&file=viewtopic&t=15 But both of them expect something that I'm missing and due to their failure to provide source code I can't find out. Anyway, Let me illustrate the problem code: In the rendering loop the following is done:
render begin
  shadows begin
    //renders lights point of view
    render trees
    render terrain
  shadows calculate
    render lit trees
    render lit terrain
  shadows end
    render shadows on trees
    render shadows on terrain
render end

everything works well until the shadows end, the part which the next code deals with
void
shadows_end()
{
	static mat4 bias = { 0.5f, 0.0f, 0.0f, 0.0f,
			0.0f, 0.5f, 0.0f, 0.0f,
			0.0f, 0.0f, 0.5f, 0.0f,
			0.5f, 0.5f, 0.5f, 1.0f}; 


	set_texture(&ter_shader, "shadow_map", 2);
	/*
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	
	const GLdouble x[] = {1.0, 0.0, 0.0, 0.0};
	const GLdouble y[] = {0.0, 1.0, 0.0, 0.0};
	const GLdouble z[] = {0.0, 0.0, 1.0, 0.0};
	const GLdouble w[] = {0.0, 0.0, 0.0, 1.0};
	
	glTexGendv(GL_S, GL_EYE_PLANE, x );
	glTexGendv(GL_T, GL_EYE_PLANE, y );
	glTexGendv(GL_R, GL_EYE_PLANE, z );
	glTexGendv(GL_Q, GL_EYE_PLANE, w );
	*/
	glMatrixMode(GL_TEXTURE);
	glLoadMatrixf(bias);
	glMultMatrixf(light_proj_matrix);
	glMultMatrixf(light_matrix);
	glMatrixMode(GL_MODELVIEW);
	
	//Bind & enable shadow map texture

	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
	
	//render using shadow vp and fp
	set_uniform1i(&ter_shader, "state", SHADOW_PASS);


}

Another thing is that after using shadows if I don't set GL_TEXTURE_COMPARE_MODE_ARB to GL_NONE then the shadow texture will be either loaded as empty or render as empty. This doesn't worry me too much, except for the fact that I'm afraid it isn't working. Here are the SHADOW_PASS GLSL programs VP
        proj_shadow = gl_TextureMatrix[0] * gl_Vertex;
        gl_Position = ftransform();

fp
        vec4 color = vec4(1.0);
	// Do the Z comparison:
	color *= shadow2DProj(shadow_map, proj_shadow).r;
	// Output final color:
	gl_FragColor = color;

So does anyone have working glsl shadow maps? I'd really appreciate some pointers.

Share this post


Link to post
Share on other sites
Advertisement
In the shader by replacing proj_shadow with gl_Position i managed to project the texture onto the screen. Now I need to figure out what is wrong. I think one problem might be my texture matrix, which I will look next.

Share this post


Link to post
Share on other sites
I don't know but I have seen the same sort of artifacts I think. WHen you move the camera do those weird black shapes follow/move around by any chance?

Share this post


Link to post
Share on other sites
The black shapes do follow, but I discovered the problem.

I think one could call these crude unrefined shadows:


My problem was that I kept stubbornly calling texturematrix[0] whereas i should have been calling texturematrix[2] according to the units. I didn't realize that bind texture binds the texture matrix the the according number. Anyhow. I still need to do some stuff to get these ready for some prime time 8)

Share this post


Link to post
Share on other sites
I've read about doing blurs on shadow maps to get soft edges. Anyone have any idea how to do this right?

I can't figure out a way to do blur in the shader and I really don't want to copy the depthbuffer off the card, do blur on it and then load it back to the gpu.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!