Exemple #1
0
void SMAA::doEdgePass( const ci::gl::FboRef& source )
{
	int w = mFboEdgePass->getWidth();
	int h = mFboEdgePass->getHeight();

	// Enable frame buffer
	gl::ScopedFramebuffer fbo( mFboEdgePass );
	gl::ScopedTextureBind tex0( source->getColorTexture(), 0 );
	gl::ScopedGlslProg shader( mSMAAFirstPass );
	mSMAAFirstPass->uniform( "uColorTex", 0 );
	mSMAAFirstPass->uniform( "SMAA_RT_METRICS", vec4( 1.0f / w, 1.0f / h, (float)w, (float)h ) );
	{
		gl::clear();
		gl::clearStencil( 0 );

		gl::ScopedColor color( Color::white() );
		gl::ScopedBlend blend( false );

		gl::enableStencilTest();

		gl::stencilFunc( GL_ALWAYS, 1, 0xFF ); // replace, ref = 1
		gl::stencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
		gl::stencilMask( 0xFF );

		gl::drawSolidRect( mFboEdgePass->getBounds() );

		gl::disableStencilTest();
	}
}
ci::gl::Texture2dRef CameraProgram::getColorTexture(ci::gl::FboRef base, ci::gl::FboRef extra)
{
	gl::ScopedFramebuffer fbo(base);
	gl::draw(mCaptureTex, Area(ivec2(0), *matrixWindow()), app::getWindowBounds());
	ProgramRef e = getEffect();
	if (e) {
		return e->getColorTexture(base, extra);
	}

	return base->getColorTexture();
}
Exemple #3
0
void SMAA::apply( const ci::gl::FboRef& destination, const ci::gl::FboRef& source )
{
	// Source and destination should have the same size
	assert( destination->getWidth() == source->getWidth() );
	assert( destination->getHeight() == source->getHeight() );

	// Create or resize frame buffers
	int w = source->getWidth();
	int h = source->getHeight();

	gl::Texture2d::Format fmt;
	fmt.setMinFilter( GL_LINEAR );
	fmt.setMagFilter( GL_LINEAR );
	fmt.setWrap( GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER );

	if( !mFboEdgePass || mFboEdgePass->getWidth() != w || mFboEdgePass->getHeight() != h ) {
		// Note: using only RG channels decreases performance on NVIDIA, 
		//       while RGBA does not decrease performance on Intel and AMD
		//fmt.setInternalFormat( GL_RG );
		//fmt.setSwizzleMask( GL_RED, GL_GREEN, GL_ZERO, GL_ONE );
		mFboEdgePass = gl::Fbo::create( w, h, gl::Fbo::Format().colorTexture( fmt ).disableDepth().stencilBuffer() );
	}

	if( !mFboBlendPass || mFboBlendPass->getWidth() != w || mFboBlendPass->getHeight() != h ) {
		fmt.setInternalFormat( GL_RGBA );
		fmt.setSwizzleMask( GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA );
		mFboBlendPass = gl::Fbo::create( w, h, gl::Fbo::Format().colorTexture( fmt ).disableDepth() );
	}

	// Apply first two passes
	doEdgePass( source );
	doBlendPass();

	// Apply SMAA
	gl::ScopedFramebuffer fbo( destination );
	gl::ScopedTextureBind tex0( source->getColorTexture(), 0 );
	gl::ScopedTextureBind tex1( mFboBlendPass->getColorTexture(), 1 );
	gl::ScopedGlslProg shader( mSMAAThirdPass );
	mSMAAThirdPass->uniform( "uColorTex", 0 );
	mSMAAThirdPass->uniform( "uBlendTex", 1 );
	mSMAAThirdPass->uniform( "SMAA_RT_METRICS", vec4( 1.0f / w, 1.0f / h, (float)w, (float)h ) );
	{
		gl::clear();
		gl::ScopedColor color( Color::white() );
		gl::ScopedBlend blend( false );

		gl::drawSolidRect( destination->getBounds() );
	}
}
ci::gl::Texture2dRef ImageProgram::getColorTexture(ci::gl::FboRef base, ci::gl::FboRef extra)
{
	if(mImage) {
		gl::ScopedFramebuffer fbo(base);
		gl::clear(Color(mClearShade, mClearShade, mClearShade));

		gl::pushViewport();
		gl::pushMatrices();
		gl::setMatricesWindow(app::getWindow()->getSize());
		vec2 offset = (vec2)(app::getWindowSize() - mImage->getSize()) * 0.5f;
		auto dst = mImage->getBounds();
		dst.offset(offset);
		gl::draw(mImage, dst);
		gl::popMatrices();
		gl::popViewport();
	}

	auto e = getEffect();
	if(e) {
		return e->getColorTexture(base, extra);
	}

	return base->getColorTexture();
}