Jump to content
  • Advertisement
Sign in to follow this  
pressgreen

Need help with Z buffer, depth texture, shadow mapping understanding

This topic is 1871 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 am interested in creating a cube shadow map from the perspective of a point light for my project. but there are some things that i am not fully understanding in the shadow mapping technique in general. I am using opengl 3.0 and glsl  #version 130.

 

From what I have read i think shadow maps are generated using the depth values from the depth buffer. the depth buffer in examples are usually gathered in a writing of the scene to a depth_attachment of a frame buffer object from the perspective of the light source. then one can pass that depth buffer information to the frag shader to inform what pixels in the final rendering need to be altered with the shadow map info. 

 

I guess the part i am failing to understand is how this depth component is actually to be captured and passed to the fragment shader. I have been able to mind the scene to a complete frame buffer just fine and render that frame buffer object to a full screen quad but i fail to figure out how to just use the depth component of a frame buffer object. and storing that as a separate piece of information. I found a working example of a cube mapping technique and in the initialization portion of the code there is a function that sets up a frame buffer and a shadow map depth texture but looking at it Im not quite sure of what is going on in on particular area. that i have commented below.

 

So in the end I would just like if any one who is up to it, Help with an explanation/example on the set up and use of just a depth texture or depth component of a frame buffer for shadow mapping and or help understanding this commented portion of setting up the initialization of a shadow map

 

// calculate light matrices -----------------------------------------------------------------------------------------------

	LightView[0] = ViewMatrix(vec3( 0.0f, 0.0f, 1.0f), vec3(0.0f, 1.0f, 0.0f), vec3(-1.0f, 0.0f, 0.0f), Objects[LightObjectID].Position);
	LightView[1] = ViewMatrix(vec3( 0.0f, 0.0f,-1.0f), vec3(0.0f, 1.0f, 0.0f), vec3( 1.0f, 0.0f, 0.0f), Objects[LightObjectID].Position);
	LightView[2] = ViewMatrix(vec3( 1.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 1.0f), vec3( 0.0f,-1.0f, 0.0f), Objects[LightObjectID].Position);
	LightView[3] = ViewMatrix(vec3( 1.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f,-1.0f), vec3( 0.0f, 1.0f, 0.0f), Objects[LightObjectID].Position);
	LightView[4] = ViewMatrix(vec3(-1.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f), vec3( 0.0f, 0.0f,-1.0f), Objects[LightObjectID].Position);
	LightView[5] = ViewMatrix(vec3( 1.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f), vec3( 0.0f, 0.0f, 1.0f), Objects[LightObjectID].Position);

	LightTexture[0] = BiasMatrix() * LightProjection * LightView[0];
	LightTexture[1] = BiasMatrix() * LightProjection * LightView[1];
	LightTexture[2] = BiasMatrix() * LightProjection * LightView[2];
	LightTexture[3] = BiasMatrix() * LightProjection * LightView[3];
	LightTexture[4] = BiasMatrix() * LightProjection * LightView[4];
	LightTexture[5] = BiasMatrix() * LightProjection * LightView[5];

	glUseProgram(ShadowCubeMapping);
	glUniformMatrix4fv(ShadowCubeMapping.UniformLocations[2], 6, GL_FALSE, (GLfloat*)LightTexture);
	glUseProgram(0);
	
	// render shadow cube map -------------------------------------------------------------------------------------------------

	glViewport(0, 0, SHADOW_CUBE_MAP_SIZE, SHADOW_CUBE_MAP_SIZE);

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(&LightProjection);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glCullFace(GL_FRONT);

	///------------------------------------------------setting up to bind info to frame buffer
	glBindFramebuffer(GL_FRAMEBUFFER, FBO);

	glEnableClientState(GL_VERTEX_ARRAY);

	for(int i = 0; i < 6; i++)
	{
		glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, ShadowCubeMap, 0, i);

		glClear(GL_DEPTH_BUFFER_BIT);
////////////////////////////////////////////////////////////////// this is the part in question 
//////////////////////////////////////////////////////////////////What is happening in this for loop?
		for(int ii = 0; ii < ObjectsCount; ii++)
		{
			if(Objects[ii].TrianglesCount <= 0) continue;

			glMatrixMode(GL_MODELVIEW);
			glLoadMatrixf(&LightView);
			glTranslatef(Objects[ii].Position.x, Objects[ii].Position.y, Objects[ii].Position.z);

			glBindBuffer(GL_ARRAY_BUFFER, Objects[ii].VBO[2]);
			glVertexPointer(3, GL_FLOAT, 0, NULL);

			glFrontFace(Objects[ii].FrontFace);

			glDrawArrays(GL_TRIANGLES, 0, Objects[ii].TrianglesCount * 3);
		}
/////////////////////////////////////////////////////////////////////////////////////////////////
	}
	
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glDisableClientState(GL_VERTEX_ARRAY);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glCullFace(GL_BACK);

	glDisable(GL_CULL_FACE);
	glDisable(GL_DEPTH_TEST);

 

I do apologize if I am not asking this question properly or just sound stupid.

Share this post


Link to post
Share on other sites
Advertisement

You migh have better luck if you post this in the "open gl" forum, or the "graphics programming and theory" forum.
This is beyond the beginner level  :P

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!