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 2 of 2

Thread: ping-pong between two FBO's small error

  1. #1
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251

    Question ping-pong between two FBO's small error

    hey, i was working on painting the terrain heightmap lately. so i used 2 fbo's, drawing a fullscreen quad with heightmap texture and a quad with a brush texture in front of it while painting. mechanically it works fine, but if i use resulting texture from any of fbo's directly to draw terrain, i notice constant shivering in certain spots. so i nailed it down to fbo's content:

    heightBuffer[0] and heightBuffer[1] contents:
    Click image for larger version. 

Name:	Nowhere-0_Editor-Context1-Texture19level0.jpg 
Views:	75 
Size:	2.9 KB 
ID:	1023 Click image for larger version. 

Name:	Nowhere-0_Editor-Context1-Texture20level0.jpg 
Views:	84 
Size:	2.9 KB 
ID:	1024
    looks the same, right? but they're not.

    here's the multiplied difference:
    Click image for larger version. 

Name:	difference.jpg 
Views:	88 
Size:	2.4 KB 
ID:	1025

    so there's constant error at those spots. but i can't see the reason. at first i thought it was due to low precision(unsigned byte), so i switched framebuffer attachment type to float and changed all corresponding code, but it didn't change anything. maybe someone else here will notice mistake, here's some code(sorry for fixed pipeline, this project was before i switched to OGL 3+):

    ping-pong between fbo's drawing fullscreen quad and brush:
    Code :
    void updateHeightMap() {
        fboManager.bind(heightEditBufferIDs[Counter % 2]);
        glPushMatrix();
     
        glViewport(0, 0, 1024, 1024);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0f, 1024.0f, 0.0f, 1024.0f, 0.1f, 10.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
     
        glDepthMask(0);
        SShader[3].applyProgram(10);
     
        glPushMatrix();
        glTranslatef(512.0f, 512.0f, -1.0f);
        glScalef(512.0f, 512.0f, 1.0f);
     
      //heightmap
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, fboManager[heightEditBufferIDs[Counter % 2 == 0]].rtList[0].textureObject);
        glUniform1i(SShader[shaderId].shaderSet[programId].uniform_colorMap, 0);
     
        glBindVertexArray(quadVertexArrayObjectId);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0);
        glPopMatrix();
     
      //brush
        if(terrainEditorMode && lmDown) {
            //irrelevant, currently drawing\not drawing onto heightmap doesn't affect problem
        }
     
        glBindVertexArray(0);
     
        glPopMatrix();
        glDepthMask(1);
        fboManager.unbind();
    }

    fragment shader used to draw fullscreen quad:
    Code :
    #version 120
    uniform sampler2D colorMap;
    void main(void)
    {
        vec4 Color = texture2D(colorMap, gl_TexCoord[0].st);
        gl_FragColor = Color;
    }

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    fixed. reason was wrong define in vertex shader, so it used some code intended for skinned meshes. weirdly enough, it only slightly affected color.

Posting Permissions

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