• Advertisement
Sign in to follow this  

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

This topic is 1775 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];

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





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


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

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

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


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


	glBindFramebuffer(GL_FRAMEBUFFER, 0);




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

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