Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Reflection cubemap doesn't fully cover the object

  1. #1
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12

    Question Reflection cubemap doesn't fully cover the object

    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

    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

    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 :) )
    Code :
    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
    Code :
    /// 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:
    Code :
    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
    Last edited by Blizzard_jedi; 06-17-2014 at 03:27 PM.

  2. #2
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    Currently I'm trying to solve the problem on my own and have a question:

    is the following call valid?
    Code :
        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?

  3. #3
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    ...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 ).

  4. #4
    Junior Member Newbie
    Join Date
    May 2014
    Posts
    12
    Suddenly, I ran into the answer:

    Code :
        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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •