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:
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:
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);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
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)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
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