PDA

View Full Version : ping-pong between two FBO's small error



Nowhere-01
05-10-2013, 01:12 PM
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:
1023 1024
looks the same, right? but they're not.

here's the multiplied difference:
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:

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:

#version 120
uniform sampler2D colorMap;
void main(void)
{
vec4 Color = texture2D(colorMap, gl_TexCoord[0].st);
gl_FragColor = Color;
}

Nowhere-01
05-10-2013, 02:04 PM
fixed. reason was wrong define in vertex shader, so it used some code intended for skinned meshes. weirdly enough, it only slightly affected color.