Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Adding fbo mesh objects together in a shader

$
0
0

@Sam_McElhinney_io wrote:

Hello OF

I'm wondering if anyone could give me a tip or two on how to successfully add together two fbo objects in a shader. Specifically, I'm hoping to create a mesh object, load it into an fbo and then, using a ping-pong between that and another fbo, incrementally add to a set of pixel stored values (i.e. as the mesh changes over time)

I think I'm more or less correct with the cpu side, which looks as follows:

    //toggle pingpong boolean
    isA = !isA;
    //generate an ofPath object
    pass.clear();
    for(int i = 0; i <3; i++){
        ofVec2f p (ofRandom(0,width), ofRandom(0,height));
        pass.lineTo(p);
    }
    pass.close();

    // turn ofpath to mesh
    ofMesh passMesh;
    passMesh = pass.getTessellation();

    //send fbo data to shaders
    if(isA) fboPass(fboA, fboB, passMesh);
    else    fboPass(fboB, fboA, passMesh);

Where the fboPass function is:

    fboX.begin();
    //Wipe live fbo clean
    ofClear(0, 0, 0, 0);
    shader.begin();
    //pass stored fbo to the shader
    shader.setUniformTexture("dataIn", fboY.getTextureReference(), 1 );
   //pass new mesh to the shader
   passMesh.draw();
   shader.end();
   fboX.end();

But I'm struggling to figure out the shader. I'd assumed it could just happen in the frag shader as per the below, but this does not seem to combine the respective fbo datas. Can anyone point me in the right direction?

// get mesh data recently pushed to tex0
vec4 srce = texture(tex0, texCoordVarying).rgba;

// get stored data from previous fbo
vec4 data = texture(dataIn, texCoordVarying).rgba;

srce.x += data.x;
srce.y += data.y;
srce.z += data.z;
srce.w += data.w;

//return the combined output
outputColor = vec4(srce);

S

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles