void SmoothDisplacementMappingApp::renderDisplacementMap()
{
	if( mDispMapShader && mDispMapFbo ) 
	{
		mDispMapFbo.bindFramebuffer();
		{
			// clear the color buffer
			gl::clear();			

			// setup viewport and matrices 
			glPushAttrib( GL_VIEWPORT_BIT );
			gl::setViewport( mDispMapFbo.getBounds() );

			gl::pushMatrices();
			gl::setMatricesWindow( mDispMapFbo.getSize(), false );

			// render the displacement map
			mDispMapShader.bind();
			mDispMapShader.uniform( "time", float( getElapsedSeconds() ) );
			mDispMapShader.uniform( "amplitude", mAmplitude );
			gl::drawSolidRect( mDispMapFbo.getBounds() );
			mDispMapShader.unbind();

			// clean up after ourselves
			gl::popMatrices();
			glPopAttrib();
		}
		mDispMapFbo.unbindFramebuffer();
	}
}
Exemplo n.º 2
0
void Simulacra::helix()
{
    glDisable(GL_LIGHTING);
    glDisable(GL_LIGHT0);

    // render a simple scene into mFboScene
    helixShader.bind();
    gl::translate(0,0,0);
    helixFBO.bindFramebuffer();

    helixShader.uniform("time",Vec2f(sin(rotation),1-sin(rotation*0.71)));
    gl::clear(ColorA(0,0,0,1));
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    gl::drawSolidRect(cinder::Rectf(0,0,getWindowWidth(),getWindowHeight()));
    helixFBO.unbindFramebuffer();
    helixShader.unbind();

    //Revert back to screen
    gl::color(cinder::ColorA(1,1,1,1));
    applyHelixShader.bind();
    finalFBO.bindTexture(0);
    applyHelixShader.uniform("qt_Texture0",0);
    helixFBO.bindTexture(1);
    applyHelixShader.uniform("qt_Texture1",1);

    gl::drawSolidRect(cinder::Rectf(0,getWindowHeight(),getWindowWidth(),0));
    applyHelixShader.unbind();
    helixFBO.unbindTexture();
    finalFBO.unbindTexture();

    gl::color(ColorA(1,1,1,1));
}
void BloomingNeonApp::render()
{
	// get the current viewport
	Area viewport = gl::getViewport();

	// adjust the aspect ratio of the camera
	mCamera.setAspectRatio( viewport.getWidth() / (float) viewport.getHeight() );
	
	// render our scene (see the Picking3D sample for more info)
	gl::pushMatrices();

		gl::setMatrices( mCamera );
		gl::enableDepthRead();
		gl::enableDepthWrite();
		
			mShaderPhong.bind();
			mShaderPhong.uniform("tex_diffuse", 0);
			mShaderPhong.uniform("tex_specular", 1);
				gl::pushModelView();
				gl::multModelView( mTransform );
					gl::color( Color::white() );
					gl::draw( mMesh );
				gl::popModelView();		
			mShaderPhong.unbind();

		gl::disableDepthWrite();
		gl::disableDepthRead();

	gl::popMatrices();
}
Exemplo n.º 4
0
void HiKinectApp::generateNormalMap() {
	// bind the Fbo
	mFbo.bindFramebuffer();
	// match the viewport to the Fbo dimensions
	gl::setViewport( mFbo.getBounds() );
	// setup an ortho projection
	gl::setMatricesWindow( mFbo.getWidth(), mFbo.getHeight() );
	// clear the Fbo
	gl::clear( Color( 0, 0, 0 ) );
	
	// bind the shader, set its variables
	mNormalShader.bind();
	mNormalShader.uniform( "normalStrength", mNormalStrength);
	mNormalShader.uniform( "texelWidth", 1.0f / (float)CAPTURE_WIDTH );
	
	if ( mDepthTexture ) {
		gl::pushModelView();
//		gl::translate( Vec3f( 0, mDepthTexture.getHeight(), 0 ) );
//		gl::scale( Vec3f( 1, -1, 1 ) );
		gl::draw( mDepthTexture );
		gl::popModelView();
	}
	
	// unbind the shader
	mNormalShader.unbind();
	// unbind the Fbo
	mFbo.unbindFramebuffer();
}
Exemplo n.º 5
0
void StereoscopicRenderingApp::renderAnaglyph(  const Vec2i &size, const ColorA &left, const ColorA &right )
{	
	// bind the FBO and clear its buffer
	mFbo.bindFramebuffer();
	gl::clear( mColorBackground );

	// render the scene using the side-by-side technique
	renderSideBySide( mFbo.getSize() );

	// unbind the FBO
	mFbo.unbindFramebuffer();

	// enable the anaglyph shader
	mShaderAnaglyph.bind();
	mShaderAnaglyph.uniform( "tex0", 0 );
	mShaderAnaglyph.uniform( "clr_left", left );
	mShaderAnaglyph.uniform( "clr_right", right );	

	// bind the FBO texture and draw a full screen rectangle,
	// which conveniently is exactly what the following line does
	gl::draw( mFbo.getTexture(), Rectf(0, float(size.y), float(size.x), 0) );

	// disable the anaglyph shader
	mShaderAnaglyph.unbind();
}
Exemplo n.º 6
0
void StereoscopicRenderingApp::renderInterlacedHorizontal( const Vec2i &size )
{
	// bind the FBO and clear its buffer
	mFbo.bindFramebuffer();
	gl::clear( mColorBackground );

	// render the scene using the over-under technique
	renderOverUnder( mFbo.getSize() );

	// unbind the FBO
	mFbo.unbindFramebuffer();

	// enable the interlace shader
	mShaderInterlaced.bind();
	mShaderInterlaced.uniform( "tex0", 0 );
	mShaderInterlaced.uniform( "window_origin", Vec2f( getWindowPos() ) );
	mShaderInterlaced.uniform( "window_size", Vec2f( getWindowSize() ) );

	// bind the FBO texture and draw a full screen rectangle,
	// which conveniently is exactly what the following line does
	gl::draw( mFbo.getTexture(), Rectf(0, float(size.y), float(size.x), 0) );

	// disable the interlace shader
	mShaderInterlaced.unbind();
}
void AudioVisualizerApp::draw()
{
	gl::clear();

	// use camera
	gl::pushMatrices();
	gl::setMatrices(mCamera);
	{
		// bind shader
		mShader.bind();
		mShader.uniform("uTexOffset", mOffset / float(kHistory));
		mShader.uniform("uLeftTex", 0);
		mShader.uniform("uRightTex", 1);

		// create textures from our channels and bind them
		mTextureLeft = gl::Texture(mChannelLeft, mTextureFormat);
		mTextureRight = gl::Texture(mChannelRight, mTextureFormat);

		mTextureLeft.enableAndBind();
		mTextureRight.bind(1);

		// draw mesh using additive blending
		gl::enableAdditiveBlending();
		gl::color( Color(1, 1, 1) );
		gl::draw( mMesh );
		gl::disableAlphaBlending();

		// unbind textures and shader
		mTextureRight.unbind();
		mTextureLeft.unbind();
		mShader.unbind();
	}
	gl::popMatrices();
}
Exemplo n.º 8
0
void LEDCamApp::draw()
{
	// clear out the window with black
	gl::clear( kClearColor ); 
	
	if( !mTexture ) return;
	mFbo.bindFramebuffer();
	mTexture.enableAndBind();
	mShader.bind();
	float aspect = kWindowHeight/kWindowWidth;
	cout << "Aspect: " << aspect << " \n";
	mShader.uniform( "aspect", aspect );
	mShader.uniform( "tex", 0 );
	mShader.uniform( "bright", 3.0f );
	mShader.uniform( "spacing", 3 );
	mShader.uniform( "ledCount", 100.0f );
	gl::drawSolidRect( getWindowBounds() );
	mTexture.unbind();
	mShader.unbind();
	mFbo.unbindFramebuffer();
	
	gl::Texture fboTexture = mFbo.getTexture();
	fboTexture.setFlipped();
	gl::draw( fboTexture );

}
Exemplo n.º 9
0
void PixarDemo2012::renderGradientFBO()
{
    gl::enableAlphaBlending();

    gl::SaveFramebufferBinding bindingSaver;

    mGradientFBO.bindFramebuffer();

    gl::setViewport( mGradientFBO.getBounds() );

    gl::setMatricesWindow( getWindowSize(), true );

    gl::clear( ColorA(0.0f,0.0f,0.0f,1.0f) );

    glDisable( GL_TEXTURE_2D );

    //    mGradientFBO.bindTexture(0);
    mGradientShader.bind();
    float what = mTime;
    mGradientShader.uniform("mTime", what);
    mGradientShader.uniform("resolution", Vec2f((float)getWindowWidth(),(float)getWindowHeight()));
    gl::drawSolidRect( getWindowBounds() );
    mGradientShader.unbind();
    //    mGradientFBO.unbindTexture();

    gl::popMatrices();
}
/**
 here's where the magic happens
 all calculations are done in update
 **/
void millionParticlesApp::update()
{

    mFbo[mBufferIn].bindFramebuffer();

    //set viewport to fbo size
    gl::setMatricesWindow( mFbo[0].getSize(), false ); // false to prevent vertical flipping
    gl::setViewport( mFbo[0].getBounds() );

    GLenum buffer[3] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT };
    glDrawBuffers(3,buffer);

    mFbo[mBufferOut].bindTexture(0,0);
    mFbo[mBufferOut].bindTexture(1,1);
    mFbo[mBufferOut].bindTexture(2,2);

    mVelTex.bind(3);
    mPosTex.bind(4);
    mNoiseTex.bind(5);

    mVelShader.bind();
    mVelShader.uniform("positions",0);
    mVelShader.uniform("velocities",1);
    mVelShader.uniform("information",2);
    mVelShader.uniform("oVelocities",3);
    mVelShader.uniform("oPositions",4);
    mVelShader.uniform("noiseTex",5);

    glBegin(GL_QUADS);
    glTexCoord2f( 0.0f, 0.0f);
    glVertex2f( 0.0f, 0.0f);
    glTexCoord2f( 0.0f, 1.0f);
    glVertex2f( 0.0f, PARTICLES);
    glTexCoord2f( 1.0f, 1.0f);
    glVertex2f( PARTICLES, PARTICLES);
    glTexCoord2f( 1.0f, 0.0f);
    glVertex2f( PARTICLES, 0.0f);
    glEnd();

    mVelShader.unbind();

    mFbo[mBufferOut].unbindTexture();

    mVelTex.unbind();
    mPosTex.unbind();

    mFbo[mBufferIn].unbindFramebuffer();

    mBufferIn = (mBufferIn + 1) % 2;
    mBufferOut = (mBufferIn + 1) % 2;

    //for recording
    //    if (getElapsedFrames() == 600)
    //        exit(0);

}
Exemplo n.º 11
0
void HexagonMirrorApp::draw()
{
    // clear the window
    gl::clear();

    // activate our camera
    gl::pushMatrices();
    gl::setMatrices( mCamera.getCamera() );

    // set render states
    gl::enable( GL_CULL_FACE );
    gl::enableDepthRead();
    gl::enableDepthWrite();
    gl::color( Color::white() );

    if( mVboMesh && mShaderInstanced && mBuffer )
    {
        // bind webcam image
        if( mWebcamTexture )
            mWebcamTexture.bind(0);

        // bind the shader, which will do all the hard work for us
        mShaderInstanced.bind();
        mShaderInstanced.uniform( "texture", 0 );
        mShaderInstanced.uniform( "scale", Vec2f( 1.0f / (3.0f * INSTANCES_PER_ROW), 1.0f / (3.0f * INSTANCES_PER_ROW) ) );

        // bind the buffer containing the model matrix for each instance,
        // this will allow us to pass this information as a vertex shader attribute.
        // See: initializeBuffer()
        glBindVertexArray(mVAO);

        // we do all positioning in the shader, and therefor we only need
        // a single draw call to render all instances.
        drawInstanced( mVboMesh, NUM_INSTANCES );

        // make sure our VBO is no longer bound
        mVboMesh.unbindBuffers();

        // unbind vertex array object containing our buffer
        glBindVertexArray(0);

        // unbind shader
        mShaderInstanced.unbind();

        if( mWebcamTexture )
            mWebcamTexture.unbind();
    }

    // reset render states
    gl::disableDepthWrite();
    gl::disableDepthRead();
    gl::disable( GL_CULL_FACE );

    // restore 2D drawing
    gl::popMatrices();
}
Exemplo n.º 12
0
void GeometryShaderApp::draw()
{
	// clear out the window 
	gl::clear( Color(0.95f, 0.95f, 0.95f) );

	// bind the shader and send the mesh to the GPU
	if(mShader && mVboMesh) {
		mShader.bind();
		mShader.uniform( "WIN_SCALE", Vec2f( getWindowSize() ) ); // casting to Vec2f is mandatory!
		mShader.uniform( "MITER_LIMIT", mLimit );
		mShader.uniform( "THICKNESS", mThickness );
		
		if(mTexture) {
			gl::enableAlphaBlending();
			gl::color( Color::white() );
			mTexture.enableAndBind();
		}
		else
			gl::color( Color::black() );

		gl::draw( mVboMesh );

		if(mTexture) {
			mTexture.unbind();
			gl::disableAlphaBlending();
		}

		if(mDrawWireframe) {
			gl::color( Color::black() );
			gl::enableWireframe();
			gl::draw( mVboMesh );
			gl::disableWireframe();
		}

		mShader.unbind();
	}

	// draw all points as red circles
	gl::color( Color(1, 0, 0) );

	std::vector<Vec2f>::const_iterator itr;
	for(itr=mPoints.begin();itr!=mPoints.end();++itr)
		gl::drawSolidCircle( *itr, mRadius );

	if( ! mPoints.empty() )
		gl::drawStrokedCircle( mPoints.back(), mRadius + 2.0f );

	// draw help
	if(mHelpTexture) {
		gl::color( Color::white() );
		gl::enableAlphaBlending();
		gl::draw( mHelpTexture );
		gl::disableAlphaBlending();
	}
}
Exemplo n.º 13
0
void MemExploreApp::draw()
{
  mTexture = gl::Texture(mDataPointer, GL_RGBA, mVolumeDim * mTilesDim, mVolumeDim * mTilesDim);
  mTexture.setWrap(GL_REPEAT, GL_REPEAT);
  mTexture.setMinFilter(GL_NEAREST);
  mTexture.setMagFilter(GL_NEAREST);
  
  float frustum[6];
  mCamera.getFrustum(&frustum[0], &frustum[1], &frustum[2], &frustum[3], &frustum[4], &frustum[5]);

  mFbo.bindFramebuffer();
  gl::setMatricesWindow(mFbo.getSize(), false);

  mProgram.bind();
  mProgram.uniform("uTexture", 0);
  mProgram.uniform("uVolumeDim", mVolumeDim);
  mProgram.uniform("uTilesDim", mTilesDim);
  mProgram.uniform("uTime", (float)getElapsedSeconds());
  mProgram.uniform("uEyePoint", mCamera.getEyePoint());
  mProgram.uniform("uXAxis", mCamera.getOrientation() * Vec3f::xAxis());
  mProgram.uniform("uYAxis", mCamera.getOrientation() * Vec3f::yAxis());
  mProgram.uniform("uViewDistance", mCamera.getAspectRatio() / abs(frustum[2] - frustum[0]) * mCamera.getNearClip());
  mProgram.uniform("uNegViewDir", -mCamera.getViewDirection().normalized());
  mProgram.uniform("uAspectRatio", mCamera.getAspectRatio());
  mTexture.enableAndBind();
  gl::drawSolidRect(mFbo.getBounds());
  mTexture.unbind();
  mProgram.unbind();
  
  mFbo.unbindFramebuffer();
  
  gl::setMatricesWindow(getWindowSize());
  gl::draw(mFbo.getTexture(), getWindowBounds());
}
/**
 the draw method displays the last filled buffer
 **/
void millionParticlesApp::draw()
{
    gl::setMatricesWindow( getWindowSize() );
    gl::setViewport( getWindowBounds() );

    gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 1.0f ) );

    gl::enableAlphaBlending();
    glDisable(GL_DEPTH_TEST);

    glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);

    mFbo[mBufferIn].bindTexture(0,0);
    mFbo[mBufferIn].bindTexture(1,1);
    mFbo[mBufferIn].bindTexture(2,2);

    mSpriteTex.bind(3);

    //Bewegungsshader
    mPosShader.bind();
    mPosShader.uniform("posTex",0);
    mPosShader.uniform("velTex",1);
    mPosShader.uniform("infTex",2);
    mPosShader.uniform("spriteTex",3);

    mPosShader.uniform("scale",(float)PARTICLES);

    gl::color(ColorA(1.0f,1.0f,1.0f,1.0f));
    //glTranslatef(Vec3f(getWindowWidth() / 4  - PARTICLES,0.0f,0.0f));
    gl::pushMatrices();

    glScalef(getWindowHeight() / (float)PARTICLES , getWindowHeight() / (float)PARTICLES ,1.0f);

    // draw particles
    gl::draw( mVbo );

    gl::popMatrices();

    mPosShader.unbind();

    mSpriteTex.unbind();

    mFbo[mBufferIn].unbindTexture();

    //    writeImage( "/Users/hacku/Desktop/img/1m/" + toString(getElapsedFrames()) + ".tif",   copyWindowSurface() );

    //	gl::color(Color(1,1,1));
    //	gl::setMatricesWindow( getWindowSize() );

    //drawText();

    gl::disableAlphaBlending();

}
/* 
 * @Description: render SSAO now - woohoo!
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderSSAOToFBO()
{
	gl::setViewport( mSSAOMap.getBounds() );
	
	//render out main scene to FBO
	mSSAOMap.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mSSAOMap.getSize() );
	
	mRandomNoise.bind(1);
	mNormalDepthMap.getTexture().bind(2);
	
	mSSAOShader.bind();
	
	mSSAOShader.uniform("rnm", 1 );
	mSSAOShader.uniform("normalMap", 2 );
    
    //look at shader and see you can set these through the client if you so desire.
    //	mSSAOShader.uniform("rnm", 1 );
    //	mSSAOShader.uniform("normalMap", 2 );	
    //	mSSAOShader.uniform("totStrength", 1.38f);
    //	mSSAOShader.uniform("strength", 0.07f);
    //	mSSAOShader.uniform("offset", 10.0f);
    //	mSSAOShader.uniform("falloff", 0.2f);
    //	mSSAOShader.uniform("rad", 0.8f);
    
    //	mSSAOShader.uniform("rnm", 1 );
    //	mSSAOShader.uniform("normalMap", 2 );
    //	mSSAOShader.uniform("farClipDist", 20.0f);
    //	mSSAOShader.uniform("screenSizeWidth", (float)getWindowWidth());
    //	mSSAOShader.uniform("screenSizeHeight", (float)getWindowHeight());
	
    //	mSSAOShader.uniform("grandom", 1 );
    //	mSSAOShader.uniform("gnormals", 2 );
    //	mSSAOShader.uniform("gdepth", 1 );
    //	mSSAOShader.uniform("gdiffuse", 1 );
    
    gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	
	mSSAOShader.unbind();
	
	mNormalDepthMap.getTexture().unbind(2);
	mRandomNoise.unbind(1);
	
	mSSAOMap.unbindFramebuffer();
	
	gl::setViewport( getWindowBounds() );
}
Exemplo n.º 16
0
void MandelbrotGLSLApp::draw()
{
	gl::clear( Color( 0.2f, 0.2f, 0.2f ) );	
	gl::setMatricesWindow( getWindowSize() );
	
	mBrotShader.bind();
	mBrotShader.uniform( "tex", 0 );
	mBrotShader.uniform( "center", mCenter );
	mBrotShader.uniform( "scale", mScale );
	mBrotShader.uniform( "iter", mIter );
	gl::drawSolidRect( getWindowBounds() );
	mBrotShader.unbind();
}
Exemplo n.º 17
0
void RepulsionApp::drawIntoVelocityFbo()
{
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	gl::disableAlphaBlending();
	
	mVelocityFbos[ mThisFbo ].bindFramebuffer();
	gl::clear( ColorA( 0, 0, 0, 0 ) );
	
	mPositionFbos[ mPrevFbo ].bindTexture( 0 );
	mVelocityFbos[ mPrevFbo ].bindTexture( 1 );

	mVelocityShader.bind();
	mVelocityShader.uniform( "position", 0 );
	mVelocityShader.uniform( "velocity", 1 );
	mVelocityShader.uniform( "roomBounds", mRoom.getDims() );
	mVelocityShader.uniform( "w", FBO_WIDTH );
	mVelocityShader.uniform( "h", FBO_HEIGHT );
	mVelocityShader.uniform( "invWidth", 1.0f/(float)FBO_WIDTH );
	mVelocityShader.uniform( "invHeight", 1.0f/(float)FBO_HEIGHT );
	mVelocityShader.uniform( "dt", mRoom.getTimeDelta() );
	mVelocityShader.uniform( "mainPower", mRoom.getPower() );
	mVelocityShader.uniform( "gravity", mRoom.getGravity() );
	gl::drawSolidRect( mFboBounds );
	mVelocityShader.unbind();
	
	mVelocityFbos[ mThisFbo ].unbindFramebuffer();
}
Exemplo n.º 18
0
void TerrainApp::drawIntoRoomFbo()
{
	mRoomFbo.bindFramebuffer();
	gl::clear( ColorA( 0.0f, 0.0f, 0.0f, 0.0f ), true );
	
	gl::setMatricesWindow( mRoomFbo.getSize(), false );
	gl::setViewport( mRoomFbo.getBounds() );
	gl::disableAlphaBlending();
	gl::enable( GL_TEXTURE_2D );
	glEnable( GL_CULL_FACE );
	glCullFace( GL_BACK );
	Matrix44f m;
	m.setToIdentity();
	m.scale( mRoom.getDims() );

	mCubeMap.bind();
	mRoomShader.bind();
	mRoomShader.uniform( "cubeMap", 0 );
	mRoomShader.uniform( "mvpMatrix", mSpringCam.mMvpMatrix );
	mRoomShader.uniform( "mMatrix", m );
	mRoomShader.uniform( "eyePos", mSpringCam.mEye );
	mRoomShader.uniform( "roomDims", mRoom.getDims() );
	mRoomShader.uniform( "power", mRoom.getPower() );
	mRoomShader.uniform( "lightPower", mRoom.getLightPower() );
	mRoomShader.uniform( "timePer", mRoom.getTimePer() * 1.5f + 0.5f );
	mRoom.draw();
	mRoomShader.unbind();
	
	mRoomFbo.unbindFramebuffer();
	glDisable( GL_CULL_FACE );
}
Exemplo n.º 19
0
void shaderExternalFileExampleApp::draw(){
    
	gl::clear( Color::black() );
	
    if( mTexture ) {
        mTexture.bind( 0 );
        mShader.bind();
        mShader.uniform( "texture", 0 );
        mShader.uniform( "width", (float)CAM_W );
        mShader.uniform( "height", (float)CAM_H );
        gl::drawSolidRect( getWindowBounds() );
        mShader.unbind();
        mTexture.unbind();
    }
}
void BasicBrickShaderApp::draw()
{
    gl::setMatrices(mCam);
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
    mShader.bind();
    mShader.uniform("LightPosition", mLightPos);
    mShader.uniform("BrickColor", mBrickColor);
    mShader.uniform("BrickPct", mBrickPct);
    mShader.uniform("BrickSize", mBrickSize);
    mShader.uniform("MortarColor", mMortarColor);
    gl::drawCube(Vec3f::zero(), Vec3f(50.0f,50.0f,50.0f));
    //gl::drawSphere(Vec3f::zero(), 50.0f);
    mShader.unbind();
}
Exemplo n.º 21
0
void RepulsionApp::setFboVelocities( gl::Fbo &fbo )
{
	Surface32f vel( fbo.getTexture() );
	Surface32f::Iter it = vel.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = Rand::randVec3f() * 0.1f;
			it.r() = 0.0f;//r.x;
			it.g() = 0.0f;//r.y;
			it.b() = 0.0f;//r.z;
			it.a() = 0.0f;
		}
	}
	
	gl::Texture velTexture( vel );
	velTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mVelInitShader.bind();
	mVelInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mVelInitShader.unbind();
	fbo.unbindFramebuffer();
}
void BasicShaderIIApp::draw()
{
	gl::clear( Color::black() ); 
	// Draw FPS
	gl::color( Color::white() );
	mTextureFont->drawString( toString( floor(getAverageFps()) ) + " FPS", Vec2f( 100, getWindowHeight() - mTextureFont->getDescent() ) );
    
    gl::pushMatrices();
	gl::setMatrices( mCam );
    gl::enableAlphaBlending();
    
	// draw interface
	params::InterfaceGl::draw();
	
	if( mDoSave )
	{	// save non-conflicting image
		// includes interface to record parameters
		saveFrame();
		mDoSave = false;
	}
    
    mShader.bind();
    mShader.uniform("lightDir", mLightDir );   
    
    gl::pushMatrices();
    gl::rotate( mArcball.getQuat() );
    gl::draw( mVBO );
    gl::popMatrices();
    mShader.unbind();     
    
    gl::popMatrices();
}
Exemplo n.º 23
0
void gpuPSApp::update()
{	
	gl::setMatricesWindow( mFBO[0].getSize(), false ); // false to prevent vertical flipping
	gl::setViewport( mFBO[0].getBounds() );
	
	mFBO[ mCurrentFBO ].bindFramebuffer();
	
	GLenum buf[2] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
	glDrawBuffers(2, buf);
	mFBO[ mOtherFBO ].bindTexture(0, 0);
	mFBO[ mOtherFBO ].bindTexture(1, 1);
	mPosShader.bind();
	mPosShader.uniform( "posArray", 0 );
	mPosShader.uniform( "velArray", 1 );
	
	glBegin(GL_QUADS);
	glTexCoord2f( 0.0f, 0.0f); glVertex2f( 0.0f, 0.0f);
	glTexCoord2f( 0.0f, 1.0f); glVertex2f( 0.0f, SIDE);
	glTexCoord2f( 1.0f, 1.0f); glVertex2f( SIDE, SIDE);
	glTexCoord2f( 1.0f, 0.0f); glVertex2f( SIDE, 0.0f);
	glEnd();
	
	mPosShader.unbind();
	mFBO[ mOtherFBO ].unbindTexture();
	mFBO[ mCurrentFBO ].unbindFramebuffer();
	
	mCurrentFBO = ( mCurrentFBO + 1 ) % 2;
	mOtherFBO   = ( mCurrentFBO + 1 ) % 2;
}
Exemplo n.º 24
0
void RepulsionApp::draw()
{
	// clear out the window with black
	gl::clear( ColorA( 0.1f, 0.1f, 0.1f, 0.0f ), true );
	
	gl::setMatricesWindow( getWindowSize(), false );
	gl::setViewport( getWindowBounds() );

	gl::disableDepthRead();
	gl::disableDepthWrite();
	gl::enable( GL_TEXTURE_2D );
	gl::enableAlphaBlending();
	
	gl::color( ColorA( 1.0f, 1.0f, 1.0f, 1.0f ) );
	
	// DRAW ROOM
	mRoomFbo.bindTexture();
	gl::drawSolidRect( getWindowBounds() );
	
	gl::setMatrices( mSpringCam.getCam() );
	
	// DRAW PANEL
	drawInfoPanel();
	gl::enable( GL_TEXTURE_2D );
	
	gl::enableDepthRead();
	gl::enableDepthWrite();
	
	// DRAW PARTICLES
	mPositionFbos[mThisFbo].bindTexture( 0 );
	mVelocityFbos[mThisFbo].bindTexture( 1 );
	mShader.bind();
	mShader.uniform( "currentPosition", 0 );
	mShader.uniform( "currentVelocity", 1 );
	mShader.uniform( "eyePos", mSpringCam.getEye() );
	mShader.uniform( "power", mRoom.getPower() );
	gl::draw( mSphereVbo );
	mShader.unbind();
	
	if( mSaveFrames && mNumSavedFrames < 15000 ){
		writeImage( *getHomeDirectory().c_str() + "RepulsionGPU/" + toString( mNumSavedFrames ) + ".png", copyWindowSurface() );
		mNumSavedFrames ++;
	}
	
	mThisFbo	= ( mThisFbo + 1 ) % 2;
	mPrevFbo	= ( mThisFbo + 1 ) % 2;
}
Exemplo n.º 25
0
void PostProcessingApp::draw()
{
	// clear window
	gl::clear();

	// bind shader and set shader variables
	mShader.bind();
	mShader.uniform( "tex0", 0 );
	mShader.uniform( "time", (float)getElapsedSeconds() );

	// draw image or video
	gl::color( Color::white() );
	gl::draw( mImage, getWindowBounds() );

	// unbind shader
	mShader.unbind();
}
/* 
 * @Description: need to blur[the SSAO texture] horizonatally then vertically (for shader performance reasons). Called ping-ponging as it one FBO drawn to another
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::pingPongBlur()
{
	//render horizontal blue first
	gl::setViewport( mPingPongBlurH.getBounds() );
	
	mPingPongBlurH.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mPingPongBlurH.getSize() );
	
	mSSAOMap.getTexture().bind(0);
	mHBlurShader.bind();
	mHBlurShader.uniform("RTScene", 0);
    gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	mHBlurShader.unbind();
	mSSAOMap.getTexture().unbind(0);
	
	mPingPongBlurH.unbindFramebuffer();
	
	//gl::setViewport( getWindowBounds() ); //redundant
	
	//now render vertical blur
	gl::setViewport( mPingPongBlurV.getBounds() );
	
	mPingPongBlurV.bindFramebuffer();
	
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	gl::setMatricesWindow( mPingPongBlurV.getSize() );
	
	mPingPongBlurH.getTexture().bind(0);
	mHBlurShader.bind();
	mHBlurShader.uniform("RTBlurH", 0);
	gl::drawSolidRect( Rectf( 0, 0, getWindowWidth(), getWindowHeight()) );
	mHBlurShader.unbind();
	mPingPongBlurH.getTexture().unbind(0);
	
	mPingPongBlurV.unbindFramebuffer();
	
	gl::setViewport( getWindowBounds() );
}
Exemplo n.º 27
0
void gpuPSApp::draw()
{
    
    gl::setMatrices( mMayaCam.getCamera() );
    gl::setViewport( getWindowBounds() );
    gl::clear( Color::white() );
    
    mSwapFbo.bindTexture(0);
    mSwapFbo.bindTexture(1);
    mDisplacementShader.bind();
    mDisplacementShader.uniform("displacementMap", 0 );
    mDisplacementShader.uniform("velocityMap", 1);
    gl::draw( mVboMesh );
    mDisplacementShader.unbind();
    mSwapFbo.unbindTexture();
    
    gl::setMatricesWindow(getWindowSize());
    gl::drawString( toString( SIDE*SIDE ) + " vertices", Vec2f(32.0f, 32.0f));
    gl::drawString( toString((int) getAverageFps()) + " fps", Vec2f(32.0f, 52.0f));
}
Exemplo n.º 28
0
void gpuPSApp::update()
{
    if (mStep) {
        computeAttractorPosition();
        
        gl::setMatricesWindow( mSwapFbo.getSize(), false ); // false to prevent vertical flipping
        gl::setViewport( mSwapFbo.getBounds() );
        
        mSwapFbo.updateBind();
        
        mParticlesShader.bind();
        mParticlesShader.uniform( "positions", 0 );
        mParticlesShader.uniform( "velocities", 1 );
        mParticlesShader.uniform( "attractorPos", mAttractor);
        gl::drawSolidRect(mSwapFbo.getBounds());
        mParticlesShader.unbind();
        
        mSwapFbo.updateUnbind();
        mSwapFbo.swap();
    }
}
Exemplo n.º 29
0
void RepulsionApp::drawIntoPositionFbo()
{	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	mPositionFbos[ mThisFbo ].bindFramebuffer();
	mPositionFbos[ mPrevFbo ].bindTexture( 0, 0 );
	mPositionFbos[ mPrevFbo ].bindTexture( 1, 1 );
	mVelocityFbos[ mThisFbo ].bindTexture( 2, 0 );
	mVelocityFbos[ mThisFbo ].bindTexture( 3, 1 );	
	mPositionShader.bind();
	mPositionShader.uniform( "pos0Tex", 0 );
	mPositionShader.uniform( "pos1Tex", 1 );
	mPositionShader.uniform( "vel0Tex", 2 );
	mPositionShader.uniform( "vel1Tex", 3 );
	mPositionShader.uniform( "dt", mRoom.getTimeDelta() );
	gl::drawSolidRect( mFboBounds );
	mPositionShader.unbind();
	
	mPositionFbos[ mThisFbo ].unbindFramebuffer();
}
Exemplo n.º 30
0
void EpicMonsterApp::flockToBody() {
    if(timer.getSeconds() > mTimerSlower) {
        timer.stop();
        timer.start();
        
        gl::setMatricesWindow( mPPFbo.getSize(), false ); // false to prevent vertical flipping;
    
        mPPFbo.updateBind();
    
        mBakeShader.bind();
        mBakeShader.uniform( "positions", 0 );
        mBakeShader.uniform( "scale", mNormalScale );
        mBakeShader.uniform( "velocities", 1 );
        mBakeShader.uniform( "n", n);
        mBakeShader.uniform( "attractorPos", mAttractor);
        
        mBakeShader.uniform( "offset", Vec3f(mParTexOffset.x, mParTexOffset.y, mParIteration));
    
        
        glDisable(GL_CULL_FACE);
        mAssimpLoader.draw();
        mBakeShader.unbind();
    
        mPPFbo.updateUnbind();
        mPPFbo.swap();
        mParIteration+= triangles;
        if(mParIteration > (6*n.x*n.x))
            mParIteration = 0;
        // TODO: baketuksessa overflowaa tyylikkäästi takaisin alkuun, jos menee yli
    }

}