Hey Embers,
@paul.houx has made a series of really cool samples - one of which I’m kind of dissecting and playing around with a bit. Specifically the Depth of Field example shown here:
Now then - I’m trying to have this render into a texture via an FBO. I’ve got plenty of stuff rendering into FBO’s without a problem, but for some reason when I attach the FBO to this code, it doesn’t work as intended. When I try and render the FBO color texture, all I get is black.
In @paul.houx 's code, the final compositing render looks as follows:
if( true ) {
gl::ScopedColor scpColor( 1, 1, 1 );
gl::ScopedBlend scpBlend( false );
gl::ScopedTextureBind scpTex0( mFboSource->getColorTexture(), 0 );
gl::ScopedTextureBind scpTex1( mFboBlur[1]->getTexture2d( GL_COLOR_ATTACHMENT0 ), 1 );
gl::ScopedTextureBind scpTex2( mFboBlur[1]->getTexture2d( GL_COLOR_ATTACHMENT1 ), 2 );
gl::ScopedGlslProg scpGlsl( mGlslComposite );
mGlslComposite->uniform( "uInputSourceInvSize", 1.0f / vec2( mFboSource->getSize() ) );
mGlslComposite->uniform( "uFarRadiusRescale", mFarRadiusRescale );
mGlslComposite->uniform( "uDebugOption", mDebugOption );
gl::drawSolidRect( getWindowBounds() );
}
My modified code looks as follows:
// Perform compositing.
if (true) {
// -- Injection Start
BreakUnless( mFbo );
ci::gl::ScopedFramebuffer scpFbo( mFbo );
ci::gl::ScopedViewport scpViewport( { 1280, 800 } /* mFbo->getSize()*/ );
ci::gl::ScopedMatrices scpMatrices;
ci::gl::setMatricesWindow( { 1280, 800 } /* mFbo->getSize()*/ );
// -- Injection End
ci::gl::ScopedColor scpColor( 1, 1, 1 );
ci::gl::ScopedBlend scpBlend( false );
ci::gl::ScopedTextureBind scpTex0( mFboSource->getColorTexture(), 0 );
ci::gl::ScopedTextureBind scpTex1( mFboBlur[1]->getTexture2d( GL_COLOR_ATTACHMENT0 ), 1 );
ci::gl::ScopedTextureBind scpTex2( mFboBlur[1]->getTexture2d( GL_COLOR_ATTACHMENT1 ), 2 );
ci::gl::ScopedGlslProg scpGlsl( mGlslComposite );
mGlslComposite->uniform( "uInputSourceInvSize", 1.0f / ci::vec2( mFboSource->getSize() ) );
mGlslComposite->uniform( "uFarRadiusRescale", mFarRadiusRescale );
mGlslComposite->uniform( "uDebugOption", mDebugOption );
//ci::gl::drawSolidRect( getWindowBounds() );
ci::gl::drawSolidRect( ci::Rectf( 0, 0, 1280, 800 ) );
}
As you may have guessed, the idea is to have the composition render into the mFbo and then use mFbo->getColorTexture()
to eventually display the result. However, all I seem to end up with is black when I do it this way…
If anything pops out as being completely off, I’d be keen to know. Right now I’m just scratching my head as to why attaching the FBO in advance of the final composite render doesn’t work O_o
Thanks in advance,
Gazoo