Exemple #1
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() );
}
Exemple #2
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
}
Exemple #3
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 ) );
}
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++;
    }
}
Exemple #6
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 ) );
}
Exemple #7
0
void ciApp::setup()
{
	setWindowSize(1280, 720);
	setFrameRate(60.f);
	
	int maxVertUniformsVect;
	glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxVertUniformsVect);

	mSize = 0;
	mSizePrev = -1;
	mSizeMax = 17;
	mAmplifier = 1.f;

	mExposure = 1.f;
	mGamma = 2.2f;

	printf("max uniform: %i, %i\n", maxVertUniformsVect, mSizeMax);

	mParams = params::InterfaceGl::create(getWindow(), "App parameters", ivec2(250, 300));
	mParams->setPosition(ivec2(20, 250));

	mTexture = gl::Texture::create(loadImage(loadFile(data_path + "demo.png")));
	mFbo = gl::Fbo::create(mTexture->getWidth(), mTexture->getHeight(), gl::Fbo::Format().colorTexture());
	//mShader.setup("filterGaussianBlur");

	filter = hb::GlslFilter::create(mTexture->getSize());
	filter->setParams(mParams);

	vector_blur.setup(getWindowSize());
	vector_blur.setParams(mParams);

	spout_receiver = hb::Receiver::create("Spout DX11 Sender");
	//spout_receiver = hbSpoutReceiver::create("KidsLandSea");
	spout_sender = hb::Sender::create("cinder_spout", mFbo->getWidth(), mFbo->getHeight());

#if 0
	auto ctx = audio::Context::master();

	// The InputDeviceNode is platform-specific, so you create it using a special method on the Context:
	mInputDeviceNode = ctx->createInputDeviceNode();

	// By providing an FFT size double that of the window size, we 'zero-pad' the analysis data, which gives
	// an increase in resolution of the resulting spectrum data.
	auto monitorFormat = audio::MonitorSpectralNode::Format().fftSize(2048).windowSize(1024);
	mMonitorSpectralNode = ctx->makeNode(new audio::MonitorSpectralNode(monitorFormat));

	mInputDeviceNode >> mMonitorSpectralNode;

	// InputDeviceNode (and all InputNode subclasses) need to be enabled()'s to process audio. So does the Context:
	mInputDeviceNode->enable();
	ctx->enable();
#endif
}
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();
}
Exemple #9
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 PostProcessingAAApp::render()
{
	// Bind the Fbo. Automatically unbinds it at the end of this function.
	gl::ScopedFramebuffer fbo( mFboScene );

	// Clear the buffer.
	gl::clear( ColorA( 0, 0, 0, 0 ) );
	gl::color( Color::white() );

	// Render our scene.
	gl::pushViewport( 0, 0, mFboScene->getWidth(), mFboScene->getHeight() );
	mPistons.draw( mCamera, float( mTime ) );
	gl::popViewport();
}
void MotionBlurVelocityBufferApp::drawBlurredContent()
{
    gl::ScopedTextureBind colorTex( mGBuffer->getTexture2d( G_COLOR ), 0 );
    gl::ScopedTextureBind velTex( mGBuffer->getTexture2d( G_VELOCITY ), 1 );
    gl::ScopedTextureBind neigborTex( mVelocityDilationBuffer->getTexture2d( DILATE_NEIGHBOR_MAX ), 2 );
    gl::ScopedGlslProg prog( mMotionBlurProg );
    gl::ScopedBlendPremult blend;

    mMotionBlurProg->uniform( "uColorMap", 0 );
    mMotionBlurProg->uniform( "uVelocityMap", 1 );
    mMotionBlurProg->uniform( "uNeighborMaxMap", 2 );
    mMotionBlurProg->uniform( "uNoiseFactor", mBlurNoise );
    mMotionBlurProg->uniform( "uSamples", mSampleCount );

    gl::drawSolidRect( getWindowBounds() );
}
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 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());
        }
        
    }

}
Exemple #14
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 FboMultipleRenderTargetsApp::draw()
{
	gl::clear( Color::gray( 0.35f ) );

	gl::setMatricesWindow( getWindowSize() );

	// draw the two textures we've created side-by-side
	auto tex0 = mFbo->getTexture2d( GL_COLOR_ATTACHMENT0 );
	auto tex1 = mFbo->getTexture2d( GL_COLOR_ATTACHMENT1 );
	gl::draw( tex0, tex0->getBounds() );
	gl::draw( tex1, tex1->getBounds() + vec2( tex1->getWidth(), 0 ) );
}
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 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() );
    }
}
void ShadowMappingBasic::setup()
{
	mLightPos = vec3( 0.0f, 5.0f, 1.0f );
	
	gl::Texture2d::Format depthFormat;
	
#if defined( CINDER_GL_ES )
	depthFormat.setInternalFormat( GL_DEPTH_COMPONENT16 );
#else
	depthFormat.setInternalFormat( GL_DEPTH_COMPONENT32F );
	depthFormat.setCompareMode( GL_COMPARE_REF_TO_TEXTURE );
#endif
	depthFormat.setMagFilter( GL_LINEAR );
	depthFormat.setMinFilter( GL_LINEAR );
	depthFormat.setWrap( GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE );
	depthFormat.setCompareFunc( GL_LEQUAL );
	
	mShadowMapTex = gl::Texture2d::create( FBO_WIDTH, FBO_HEIGHT, depthFormat );

	mCam.setPerspective( 40.0f, getWindowAspectRatio(), 0.5f, 500.0f );
		
	gl::Fbo::Format fboFormat;
	fboFormat.attachment( GL_DEPTH_ATTACHMENT, mShadowMapTex );
	mFbo = gl::Fbo::create( FBO_WIDTH, FBO_HEIGHT, fboFormat );
	
	// Set up camera from the light's viewpoint
	mLightCam.setPerspective( 100.0f, mFbo->getAspectRatio(), 0.5f, 10.0f );
	mLightCam.lookAt( mLightPos, vec3( 0.0f ) );
	
	try {
#if defined( CINDER_GL_ES )
		mGlsl = gl::GlslProg::create( loadAsset( "shadow_shader_es2.vert" ), loadAsset( "shadow_shader_es2.frag" ) );
#else
		mGlsl = gl::GlslProg::create( loadAsset( "shadow_shader.vert" ), loadAsset( "shadow_shader.frag" ) );
#endif
	}
	catch ( Exception &exc ) {
		CI_LOG_EXCEPTION( "glsl load failed", exc );
		std::terminate();
	}
	
	auto teapot				= geom::Teapot().subdivisions( 8 );
	mTeapotBatch			= gl::Batch::create( teapot, gl::getStockShader( gl::ShaderDef() ) );
	mTeapotShadowedBatch	= gl::Batch::create( teapot, mGlsl );
	
	auto floor				= geom::Cube().size( 10.0f, 0.5f, 10.0f );
	mFloorBatch				= gl::Batch::create( floor, gl::getStockShader( gl::ShaderDef() ) );
	mFloorShadowedBatch		= gl::Batch::create( floor, mGlsl );
	
	gl::enableDepthRead();
	gl::enableDepthWrite();
}
void MotionBlurVelocityBufferApp::drawVelocityBuffers()
{
    gl::ScopedGlslProg prog( mVelocityRenderProg );
    gl::ScopedModelMatrix matrix;
    gl::setDefaultShaderVars();

    float width = 200.0f;
    float height = width / Rectf( mVelocityDilationBuffer->getBounds() ).getAspectRatio();
    Rectf rect( 0.0f, 0.0f, width, height );

    gl::ScopedTextureBind velTex( mGBuffer->getTexture2d( G_VELOCITY ), 0 );
    gl::translate( getWindowWidth() - width - 10.0f, 10.0f );
    gl::drawSolidRect( rect );

    gl::ScopedTextureBind tileTex( mVelocityDilationBuffer->getTexture2d( DILATE_TILE_MAX ), 0 );
    gl::translate( 0.0f, height + 10.0f );
    gl::drawSolidRect( rect );

    gl::ScopedTextureBind neigborTex( mVelocityDilationBuffer->getTexture2d( DILATE_NEIGHBOR_MAX ), 0 );
    gl::translate( 0.0f, height + 10.0f );
    gl::drawSolidRect( rect );
}
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() ) );
}
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 );
	}
}
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) );
	}
}
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 );
}
Exemple #24
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 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
}
Exemple #26
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));
	}
}
Exemple #27
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();
}
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() );
}
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;
}
Exemple #30
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() );
    }
}