Beispiel #1
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;
    }
}
Beispiel #2
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 );
	}
}
void NormalGetterApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
    
    if(mFbo && mOutputFbo){
        normalize(mFbo->getColorTexture());
        gl::draw(mOutputFbo->getColorTexture());
    }
    
  //  if(mFbo) gl::draw(mFbo->getColorTexture());
    mStatus->draw();
    mParams->draw();
}
Beispiel #4
0
void FboBasicApp::draw()
{
    // clear the window to gray
    gl::clear( Color( 0.35f, 0.35f, 0.35f ) );

    // setup our camera to render the cube
    CameraPersp cam( getWindowWidth(), getWindowHeight(), 60.0f );
    cam.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );
    cam.lookAt( vec3( 2.6f, 1.6f, -2.6f ), vec3( 0 ) );
    gl::setMatrices( cam );

    // use the scene we rendered into the FBO as a texture
    mFbo->bindTexture();

    // draw a cube textured with the FBO
    {
        gl::ScopedGlslProg shaderScp( gl::getStockShader( gl::ShaderDef().texture() ) );
        gl::drawCube( vec3( 0 ), vec3( 2.2f ) );
    }

    // show the FBO color texture in the upper left corner
    gl::setMatricesWindow( toPixels( getWindowSize() ) );
    gl::draw( mFbo->getColorTexture(), Rectf( 0, 0, 128, 128 ) );
    // and draw the depth texture adjacent
    gl::draw( mFbo->getDepthTexture(), Rectf( 128, 0, 256, 128 ) );
}
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++;
    }
}
void TextParticlesApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
	gl::color( 1, 1, 1 );
	gl::enableAlphaBlending();
	
	{
		gl::ScopedMatrices scpMtrx;
		
		// SET matrices so that by default, we are looking at a rect the size of the window
		lookAtTexture( mCam, getWindowSize() );
		
		gl::translate( mTextSize * vec2( -0.5 ) );
		
		gl::ScopedDepth scpDepth(	true );
//		gl::ScopedColor scpColor( 1, 0, 0 );
//		gl::drawStrokedRect( Rectf( 0, 0, mTextSize.x, mTextSize.y ) );
		
		gl::color( Color::white() );
		if( mActive ){
			gl::ScopedGlslProg render( mRenderProg );
			gl::ScopedVao vao( mAttributes[mSourceIndex] );
			gl::context()->setDefaultShaderVars();
			gl::drawArrays( GL_POINTS, 0, mTextParticleCount );
			
		}else{
			if( mString.length() > 0 )
				gl::draw( mTextFbo->getColorTexture() );
		}
		
	}
	
	mParams->draw();
}
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() );
}
Beispiel #8
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 GpuParrallelReductionApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );
	
	gl::setMatricesWindow( getWindowSize() );
	gl::draw( mFbo->getColorTexture() );
	
	auto max = findMindMax();
	gl::drawStringCentered( "Current Max value: " + toString( max ), getWindowCenter() - vec2( 0, 10 ) );
	gl::drawStringCentered( "Reduction time " + to_string( mReductionTime ) + " ms", getWindowCenter() + vec2( 0, 12 ) );
	gl::drawStringCentered( "Read back time " + to_string( mReadBackTime ) + " ms", getWindowCenter() + vec2( 0, 25 ) );
}
void ViewportArrayApp::draw()
{
	// clear the screen and set matrices
	gl::clear( Color( 0, 0, 0 ) );
	gl::setMatricesWindow( getWindowSize() );
	
	// render our fbo texture
	gl::draw( mFbo->getColorTexture() );
	
	// and viewport bounds
	for( auto viewport : mViewports ) {
		gl::drawStrokedRect( viewport );
	}
}
Beispiel #11
0
void ciApp::draw()
{
	auto viewport = getWindowBounds();
	gl::clear();

	{
		auto rect = Rectf(fbo->getBounds()).getCenteredFit(viewport, false);
		gl::draw(fbo->getColorTexture(), rect);
	}

	if (is_debug_visible)
	{
		params->draw();

		const gl::ScopedColor scpColor(Color::white());
		auto tex = getInfoTexture(getAverageFps(), time_step, elapsed_time, time_value);
		ivec2 pos(20, getWindowHeight() - tex->getHeight() - 20);
		gl::draw(tex, pos);
	}
}
void MotionBlurVelocityBufferApp::draw()
{
    mGpuTimer->begin();
    mCpuTimer.start();

    gl::clear( Color( 0, 0, 0 ) );
    gl::ScopedMatrices matrices;
    gl::setMatricesWindowPersp( getWindowSize(), 60.0f, 1.0f, 5000.0f );
    gl::ScopedViewport viewport( vec2(0), getWindowSize() );
    gl::ScopedBlend blend(false);

    gl::draw( mBackground, getWindowBounds() );

    fillGBuffer();

    if( ! mBlurEnabled ) {
        gl::ScopedBlendAlpha blend;
        gl::draw( mGBuffer->getColorTexture() );
    }
    else {
        dilateVelocity();
        drawBlurredContent();
    }

    if( mDisplayVelocityBuffers ) {
        drawVelocityBuffers();
    }

    mCpuTimer.stop();
    mGpuTimer->end();

    mAverageCpuTime = (mCpuTimer.getSeconds() * 200) + mAverageCpuTime * 0.8f;
    mAverageGpuTime = mGpuTimer->getElapsedMilliseconds() * 0.2f + mAverageGpuTime * 0.8f;

#if ! defined( CINDER_GL_ES )
    mParams->draw();
#endif
}
Beispiel #13
0
void BayBridgeApp::draw()
{
	gl::clear( Color( 0, 0, 0 ) );

	gl::setMatrices(mCamera);
	
	gl::disableDepthRead();
	mTexSkybox->bind(0);
	mBatchSkybox->draw();
	mTexSkybox->unbind(0);
	gl::enableDepthRead();

	drawBridge(vec3(0.25f), 0.15f);
	mBridge.Draw();

	gl::setMatricesWindow(getWindowSize());
	gl::enableAdditiveBlending();
	gl::disableDepthRead();
	gl::draw(mFboBlurV->getColorTexture(), vec2(0));
	gl::disableAlphaBlending();

	mGUI->draw();
}
Beispiel #14
0
void ShaderToyApp::draw()
{
    // Bind textures.
    if( mChannel0 ) mChannel0->bind( 0 );
    if( mChannel1 ) mChannel1->bind( 1 );
    if( mChannel2 ) mChannel2->bind( 2 );
    if( mChannel3 ) mChannel3->bind( 3 );

    // Render the current shader to a frame buffer.
    if( mShaderCurrent && mBufferCurrent ) {
        gl::ScopedFramebuffer fbo( mBufferCurrent );

        // Bind shader.
        gl::ScopedGlslProg shader( mShaderCurrent );
        setUniforms();

        // Clear buffer and draw full screen quad (flipped).
        gl::clear();
        gl::drawSolidRect( Rectf( 0, (float)getWindowHeight(), (float)getWindowWidth(), 0 ) );
    }

    // Render the next shader to a frame buffer.
    if( mShaderNext && mBufferNext ) {
        gl::ScopedFramebuffer fbo( mBufferNext );

        // Bind shader.
        gl::ScopedGlslProg shader( mShaderNext );
        setUniforms();

        // Clear buffer and draw full screen quad (flipped).
        gl::clear();
        gl::drawSolidRect( Rectf( 0, (float)getWindowHeight(), (float)getWindowWidth(), 0 ) );
    }

    // Perform a cross-fade between the two shaders.
    double time = getElapsedSeconds() - mTransitionTime;
    double fade = math<double>::clamp( time / mTransitionDuration, 0.0, 1.0 );

    if( fade <= 0.0 ) {
        // Transition has not yet started. Keep drawing current buffer.
        gl::draw( mBufferCurrent->getColorTexture(), getWindowBounds() );
    }
    else if( fade < 1.0 ) {
        // Transition is in progress.
        // Use a transition shader to avoid having to draw one buffer on top of another.
        gl::ScopedTextureBind tex0( mBufferCurrent->getColorTexture(), 0 );
        gl::ScopedTextureBind tex1( mBufferNext->getColorTexture(), 1 );

        gl::ScopedGlslProg shader( mShaderTransition );
        mShaderTransition->uniform( "iSrc", 0 );
        mShaderTransition->uniform( "iDst", 1 );
        mShaderTransition->uniform( "iFade", (float)fade );

        gl::drawSolidRect( getWindowBounds() );
    }
    else if( mShaderNext ) {
        // Transition is done. Swap shaders.
        gl::draw( mBufferNext->getColorTexture(), getWindowBounds() );

        mShaderCurrent = mShaderNext;
        mShaderNext.reset();

        mPathCurrent = mPathNext;
        mPathNext.clear();

        getWindow()->setTitle( std::string( "ShaderToyApp - Showing " ) + mPathCurrent.filename().string() );
    }
    else {
        // No transition in progress.
        gl::draw( mBufferCurrent->getColorTexture(), getWindowBounds() );
    }
}
void NormalGetterApp::setupParams(){
    mParams = params::InterfaceGl::create( "Normal Getter", vec2( 300, 220 ) );
    mParams->addSeparator();
    mParams->addButton("InvertG", [&](){
        invertG = !invertG;
    });
    mParams->addButton("InvertR", [&](){
        invertR =! invertR;
    });
    mParams->addParam("bias", &bias).min(0.f).max(100.f);
    mParams->addButton( "Load movie", [ & ](){
        makeMovie = true;
    } );
    mParams->addButton( "Play movie", [ & ](){
        if(mMovie) mMovie->play();
    } );
    mParams->addButton( "Stop movie", [ & ](){
        if(mMovie) mMovie->stop();
    } );
    mParams->addButton( "Choose Save Directory", [ & ](){
        saveDirectory = getFolderPath();
        directory = saveDirectory.string();
    } );
    mParams->addParam("Save Directory", &directory).updateFn([&](){
        saveDirectory = directory;
    });
    mParams->addButton( "Process Frame", [ & ](){
        if(mMovie && mOutputFbo)writeImage(saveDirectory / string(to_string(1000000 +int(mMovie->getCurrentTime()*mMovie->getFramerate()))+ ".png"), mOutputFbo->getColorTexture()->createSource(), ImageTarget::Options(),"png");
    } );
    mParams->addButton( "Process Batch", [ & ](){
        if(!pushFramesToBuffer && mMovie){
            pushFramesToBuffer = true;
            currentFrame = 0;
            mMovie->seekToStart();
            mMovie->setLoop(false);
            mMovie->play();
        }
    } );

}
Beispiel #16
0
void FaceOff::draw()
{
    gl::clear(ColorA::black(), false);

    if (!mCapture.isReady())
        return;

    gl::setMatricesWindow(getWindowSize());

    gl::enableAlphaBlending();

    float camAspect = CAM_W / (float)CAM_H;
    float winAspect = getWindowAspectRatio();
    float adaptiveCamW = 0;
    float adaptiveCamH = 0;
    if (camAspect > winAspect)
    {
        adaptiveCamW = APP_W;
        adaptiveCamH = APP_W / camAspect;
    }
    else
    {
        adaptiveCamH = APP_H;
        adaptiveCamW = APP_H * camAspect;
    }
    Area srcArea = { 0, 0, CAM_W, CAM_H };
    Rectf dstRect =
    {
        APP_W * 0.5f - adaptiveCamW * 0.5f,
        APP_H * 0.5f - adaptiveCamH * 0.5f,
        APP_W * 0.5f + adaptiveCamW * 0.5f,
        APP_H * 0.5f + adaptiveCamH * 0.5f
    };

    if (!mOnlineTracker)
    {
        gl::draw(mCapture.texture, srcArea, dstRect);
        return;
    }

    gl::Texture2dRef fullscreenTex;
    if (VFX_VISIBLE && mHasNewRenderedFace)
    {
        fullscreenTex = mClone.getResultTexture();
    }
    else if (VFX_VISIBLE && MOVIE_MODE)
    {
        fullscreenTex = mRenderedOfflineFaceFbo->getColorTexture();
    }
    else
    {
        fullscreenTex = mCapture.texture;
    }
    gl::draw(fullscreenTex, srcArea, dstRect);

    if (OFFLINE_VISIBLE)
    {
        gl::draw(mOfflineFaceTex);
    }

    FPS = getAverageFps();

    gl::disableAlphaBlending();

    if (WIREFRAME_MODE && (MOVIE_MODE || mHasNewRenderedFace))
    {
        gl::enableWireframe();

        gl::ScopedModelMatrix modelMatrix;
        gl::ScopedColor color(ColorA(0, 1.0f, 0, 1.0f));
        gl::translate(dstRect.x1, dstRect.y1);
        gl::scale(adaptiveCamW / CAM_W, adaptiveCamH / CAM_H);
        gl::draw(mFaceMesh);

        if (OFFLINE_VISIBLE)
        {
            gl::draw(mOfflineTracker->getImageMesh());
        }

        gl::disableWireframe();
    }
    
    updateGui();
}
void PostProcessingAAApp::draw()
{
	// Render our scene to an Fbo.
	render();

	// Clear the main buffer.
	gl::clear();
	gl::color( Color::white() );

	// Draw non-anti-aliased scene.
	if( mDividerMode == MODE_COMPARISON || mDividerMode == MODE_ORIGINAL1 || mDividerMode == MODE_ORIGINAL2 )
		gl::draw( mFboScene->getColorTexture(), getWindowBounds() );

	// Draw FXAA-anti-aliased scene.
	if( mDividerMode == MODE_COMPARISON || mDividerMode == MODE_FXAA ) {
		mFXAA.apply( mFboFinal, mFboScene );

		if( mDividerMode == MODE_COMPARISON ) {
			gl::pushMatrices();
			gl::setMatricesWindow( mDividerWidth, getWindowHeight() );
			gl::pushViewport( (int) mDivider.x - mDividerWidth, 0, mDividerWidth, getWindowHeight() );
			gl::draw( mFboFinal->getColorTexture(), getWindowBounds().getMoveULTo( vec2( -( mDivider.x - mDividerWidth ), 0 ) ) );
			gl::popViewport();
			gl::popMatrices();
		}
		else {
			gl::draw( mFboFinal->getColorTexture(), getWindowBounds() );
		}
	}

	// Draw SMAA-anti-aliased scene.
	if( mDividerMode == MODE_COMPARISON || mDividerMode == MODE_SMAA ) {
		mSMAA.apply( mFboFinal, mFboScene );

		gl::TextureRef tex;
		switch( mSMAAMode ) {
		case SMAA_EDGE_DETECTION: tex = mSMAA.getEdgePass(); break;
		case SMAA_BLEND_WEIGHTS: tex = mSMAA.getBlendPass(); break;
		case SMAA_BLEND_NEIGHBORS: tex = mFboFinal->getColorTexture(); break;
		}

		if( mDividerMode == MODE_COMPARISON ) {
			gl::pushMatrices();
			gl::setMatricesWindow( mDividerWidth, getWindowHeight() );
			gl::pushViewport( (int) mDivider.x, 0, mDividerWidth, getWindowHeight() );
			gl::draw( tex, getWindowBounds().getMoveULTo( vec2( -mDivider.x, 0 ) ) );
			gl::popViewport();
			gl::popMatrices();
		}
		else {
			gl::pushMatrices();
			gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
			gl::draw( tex, getWindowBounds() );
			gl::popMatrices();
		}
	}

	// Draw divider.
	if( mDividerMode == MODE_COMPARISON ) {
		gl::drawLine( vec2( (float) mDivider.x, 0 ), vec2( (float) mDivider.x, (float) getWindowHeight() ) );
		gl::drawLine( vec2( (float) ( mDivider.x - mDividerWidth ), 0 ), vec2( (float) ( mDivider.x - mDividerWidth ), (float) getWindowHeight() ) );
		gl::drawLine( vec2( (float) ( mDivider.x + mDividerWidth ), 0 ), vec2( (float) ( mDivider.x + mDividerWidth ), (float) getWindowHeight() ) );
	}

	// Draw info.
	gl::enableAlphaBlending();
	switch( mDividerMode ) {
	case MODE_COMPARISON:
		gl::draw( mInfoOriginal, vec2( mDivider.x - mDividerWidth * 3 / 2 - 128, 32 ) );
		gl::draw( mInfoFXAA, vec2( mDivider.x - mDividerWidth * 1 / 2 - 128, 32 ) );
		gl::draw( mInfoSMAA, vec2( mDivider.x + mDividerWidth * 1 / 2 - 128, 32 ) );
		gl::draw( mInfoOriginal, vec2( mDivider.x + mDividerWidth * 3 / 2 - 128, 32 ) );
		break;
	case MODE_ORIGINAL1:
	case MODE_ORIGINAL2:
		gl::draw( mInfoOriginal, vec2( getWindowWidth() / 2 - 128, 32 ) );
		break;
	case MODE_FXAA:
		gl::draw( mInfoFXAA, vec2( getWindowWidth() / 2 - 128, 32 ) );
		break;
	case MODE_SMAA:
		gl::draw( mInfoSMAA, vec2( getWindowWidth() / 2 - 128, 32 ) );
		break;
	default:
		break;
	}
	gl::disableAlphaBlending();
}