void MotionBlurVelocityBufferApp::dilateVelocity()
{
    gl::ScopedFramebuffer fbo( mVelocityDilationBuffer );
    gl::ScopedViewport viewport( ivec2( 0, 0 ), mVelocityDilationBuffer->getSize() );
    gl::ScopedMatrices	matrices;
    gl::setMatricesWindowPersp( mVelocityDilationBuffer->getSize() );

    {   // downsample velocity into tilemax
        gl::ScopedTextureBind tex( mGBuffer->getTexture2d( G_VELOCITY ), 0 );
        gl::ScopedGlslProg prog( mTileProg );
        gl::drawBuffer( DILATE_TILE_MAX );

        mTileProg->uniform( "uVelocityMap", 0 );
        mTileProg->uniform( "uTileSize", mTileSize );

        gl::drawSolidRect( mVelocityDilationBuffer->getBounds() );
    }
    {   // build max neighbors from tilemax
        gl::ScopedTextureBind tex( mVelocityDilationBuffer->getTexture2d( DILATE_TILE_MAX ), 0 );
        gl::ScopedGlslProg prog( mNeighborProg );
        gl::drawBuffer( DILATE_NEIGHBOR_MAX );

        mNeighborProg->uniform( "uTileMap", 0 );

        gl::drawSolidRect( mVelocityDilationBuffer->getBounds() );
    }
}
Esempio n. 2
0
void NormalGetterApp::normalize(gl::TextureRef _tex){
    {
        gl::ScopedMatrices push;
        gl::ScopedFramebuffer fbo(mOutputFbo);
        gl::clear();
        ci::gl::setMatricesWindow( mOutputFbo->getSize() );
        ci::gl::ScopedViewport view( ci::vec2(0), mOutputFbo->getSize() );
        gl::ScopedGlslProg mGlsl(mNormalGlsl);
        gl::ScopedTextureBind tex0(_tex);
        mNormalGlsl->uniform("uSampler", 0);
        mNormalGlsl->uniform("u_textureSize", vec2(_tex->getWidth(), _tex->getHeight()));
        mNormalGlsl->uniform("bias", bias);
        mNormalGlsl->uniform("invertR", float(invertR ? -1.0 : 1.0) );
        mNormalGlsl->uniform("invertG", float(invertG ? -1.0 : 1.0));
        gl::drawSolidRect(Rectf(vec2(0), _tex->getSize()));
    }
    if( pushFramesToBuffer){
        mPreprocessedImages->pushFront(std::make_pair(mOutputFbo->getColorTexture()->createSource(), currentFrame));
        if(currentFrame == mMovie->getNumFrames()){
            pushFramesToBuffer = false;
            mMovie->setLoop(true);
            mMovie->seekToStart();
        }
        currentFrame++;
    }
}
Esempio n. 3
0
void ciApp::update()
{
	auto get_center_rect = [&](Area area) ->Rectf { return Rectf(area).getCenteredFit(getWindowBounds(), true); };

	
	spout_receiver->receive(mTexture);

	filter->update(mTexture);
	vector_blur.update(filter->getTexture());

	{
		const gl::ScopedColor scpColor(Color::white());
		const gl::ScopedFramebuffer scpFbo(mFbo);
		gl::clear();

		const gl::ScopedViewport scpView(ivec2(0), mFbo->getSize());
		const gl::ScopedMatrices scpMatrces;
		gl::setMatricesWindow(mFbo->getSize());

		auto tex = filter->getTexture();
		//auto tex = vector_blur.getTexture();
		gl::draw(tex);
	}

	spout_sender->send(mTexture);
#if 0
	// We copy the magnitude spectrum out from the Node on the main thread, once per update:
	mMagSpectrum = mMonitorSpectralNode->getMagSpectrum();
#endif
}
Esempio n. 4
0
void SMAA::apply( gl::FboRef destination, gl::FboRef source )
{
	gl::ScopedFramebuffer fbo( destination );
	gl::ScopedViewport viewport( 0, 0, destination->getWidth(), destination->getHeight() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( destination->getSize() );

	// Make sure our source is linearly interpolated.
	GLenum minFilter = source->getFormat().getColorTextureFormat().getMinFilter();
	GLenum magFilter = source->getFormat().getColorTextureFormat().getMagFilter();
	bool filterChanged = ( minFilter != GL_LINEAR || magFilter != GL_LINEAR );
	if( filterChanged ) {
		source->getColorTexture()->setMinFilter( GL_LINEAR );
		source->getColorTexture()->setMagFilter( GL_LINEAR );
	}

	// Perform SMAA anti-aliasing.
	gl::clear( ColorA( 0, 0, 0, 0 ) );
	draw( source->getColorTexture(), destination->getBounds() );

	// Restore texture parameters.
	if( filterChanged ) {
		source->getColorTexture()->setMinFilter( minFilter );
		source->getColorTexture()->setMagFilter( magFilter );
	}
}
Esempio n. 5
0
// Render the color cube into the FBO
void FboBasicApp::renderSceneToFbo()
{
    // this will restore the old framebuffer binding when we leave this function
    // on non-OpenGL ES platforms, you can just call mFbo->unbindFramebuffer() at the end of the function
    // but this will restore the "screen" FBO on OpenGL ES, and does the right thing on both platforms
    gl::ScopedFramebuffer fbScp( mFbo );
    // clear out the FBO with blue
    gl::clear( Color( 0.25, 0.5f, 1.0f ) );

    // setup the viewport to match the dimensions of the FBO
    gl::ScopedViewport scpVp( ivec2( 0 ), mFbo->getSize() );

    // setup our camera to render the torus scene
    CameraPersp cam( mFbo->getWidth(), mFbo->getHeight(), 60.0f );
    cam.setPerspective( 60, mFbo->getAspectRatio(), 1, 1000 );
    cam.lookAt( vec3( 2.8f, 1.8f, -2.8f ), vec3( 0 ));
    gl::setMatrices( cam );

    // set the modelview matrix to reflect our current rotation
    gl::setModelMatrix( mRotation );

    // render the color cube
    gl::ScopedGlslProg shaderScp( gl::getStockShader( gl::ShaderDef().color() ) );
    gl::color( Color( 1.0f, 0.5f, 0.25f ) );
    gl::drawColorCube( vec3( 0 ), vec3( 2.2f ) );
    gl::color( Color::white() );
}
Esempio n. 6
0
void FaceOff::updateClone()
{
    gl::ScopedMatrices mvp;
    gl::setMatricesWindow(mRenderedOfflineFaceFbo->getSize());
    gl::ScopedViewport viewport(0, 0, mRenderedOfflineFaceFbo->getWidth(), mRenderedOfflineFaceFbo->getHeight());

    // TODO: merge these two passes w/ MRTs
    {
        gl::ScopedFramebuffer fbo(mRenderedOfflineFaceFbo);
        gl::ScopedGlslProg glsl(gl::getStockShader(gl::ShaderDef().texture()));
        gl::ScopedTextureBind t0(mOfflineFaceTex, 0);
        gl::clear(ColorA::black(), false);
        gl::draw(mFaceMesh);
    }

    if (!MOVIE_MODE)
    {
        {
            gl::ScopedFramebuffer fbo(mFaceMaskFbo);
            gl::clear(ColorA::black(), false);
            gl::draw(mFaceMesh);
        }

        // TODO: add gl::ScopedMatrices in mClone.update()
        mClone.update(mRenderedOfflineFaceFbo->getColorTexture(), mCapture.texture, mFaceMaskFbo->getColorTexture());
        mHasNewRenderedFace = true;
    }
}
// Render our scene into the FBO (a cube)
void FboMultipleRenderTargetsApp::renderSceneToFbo()
{
	// setup our camera to render our scene
	CameraPersp cam( mFbo->getWidth(), mFbo->getHeight(), 60 );
	cam.setPerspective( 60, mFbo->getAspectRatio(), 1, 1000 );
	cam.lookAt( vec3( 2.8f, 1.8f, -2.8f ), vec3( 0 ) );

	// bind our framebuffer in a safe way:
	gl::ScopedFramebuffer fboScope( mFbo );

	// clear out both of the attachments of the FBO with black
	gl::clear();

	// setup the viewport to match the dimensions of the FBO, storing the previous state
	gl::ScopedViewport viewportScope( ivec2( 0 ), mFbo->getSize() );

	// store matrices before updating for CameraPersp
	gl::ScopedMatrices matScope;
	gl::setMatrices( cam );

	// set the modelview matrix to reflect our current rotation
	gl::multModelMatrix( mRotation );

	// render the torus with our multiple-output shader
	gl::ScopedGlslProg glslScope( mGlslMultipleOuts );
	gl::drawCube( vec3( 0 ), vec3( 2.2f ) );
}
Esempio n. 8
0
void NormalGetterApp::updateFbos(){
    if( mMovie && !makeMovie){
        if(!mFbo) mFbo = gl::Fbo::create(movieSize.x, movieSize.y);
        if( !mOutputFbo) mOutputFbo = gl::Fbo::create(movieSize.x, movieSize.y);
        
        if(mFbo){
            gl::ScopedMatrices push;
            gl::ScopedFramebuffer fbo(mFbo);
            ci::gl::clear(ci::Color(0,0,0));
            ci::gl::setMatricesWindow( mFbo->getSize() );
            ci::gl::ScopedViewport view( ci::vec2(0), mFbo->getSize() );
            gl::draw(mMovie->getTexture());
        }
        
    }

}
Esempio n. 9
0
void MotionBlurFboApp::draw()
{
	gl::viewport( vec2(), mAccumFbo->getSize() );

	if( ! mPaused ) {
		// make 'mAccumFbo' the active framebuffer
		gl::ScopedFramebuffer fbScp( mAccumFbo );
		// clear out both of our FBOs
		gl::clear( Color::black() );
		gl::color( 1, 1, 1, 1 );

		// iterate all the sub-frames
		double startTime = getElapsedSeconds();
		for( int i = 0; i < SUBFRAMES; ++i ) {
			// draw the Cube's sub-frame into mFbo
			gl::enableDepth();
			gl::enableAlphaBlending();
			mFbo->bindFramebuffer();
			gl::clear();
			gl::enableDepth();
			gl::setMatrices( mCam );
			updateCubeRotation( startTime + i / (float)SUBFRAMES );
			gl::multModelMatrix( mCubeRotation );
			mBatch->draw();
			
			// now add this frame to the accumulation FBO
			mAccumFbo->bindFramebuffer();
			gl::setMatricesWindow( mAccumFbo->getSize() );
			gl::enableAdditiveBlending();
			gl::enableDepth( false );
			gl::draw( mFbo->getColorTexture() );
		}
	}
	
	gl::disableDepthRead();
	gl::disableAlphaBlending();
	// set the color to be 1/SUBFRAMES, which divides the HDR image by the number of sub-frames we rendered
	gl::color( 1.0f / SUBFRAMES, 1.0f / SUBFRAMES, 1.0f / SUBFRAMES, 1 );
	gl::setMatricesWindow( getWindowSize() );
	gl::draw( mAccumFbo->getColorTexture() );
}
void GpuParrallelReductionApp::update()
{
	{
		gl::ScopedFramebuffer scopedFbo( mFbo );
		gl::ScopedViewport scopedViewport( vec2(0), mFbo->getSize() );
		gl::ScopedDepth scopedDepth( true );
		gl::ScopedBlend scopedBlend( false );
		gl::setMatrices( mCamera );
	
		gl::clear( ColorA::gray( 0.0f ) );
		gl::drawColorCube( vec3(0), vec3(1) );
		gl::drawCube( vec3(0,0,-0.5), vec3(0.1) );
	}
}
Esempio n. 11
0
void ShadowMappingBasic::renderDepthFbo()
{
	// Set polygon offset to battle shadow acne
	gl::enable( GL_POLYGON_OFFSET_FILL );
	glPolygonOffset( 2.0f, 2.0f );

	// Render scene to fbo from the view of the light
	gl::ScopedFramebuffer fbo( mFbo );
	gl::ScopedViewport viewport( vec2( 0.0f ), mFbo->getSize() );
	gl::clear( Color::black() );
	gl::color( Color::white() );
	gl::setMatrices( mLightCam );

	drawScene( true );
	
	// Disable polygon offset for final render
	gl::disable( GL_POLYGON_OFFSET_FILL );
}
Esempio n. 12
0
void FXAA::apply( const gl::FboRef &destination, const gl::FboRef &source )
{
	gl::ScopedFramebuffer fbo( destination );
	gl::ScopedViewport viewport( 0, 0, destination->getWidth(), destination->getHeight() );
	gl::ScopedMatrices matrices;
	gl::setMatricesWindow( destination->getSize(), false );

	// Make sure our source is linearly interpolated.
	GLenum minFilter = source->getFormat().getColorTextureFormat().getMinFilter();
	GLenum magFilter = source->getFormat().getColorTextureFormat().getMagFilter();
	source->getColorTexture()->setMinFilter( GL_LINEAR );
	source->getColorTexture()->setMagFilter( GL_LINEAR );

	// Perform FXAA anti-aliasing.
	gl::clear( ColorA( 0, 0, 0, 0 ) );
	draw( source->getColorTexture(), destination->getBounds() );

	// Restore texture parameters.
	source->getColorTexture()->setMinFilter( minFilter );
	source->getColorTexture()->setMagFilter( magFilter );
}
void TextParticlesApp::drawTextToFbo()
{
	{
		vec2 size = mTextFbo->getSize();
		gl::ScopedFramebuffer scpFbo( mTextFbo );
		gl::clear( ColorA( 0 , 0, 0, 0 ) );
		gl::ScopedViewport scpVp( ivec2(), size );
		gl::ScopedMatrices scpMtrx;
		gl::ScopedColor scpCol( 1, 1, 1);
		
		vec2 stringSize = mTextureFont->measureString( mString );
		float descent = mTextureFont->getDescent();
		float ascent = mTextureFont->getAscent();
		mTextSize = stringSize + vec2( 0, descent );
		
		// OPTIONALLY, draw the text metrics
		/*
		// string size - RED
		gl::color(1, 0, 0);
		gl::drawSolidRect( Rectf( -10, 0, stringSize.x + 10.0, stringSize.y ) );
		// ascent - CYAN
		gl::color(0, 1, 1);
		gl::drawSolidRect( Rectf( 0, stringSize.y - ascent, stringSize.x, ascent ) );
		// descent - YELLOW
		gl::color(1, 1, 0);
		gl::drawSolidRect( Rectf( 0, stringSize.y-descent, stringSize.x, stringSize.y ) );
		// above ascent
		gl::color( 0, 1, 0 );
		gl::drawSolidRect( Rectf( 0, 0, stringSize.x, stringSize.y-ascent ) );*/
		
		// DRAW string to FBO
		gl::color(1, 1, 1);
		mTextureFont->drawString( mString, vec2( 0, stringSize.y - descent ) );
	}
	
	// GET Texture from FBO
	mTextSurf = Surface( mTextFbo->readPixels8u( mTextFbo->getBounds() ) );
}
Esempio n. 14
0
void ciApp::update()
{
	// update params
	double current_time = ci::app::getElapsedSeconds();
	time_step = glm::clamp(current_time - elapsed_time, 1.0 / 120.0, 1.0 / 30.0);
	elapsed_time = current_time;
	int interval = 100000;
	double value = int(current_time * 1000) % interval / double(interval);
	time_value = sin(value * glm::two_pi<double>()) * 0.5 + 0.5; // continuous sin value

	// update fbo
	{
		const gl::ScopedFramebuffer scp_fbo(fbo);
		const gl::ScopedViewport scp_vp(ivec2(0), fbo->getSize());
		gl::clear();

		const gl::ScopedDepth scp_depth(true);
		const gl::ScopedMatrices scp_m;
		gl::setMatrices(camera);

		gl::drawColorCube(vec3(0), vec3(1, 2, 3));
	}
}
vec4 GpuParrallelReductionApp::findMindMax()
{
	// init the programs, fbo and texture used for the parrallel reduction
	static gl::FboRef sReductionFbo, sReadFbo;
	static gl::Texture2dRef sReductionTexture0;
	static gl::GlslProgRef sReductionProg, sCopyProg;
	auto startingSize		= mFbo->getSize() / 2;
	if( !sReductionFbo || sReductionFbo->getSize() != startingSize ) {
		sReductionTexture0	= gl::Texture2d::create( startingSize.x, startingSize.y, gl::Texture2d::Format().minFilter( GL_NEAREST_MIPMAP_NEAREST ).magFilter( GL_NEAREST ).mipmap().immutableStorage() );
		sReductionFbo		= gl::Fbo::create( startingSize.x, startingSize.y, gl::Fbo::Format()
											  .attachment( GL_COLOR_ATTACHMENT0, sReductionTexture0 )
											  .disableDepth() );
		sReductionProg		= gl::GlslProg::create( loadAsset( "minMax.vert" ), loadAsset( "minMax.frag" ) );
	}
	// start reduction profiling
	static auto sTimer0 = gl::QueryTimeSwapped::create();
	sTimer0->begin();
	
	// attach the main level of the texture
	gl::ScopedFramebuffer scopedFbo( sReductionFbo );
	glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sReductionTexture0->getId(), 0 );
	
	// start by blitting the main fbo into the reduction one
	mFbo->blitTo( sReductionFbo, mFbo->getBounds(), sReductionFbo->getBounds(), GL_NEAREST );
	
	
	// bind the reduction program and texture and disable blending
	gl::ScopedMatrices scopedMatrices;
	gl::ScopedGlslProg scopedGlsl( sReductionProg );
	gl::ScopedBlend scopedBlend( false );
	gl::ScopedTextureBind scopedTexBind0( sReductionTexture0, 0 );
	sReductionProg->uniform( "uTex0", 0 );
	
	// iterate trough each mipmap level
	int numMipMaps = gl::Texture2d::requiredMipLevels( startingSize.x, startingSize.y, 0 );
	for( int level = 1;	level < numMipMaps; ++level ) {
		// attach the current mipmap level to the framebuffer and limit texture sampling to the previous level
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level - 1 );
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level - 1 );
		glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sReductionTexture0->getId(), level );
		
		// get the current mipmap size and update uniforms
		vec2 size = gl::Texture2d::calcMipLevelSize( level, sReductionFbo->getWidth(), sReductionFbo->getHeight() );
		sReductionProg->uniform( "uInvSize", vec2( 1.0f ) / vec2( size ) );
		
		// render a fullscreen quad
		gl::ScopedViewport scopedViewport( ivec2( 0 ), size );
		gl::setMatricesWindow( size.x, size.y );
		gl::drawSolidRect( Rectf( vec2( 0.0f ), vec2( size ) ) );
	}
	// stop reduction profiling
	sTimer0->end();
	mReductionTime = sTimer0->getElapsedMilliseconds();
	
	// start readback profiling
	static auto sTimer1 = gl::QueryTimeSwapped::create();
	sTimer1->begin();
	
	// read back to the cpu and find the max value
	vec4 max( 0.0f );
	ivec2 readSize = gl::Texture2d::calcMipLevelSize( numMipMaps - 1, startingSize.x, startingSize.y );
	Surface8u surface( readSize.x, readSize.y, true );
	glGetTexImage( sReductionTexture0->getTarget(), numMipMaps - 1, GL_RGBA, GL_UNSIGNED_BYTE, surface.getData() );
	auto it = surface.getIter();
	while( it.line() ) { while( it.pixel() ) {
		max = glm::max( max, vec4( it.r(), it.g(), it.b(), it.a() ) );
	} }
	
	// stop readback profiling
	sTimer1->end();
	mReadBackTime = sTimer1->getElapsedMilliseconds();
	
	return max;
}