View Full Version : Reflection cubemap doesn't fully cover the object

06-17-2014, 03:18 PM
I try to render a reflection map and then use it to create reflections on the surface of a ball. The problem is that I can't force opengl to create 6 textures, that cover the cubemap correctly. That is why you can see thick black stripes between the parts of the cubemap:

Screenshot (https://www.dropbox.com/s/hs9ykgryiu1bh6x/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2 02014-06-18%2001.20.56.png)

I tried to change my main camera with one of the 6 cameras, which are used to render the reflection map - to have a look on what these cams actually render. And everything seems ok.
I also tried to attach my skybox cubemap (which is definitely correct) instead of the reflection cubemap - the ball looks ok:

Screenshot (https://www.dropbox.com/s/p4121i54i345k9a/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2 02014-06-18%2001.51.53.png)

So the problem seems to be somehow connected with the dimensions of the reflection cubemap texture. Here's some code, that I use:

/// Here's how I initialize the cubemap and cameras (sorry for some hard coding :) )

for (unsigned int i = 0; i < 6; ++i)
/// Parameters for the i-th camera
/// CameraCreationParameters (float iFov, float iNearClipPlane, float iFarClipPlane, int iScreenWidth, int iScreenHeight)
auto params = CameraCreationParametersUPtr
(new Scene::CameraCreationParameters (90.f, 0.5f, 100.f, 1, 1));
/// Rotation parameters
params->SetForwardAxis (axii[i][0]);
params->SetSideAxis (axii[i][1]);
/// Camera creation
Scene::Camera::Create (params, _cameras[i]);
_cameras[i]->Move (objectCenter);

/// Allocate data for the i-th texture
glTexImage2D (Model::CubeTexture::IntToTextureType (i), 0, GL_RGB,
1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

/// Here's how I render the cubemap

/// FBO and it's depth RBO are created in another place
glBindFramebuffer (GL_FRAMEBUFFER, _fbo);
glBindRenderbuffer (GL_RENDERBUFFER, _rbo);

glReadBuffer (GL_NONE);

GLenum status = glCheckFramebufferStatus (GL_FRAMEBUFFER);
std::cout << "FrameBuffer error, status: 0x" << status << std::endl;
return BadFrameBuffer;

/// Render 6 sides of the cubemap
for (unsigned int i = 0; i < 6; ++i)

glFramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Model::CubeTexture::IntToTextureType (i), _texture->GetTexId (), 0);

/// Drawing routines

/// Switch to the default fbo
glBindFramebuffer (GL_FRAMEBUFFER, 0);

/// And finally, here's how I attach the cubemap to my shader:

glActiveTexture (GL_TEXTURE4);
glBindTexture (GL_TEXTURE_CUBE_MAP, _texture->GetTexId ());
GLuint gReflectionMapUniform;
if (!shader->GetUniformLocation ("gReflectionMap", gReflectionMapUniform))
return UniformVariableBadName;
glUniform1i (gReflectionMapUniform, 4);

The only things, which seem to have any effect on the reflection are the dimensions of the 2D-parts of the cubemap. Here's what happens, when I set the width and height of the textures to 2024 and 2024:
Screenshot (https://www.dropbox.com/s/rmi4jgggpvmop73/%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2 02014-06-18%2002.23.52.png)

06-18-2014, 12:10 AM
Currently I'm trying to solve the problem on my own and have a question:

is the following call valid?

glFramebufferTexture2D (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Model::CubeTexture::IntToTextureType (i), _texture->GetTexId (), 0);

Here I attach one of the 6 cubemap parts (GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, ...) to the color attachment point of my framebuffer. Is it really valid to use these parts separately? Or should I use some renderbuffer for the color attachment and then copy it's result to the cubemap part?

06-18-2014, 12:10 PM
...No, simply rendering to a 2D-texture and copying it to one of the 6 parts of the reflection cubemap doesn't change anything. Well, except for the low framerate ).

06-18-2014, 03:48 PM
Suddenly, I ran into the answer:

glViewport (0, 0, 1024, 1024);

/// Rendering the reflection map

glViewport (0, 0, 1024, 768);

So, the viewport influences the rendering routine in general. I hope, that it would help other beginners with the same problem.