Skip to main content
GameDev.net gamedev.net
🔒 Locked

depth cubemap texture array setup

Started by Yours3!f Aug 16, 2014 at 3:58 PM 2 replies 3.7k views
Original Post
Yours3!f
Yours3!f

hi there,

is this the correct way to set up depth cubemap texture arrays? My problem is that nothing is rendered to the textures...

EDIT: I seem to have been able to render 1 face correctly, I still suspect the setup code.

I get no errors or debug output messages.
I suspect that I should somehow enable each face as usual with the cubemaps, but I couldn't find a way to do that...


  GLuint point_shadow_texture;
  glGenTextures(1, &point_shadow_texture);
  glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, point_shadow_texture);

  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  glTexParameteri( GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  glTexImage3D( GL_TEXTURE_CUBE_MAP_ARRAY, 0, GL_DEPTH_COMPONENT32, shadow_texture_size.x, shadow_texture_size.y, lights.size() * 6, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );

  vector<GLuint> point_shadow_fbos;
  point_shadow_fbos.resize( lights.size() );
  glGenFramebuffers( lights.size(), &point_shadow_fbos[0] );

  for( int c = 0; c < lights.size(); ++c )
  {
    glBindFramebuffer( GL_FRAMEBUFFER, point_shadow_fbos[c] );
    glDrawBuffer( GL_NONE );
    glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, c );
    frm.check_fbo_status();
  }

  glBindFramebuffer( GL_FRAMEBUFFER, 0 );

usually I set up non-texture-array depth cubemaps like this:


  GLuint cubemap_tex;
  glGenTextures( 1, &cubemap_tex );
  glBindTexture( GL_TEXTURE_CUBE_MAP, cubemap_tex );

  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

  uvec2 texsize( 1024 );

  for( int c = 0; c < 6; ++c )
    glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + c, 0, GL_DEPTH_COMPONENT24, texsize.x, texsize.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0 );

  GLuint cubemap_fbo;
  glGenFramebuffers( 1, &cubemap_fbo );
  glBindFramebuffer( GL_FRAMEBUFFER, cubemap_fbo );

  //attach depth cubemap to fbo's depth attachment
  glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, cubemap_tex, 0 );

  //no color textures attached
  glDrawBuffer( GL_NONE );

  frm.check_fbo_status();

  //unbind
  glBindFramebuffer( GL_FRAMEBUFFER, 0 );

Best regards,

Yours3!f

Yours3&#33;f
Yours3&#33;f

so it seems like if you change the layer to 0..6 then each face of the cubemap DOES render correctly, but not all of them at once.

like this:


glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, 0 );
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, 1 );
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, 2 );
...
glFramebufferTextureLayer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0, 6 );

here's the vertex shader I'm using:


#version 430 core

uniform mat4 light_model_mat;

layout(location=0) in vec4 in_vertex;

void main()
{
  gl_Position = light_model_mat * in_vertex;
}

the geometry shader:


#version 430 core

//get me a triangle
layout(triangles) in; 
//3 vertices per triangle, 6 triangles overall
layout(triangle_strip, max_vertices=18) out;

//per face view projection matrices
uniform mat4 cube_viewproj[6];

void main()
{
  //redirect to 6 cubemap faces
  for(gl_Layer = 0; gl_Layer < 6; ++gl_Layer)
  {
    for(int c = 0; c < 3; ++c) //send the triangle through
    {
      gl_Position = cube_viewproj[gl_Layer] * gl_in[c].gl_Position;
      EmitVertex();
    }
    
    EndPrimitive();
  }
}

and the pixel shader:


#version 430 core

out vec4 color;

void main()
{
  color = vec4(1);
}

Yours3&#33;f
Yours3&#33;f

seems like if I just bind the texture as a non-layered texture, then it does get rendered correctly... But then I can't use the other layers... Is this a driver bug? Anyone?


glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, point_shadow_texture, 0 );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.