[SOLVED] Custom shader and Multiple Render Targets

Hi everybody!

I want to create a custom Fbo with MRT (for depth and textures), but I can’t get the textures right…
These are the settings for the FBO:

ofFbo::Settings settings;
    settings.width = ofNextPow2(ofGetWidth());
    settings.height = ofNextPow2(ofGetHeight());
    settings.internalformat = GL_RGB32F;
    settings.numSamples = 4;
    settings.useDepth = false;
    settings.useStencil = false;
    settings.depthStencilAsTexture = false;
    settings.textureTarget = GL_TEXTURE_2D_BINDING_EXT;
    settings.depthStencilInternalFormat = GL_DEPTH_COMPONENT24;
    settings.minFilter = GL_NEAREST;
    settings.maxFilter = GL_NEAREST;
    settings.wrapModeHorizontal = GL_CLAMP_TO_BORDER;
    settings.wrapModeVertical = GL_CLAMP_TO_BORDER;
    settings.numColorbuffers = 2; // <--- COLOR BUFFERS

And, on the fragment shader (I’m using #version 410, so no gl_FragData[]), I did:

layout (location = 0) out vec4 outputColor1;
layout (location = 1) out vec4 outputColor2;

But, when doing fbo.getTexture(1).draw(0,0), I get:

Instead of the most beautiful rotating red cube, of course. : ) Any ideas? Thanks!

Any luck figuring this out? I think I’m stuck at just about the same place you are/were…

Would you mind posting your entire frag shader?

Hi there!

I completely forgot to update this… I couldn’t make it all with ofFbo::Settings, so ended up combining that FBO object with createAndAttachTexture.

As an example, I would use these settings:

ofFbo::Settings settings;
settings.width = ofNextPow2(ofGetWidth());
settings.height = ofNextPow2(ofGetHeight());
settings.internalformat = GL_RGB32F;
settings.numSamples = 0;
settings.useDepth = true;
settings.useStencil = true;
settings.depthStencilAsTexture = true;
settings.textureTarget = GL_TEXTURE_2D;
settings.depthStencilInternalFormat    = GL_DEPTH_COMPONENT24;
settings.minFilter = GL_NEAREST;
settings.maxFilter = GL_NEAREST;
settings.wrapModeHorizontal = GL_CLAMP_TO_BORDER;
settings.wrapModeVertical = GL_CLAMP_TO_BORDER;

Then, I would allocate them to the FBO and add two textures:

fbo.allocate(settings);

fbo.createAndAttachTexture(GL_RGBA32F, 1);
fbo.createAndAttachTexture(GL_RGBA32F, 2);

When you draw your scene, don’t forget to do activateAllDrawBuffers() after you begin your FBO.
The fragment shader stays the same.

2 Likes

Awesome, thanks!

What is the best way to load initial data into separate draw buffers? (ie, from an array of floats)

I’m not sure of what is your objective.

(Correct me if I’m wrong) but drawBuffers are destination only. That is, they are the output to which the fragment shader data will be written.

NICE !!! thank you so much.
<3