I have not been able to advance at all regarding this. I will just post what is absolutely necessary and hopefully someone can help guide me as to what I am doing wrong.
Again, my intention is to obtain a 2D image from sampling a depth cubemap (a cubemap containing the depth information for the scene around the camera location) .
My result is just a blank image made up of 0s. I do not know why I am not getting any output FYI, depth_cube_tex
is the depth cubemap.
My sampling procedure is as follows,
# SAMPLING CUBEMAP
##################
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS)
angle_step = 0.025
hangle = np.array([0, 360, angle_step], dtype=np.float32)
vangle = np.array([-90, 90, angle_step], dtype=np.float32)
width = int( (hangle[1]-hangle[0]) / hangle[2])
height = int( (vangle[1]-vangle[0]) / hangle[2])
# create scene buffer
scene_buffer = glGenFramebuffers(1)
glBindFramebuffer(GL_FRAMEBUFFER, scene_buffer)
# generate color depth buffer
color_depth = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, color_depth)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_depth, 0)
# send information to sampling shader
cubemap_sampling_shader.use()
cubemap_sampling_shader.set_uniform_int('depth_cube', depth_cube_tex)
cubemap_sampling_shader.set_uniform_vec3('display_size', glm.vec2(width,height))
cubemap_sampling_shader.set_uniform_float('angle_step', angle_step)
#draw to my scene buffer
glBindVertexArray(quad_vao)
glBindTexture(GL_TEXTURE_2D, color_depth)
glDrawArrays(GL_TRIANGLES, 0, 6)
glBindVertexArray(0)
# save output ?
zbuffer = glReadPixelsf(0, 0, width, height, GL_RED, GL_FLOAT)
zbuffer = zbuffer.reshape((height, width))
np.save('Scene', np.flipud(zbuffer))
glBindFramebuffer(GL_FRAMEBUFFER, 0) #scene_buffer
The 'cubemap_sampling` shader program has the following vertex shader,
#version 330 core
layout (location = 0) in vec2 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0f, 1.0f);
}
Given that I am not rendering any new geometry, I am uncertain about what to use for a vertex fragment. The vertex shader I am including here is thought with regards to a simple quad (see below). fragment shader is the following,
#version 330 core
uniform samplerCube depth_cube;
uniform float angle_step;
uniform vec2 display_size; // width, height of display
out float depth;
void main()
{
// phi the horizontal deviation angle
float phi= (gl_FragCoord.x - display_size.x / 2 ) * radians(angle_step);
// theta is the vertical deviation angle
float theta = (gl_FragCoord.y - display_size.y / 2 ) * radians(angle_step);
// create sampling direction vector
float x = sin(theta) * cos(phi);
float z = sin(theta) * sin(phi);
float y = cos(theta);
depth = texture(depth_cube,vec3(x,y,z)).r;
}
And my quad_vao
is just two triangles spaning the entire screen in Normalize Device Coords.