Fbo render artifacts compared with the default display buffer

I tried with many allocate parameters as GL_RGBA, GL_RGBA32F, Multisamples at 8. but there’s no way I can get a clean drawing using an FBO. It shows some kind of noise artifact. But I’m forced to use FBOs because I need to use its method clearDepthBuffer() to achieve the visuals I want, and that method can’t be applied (as far as I know) to the default display buffer.

Drawing in the fbo:

drawing with no fbo:
image

void ofApp::draw()
{
    ofEnableAlphaBlending();
    fbo.begin();
    fbo.clearDepthBuffer(1.f);
    ofEnableDepthTest();
    ofEnableSmoothing();
    for (Particle p : particles)
    {
        p.draw();
    }
    ofSetColor(ofColor::black, 1);
    ofDrawRectangle(0, 0, w, h);
    ofEnableSmoothing();
    ofDisableDepthTest();
    fbo.end();

    ofSetColor(ofColor::white);
    fbo.draw(0, 0);

    ofDisableAlphaBlending();
}

Repo:

I changed the glSetup to use gl 3.2 and that noisy artifact is gone but…

void ofSetupOpenGL(int w, int h, ofWindowMode screenMode){
#ifdef TARGET_OPENGLES
	ofGLESWindowSettings settings;
	settings.glesVersion = 1;
#else
	ofGLWindowSettings settings;
	settings.glVersionMajor = 3;
	settings.glVersionMinor = 2; 
...

now the spheres are plane circles…
image

I’ve just run from your repo (after removing utils and videorecorder) and the results are like this:
maybe the artifacts are specific to your system / video card

Hi @dimitre. Thank you for your time.
Are you applying fbo.clearDepthBuffer(1.f)?
The problem is visible when making the trail effect with a black rectangle and clearing the depth buffer, but looking at the images you show this trail effect isn’t happening.
Maybe I commented that part of the code before the github commit

yes post here the trail effect and I can test again.

void ofApp::draw()
{
    ofEnableAlphaBlending();
    fbo.begin();
    fbo.clearDepthBuffer(1.f);
    ofEnableDepthTest();
    ofEnableSmoothing();
    for (Particle p : particles)
    {
        p.draw(trigger);
    }
    ofEnableSmoothing();
    ofDisableDepthTest();
//increase this alpha value to  make the trail effect more perceptible
    ofSetColor(ofColor::black, 1); 
    ofDrawRectangle(0, 0, w, h);
    fbo.end();
    ofSetColor(ofColor::white);
    fbo.draw(0, 0);
    ofDisableAlphaBlending();
}

this should do the job =/

with alpha = 3:
image

I don’t know why it’s not clearing the depth buffer correctly in your system =/.
those black trajectory lines are still visible when a sphere goes behind it. The clearDepthBuffer() should remove them.

Would it help to ofDisableAlphaBlending() after the above line of code? Maybe this is a case of the classic alpha blending vs. depth testing.

Yeah I’ve waited so the depth test appear and you can see.
One suggestion I have is disable smoothing, maybe instead you can use multisampling, because I think the summing of the fbo alpha in time gives some pixelated aspect.

Other thing: I’ve tried to use alpha channel with a value lower than 1, using ofFloatColor with alpha like 0.003 or something, but it feels like it is rounded to zero, so I don’t know if ofFloatColor internals is using 8 bits anyway.

1 Like

I tried. It’s the same with alphaBlending disabled

I tried to apply multisampling on the GL_RGBA32F fbo and it’s not rendering a thing. Also tried using an fbo with x4 size and then drawing it smaller and the artifact persists.

Perhaps try adding:

ofClearAlpha();

just before:

fbo.end();