Example #1
0
void gpuPSApp::setupTextures(){
	// Position 2D texture array
	mInitPos = Surface32f( SIDE, SIDE, true);
	Surface32f::Iter pixelIter = mInitPos.getIter();
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			/* Initial particle positions are passed in as R,G,B 
			 float values. Alpha is used as particle mass. */
			mInitPos.setPixel( pixelIter.getPos(), ColorAf( Rand::randFloat()-0.5f, Rand::randFloat()-0.5f, Rand::randFloat()-0.5f, Rand::randFloat(0.2f, 1.0f) ) );
		}
	}
	gl::Texture::Format tFormat;
	tFormat.setInternalFormat(GL_RGBA32F_ARB);
	mPositions = gl::Texture( mInitPos, tFormat);
	mPositions.setWrap( GL_REPEAT, GL_REPEAT );
	mPositions.setMinFilter( GL_NEAREST );
	mPositions.setMagFilter( GL_NEAREST );
	
	//Velocity 2D texture array
	mInitVel = Surface32f( SIDE, SIDE, true);
	pixelIter = mInitVel.getIter();
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			/* Initial particle velocities are
			 passed in as R,G,B float values. */
			mInitVel.setPixel( pixelIter.getPos(), ColorAf( 0.0f, 0.0f, 0.0f, 1.0f ) );
		}
	}
	mVelocities = gl::Texture( mInitVel, tFormat);
	mVelocities.setWrap( GL_REPEAT, GL_REPEAT );
	mVelocities.setMinFilter( GL_NEAREST );
	mVelocities.setMagFilter( GL_NEAREST );
}
Example #2
0
void CatalogApp::setFboPositions( gl::Fbo &fbo )
{
	int numBrightStars = mBrightStars.size();

	int index = 0;
	
	Surface32f posSurface( fbo.getTexture() );
	Surface32f::Iter it = posSurface.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f pos = Vec3f( 1000000.0f, 0.0f, 0.0f );
			float col = 0.4f;
			float rad = 0.0f;
			if( index < numBrightStars ){
				pos = mBrightStars[index]->mPos;
				col = mBrightStars[index]->mColor;
				rad = floor( constrain( ( ( 6.0f - ( mBrightStars[index]->mAbsoluteMag ) )/6.0f ), 0.3f, 1.0f ) * 3.0f * 1000 );
			}
			it.r() = pos.x;
			it.g() = pos.y;
			it.b() = pos.z;
			it.a() = rad + col;

			index ++;
		}
	}

	gl::Texture posTexture( posSurface );
	fbo.bindFramebuffer();
	gl::setMatricesWindow( fbo.getSize(), false );
	gl::setViewport( fbo.getBounds() );
	gl::clear( ColorA( 0, 0, 0, 0 ), true );
	gl::draw( posTexture );
	fbo.unbindFramebuffer();
}
void EpicMonsterApp::setupPingPongFbo()
{
    float scale = 8.0f;
    // TODO: Test with more than 2 texture attachments
    Surface32f surfaces[2];
    // Position 2D texture array
    surfaces[0] = Surface32f( SIDE, SIDE, true);
    Surface32f::Iter pixelIter = surfaces[0].getIter();
    while( pixelIter.line() ) {
        while( pixelIter.pixel() ) {
            /* Initial particle positions are passed in as R,G,B
             float values. Alpha is used as particle invMass. */
            surfaces[0].setPixel(pixelIter.getPos(),
                                 ColorAf(scale*(Rand::randFloat()-0.5f),
                                         scale*(Rand::randFloat()-0.5f),
                                         scale*(Rand::randFloat()-0.5f),
                                         Rand::randFloat(0.2f, 1.0f) ) );
        }
    }
    
    //Velocity 2D texture array
    surfaces[1] = Surface32f( SIDE, SIDE, true);
    pixelIter = surfaces[1].getIter();
    while( pixelIter.line() ) {
        while( pixelIter.pixel() ) {
            /* Initial particle velocities are
             passed in as R,G,B float values. */
            surfaces[1].setPixel( pixelIter.getPos(), ColorAf( 0.0f, 0.0f, 0.0f, 1.0f ) );
        }
    }
    mPPFbo = PingPongFbo(surfaces);
}
Example #4
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 PointCloudApp::update()
{
	mFrameRate = getAverageFps();
	
	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
		mFullScreen = isFullScreen();
	}

	if ( !mSurfaceDepthToCameraTable ) {
		mSurfaceDepthToCameraTable = mDevice->mapDepthToCameraTable();
	}

	if ( ( mTimeStamp != mTimeStampPrev ) && mSurfaceColor && mChannelDepth ) {
		mTimeStampPrev = mTimeStamp;

		mSurfaceDepthToColorTable	= Surface32f::create( mChannelDepth->getWidth(), mChannelDepth->getHeight(), false, SurfaceChannelOrder::RGB );
		vector<ivec2> positions		= mDevice->mapDepthToColor( mChannelDepth );

		vec2 sz( Kinect2::ColorFrame().getSize() );

		Surface32f::Iter iter		= mSurfaceDepthToColorTable->getIter();
		vector<ivec2>::iterator v	= positions.begin();
		while ( iter.line() ) {
			while ( iter.pixel() ) {
				iter.r() = (float)v->x / sz.x;
				iter.g() = 1.0f - (float)v->y / sz.y;
				iter.b() = 0.0f;
				++v;
			}
		}
	}
}
Example #6
0
Surface32f mapDepthFrameToBody( const ci::Channel16u& depth, ICoordinateMapper* mapper )
{
    size_t numPoints = depth.getWidth() * depth.getHeight();
    Surface32f surface( depth.getWidth(), depth.getHeight(), false /* no alpha */, SurfaceChannelOrder::RGB );
    vector<CameraSpacePoint> cameraSpacePoints( numPoints );
    long hr = mapper->MapDepthFrameToCameraSpace( (UINT)numPoints, depth.getData(), numPoints, &cameraSpacePoints[0] );
    if ( SUCCEEDED( hr ) ) {
        Surface32f::Iter iter = surface.getIter();
        while ( iter.line() ) {
            while ( iter.pixel() ) {
                size_t i = iter.getPos().y * iter.getWidth() + iter.getPos().x;
                CameraSpacePoint &p = cameraSpacePoints[i];
                iter.r() = p.X;
                iter.g() = p.Y;
                iter.b() = p.Z;
            }
        }
    }
    return surface;
}
void ImageHFApp::updateData( ImageHFApp::ColorSwitch whichColor )
{
	Surface32f::Iter pixelIter = mImage.getIter();
	auto vertPosIter = mVboMesh->mapAttrib3f( geom::POSITION );
	auto vertColorIter = mVboMesh->mapAttrib3f( geom::COLOR );

	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height;
			const float muteColor = 0.2f;

			// calculate the height based on a weighted average of the RGB, and emphasize either the red green or blue color in each of those modes
			switch( whichColor ) {
				case kColor:
					height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );
				break;
				case kRed:
					height = color.dot( Color( 1, 0, 0 ) );
					color *= Color( 1, muteColor, muteColor );
				break;
				case kGreen:
					height = color.dot( Color( 0, 1, 0 ) );
					color *= Color( muteColor, 1, muteColor );
				break;
				case kBlue:
					height = color.dot( Color( 0, 0, 1 ) );
					color *= Color( muteColor, muteColor, 1 );					
				break;            
			}

			// the x and the z coordinates correspond to the pixel's x & y
			float x = pixelIter.x() - mWidth / 2.0f;
			float z = pixelIter.y() - mHeight / 2.0f;

			*vertPosIter++ = vec3( x, height * 30.0f, z );
			*vertColorIter++ = vec3( color.r, color.g, color.b );
		}
	}

	vertPosIter.unmap();
	vertColorIter.unmap();
}
Example #8
0
void RepulsionApp::setFboPositions( gl::Fbo &fbo )
{
	Surface32f pos( fbo.getTexture() );
	Surface32f::Iter it = pos.getIter();
	while( it.line() ){
		while( it.pixel() ){
			Vec3f r = mRoom.getRandRoomPos();
			float mass = Rand::randFloat( 20.0f, 30.0f );
			if( Rand::randFloat() < 0.05f ) 
				mass = Rand::randFloat( 50.0f, 60.0f );
			
			if( it.y() < 5  && it.x() < 50 )
				mass = Rand::randFloat( 300.0f, 5000.0f );
			else
				mass = Rand::randFloat( 50.0f, 300.0f );
			
			it.r() = r.x;
			it.g() = r.y;
			it.b() = r.z;
			it.a() = 100.0f;
		}
	}
	
	gl::Texture posTexture( pos );
	posTexture.bind();
	
	gl::setMatricesWindow( mFboSize, false );
	gl::setViewport( mFboBounds );
	
	fbo.bindFramebuffer();
	mPosInitShader.bind();
	mPosInitShader.uniform( "initTex", 0 );
	gl::drawSolidRect( mFboBounds );
	mPosInitShader.unbind();
	fbo.unbindFramebuffer();
}
Example #9
0
void BasicApp::updateData( BasicApp::ColorSwitch whichColor )
{
	Surface32f::Iter pixelIter = mImage.getIter();
	dx::VboMesh::VertexIter vertexIter( mVboMesh );

	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height;
			const float muteColor = 0.2f;

			// calculate the height based on a weighted average of the RGB, and emphasize either the red green or blue color in each of those modes
			switch( whichColor ) {
				case kColor:
					height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );
				break;
				case kRed:
					height = color.dot( Color( 1, 0, 0 ) );
					color *= Color( 1, muteColor, muteColor );
				break;
				case kGreen:
					height = color.dot( Color( 0, 1, 0 ) );
					color *= Color( muteColor, 1, muteColor );
				break;
				case kBlue:
					height = color.dot( Color( 0, 0, 1 ) );
					color *= Color( muteColor, muteColor, 1 );					
				break;            
			}

			// the x and the z coordinates correspond to the pixel's x & y
			float x = pixelIter.x() - mWidth / 2.0f;
			float z = pixelIter.y() - mHeight / 2.0f;

            vertexIter.setPosition( x, height * 60.0f, z );
			vertexIter.setColorRGB( color );
			++vertexIter;
		}
	}
}
Example #10
0
void triMeshApp::updateData()
{
	Surface32f::Iter pixelIter = m_hfImage.getIter();
	gl::VboMesh::VertexIter vertexIter( mVBOHeightfield );
	
	while( pixelIter.line() ) {
		while( pixelIter.pixel() ) {
			Color color( pixelIter.r(), pixelIter.g(), pixelIter.b() );
			float height;

			height = color.dot( Color( 0.3333f, 0.3333f, 0.3333f ) );
         

			// the x and the z coordinates correspond to the pixel's x & y
			float x = (pixelIter.x() - m_hfImage.getWidth() / 2.0f);
			float z = (pixelIter.y() - m_hfImage.getHeight() / 2.0f);
			
            vertexIter.setPosition( x * HF_SCALE, height * HF_SCALEY, z * HF_SCALE);
			vertexIter.setColorRGB( color );
			++vertexIter;
		}
	}
}
void millionParticlesApp::setup()
{
    gl::clear();

    try {
        mPosShader = gl::GlslProg(ci::app::loadResource(POS_VS),ci::app::loadResource(POS_FS));
        mVelShader = gl::GlslProg(ci::app::loadResource(VEL_VS),ci::app::loadResource(VEL_FS));
    }
    catch( gl::GlslProgCompileExc &exc ) {
        std::cout << "Shader compile error: " << std::endl;
        std::cout << exc.what();
    }
    catch( ... ) {
        std::cout << "Unable to load shader" << std::endl;
    }

    //controls
    mDrawTextures = false;
    mIsFullScreen = false;

    mFrameCounter = 0;

    mPerlin = Perlin(32,clock() * .1f);

    //initialize buffer
    Surface32f mPosSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mVelSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mInfoSurface = Surface32f(PARTICLES,PARTICLES,true);
    Surface32f mNoiseSurface = Surface32f(PARTICLES,PARTICLES,true);

    Surface32f::Iter iterator = mPosSurface.getIter();


    while(iterator.line())
    {
        while(iterator.pixel())
        {

            mVertPos = Vec3f(Rand::randFloat(getWindowWidth()) / (float)getWindowWidth(),
                             Rand::randFloat(getWindowHeight()) / (float)getWindowHeight(),0.0f);

            //velocity
            Vec2f vel = Vec2f(Rand::randFloat(-.005f,.005f),Rand::randFloat(-.005f,.005f));

            float nX = iterator.x() * 0.005f;
            float nY = iterator.y() * 0.005f;
            float nZ = app::getElapsedSeconds() * 0.1f;
            Vec3f v( nX, nY, nZ );
            float noise = mPerlin.fBm( v );

            float angle = noise * 15.0f ;

            //vel = Vec3f( cos( angle ) * 6.28f, cos( angle ) * 6.28f, 0.0f );

            //noise
            mNoiseSurface.setPixel(iterator.getPos(),
                                   Color( cos( angle ) * Rand::randFloat(.00005f,.0002f), sin( angle ) * Rand::randFloat(.00005f,.0002f), 0.0f ));

            //position + mass
            mPosSurface.setPixel(iterator.getPos(),
                                 ColorA(mVertPos.x,mVertPos.y,mVertPos.z,
                                        Rand::randFloat(.00005f,.0002f)));
            //forces + decay
            mVelSurface.setPixel(iterator.getPos(), Color(vel.x,vel.y, Rand::randFloat(.01f,1.00f)));

            //particle age
            mInfoSurface.setPixel(iterator.getPos(),
                                  ColorA(Rand::randFloat(.007f,1.0f), 1.0f,0.00f,1.00f));

        }
    }

    //gl texture settings
    gl::Texture::Format tFormat;
    tFormat.setInternalFormat(GL_RGBA16F_ARB);

    gl::Texture::Format tFormatSmall;
    tFormat.setInternalFormat(GL_RGBA8);

    mSpriteTex = gl::Texture( loadImage( loadResource( "point.png" ) ), tFormatSmall);


    mNoiseTex = gl::Texture(mNoiseSurface, tFormatSmall);
    mNoiseTex.setWrap( GL_REPEAT, GL_REPEAT );
    mNoiseTex.setMinFilter( GL_NEAREST );
    mNoiseTex.setMagFilter( GL_NEAREST );

    mPosTex = gl::Texture(mPosSurface, tFormat);
    mPosTex.setWrap( GL_REPEAT, GL_REPEAT );
    mPosTex.setMinFilter( GL_NEAREST );
    mPosTex.setMagFilter( GL_NEAREST );

    mVelTex = gl::Texture(mVelSurface, tFormat);
    mVelTex.setWrap( GL_REPEAT, GL_REPEAT );
    mVelTex.setMinFilter( GL_NEAREST );
    mVelTex.setMagFilter( GL_NEAREST );

    mInfoTex = gl::Texture(mInfoSurface, tFormatSmall);
    mInfoTex.setWrap( GL_REPEAT, GL_REPEAT );
    mInfoTex.setMinFilter( GL_NEAREST );
    mInfoTex.setMagFilter( GL_NEAREST );

    //initialize fbo
    gl::Fbo::Format format;
    format.enableDepthBuffer(false);
    format.enableColorBuffer(true, 3);
    format.setMinFilter( GL_NEAREST );
    format.setMagFilter( GL_NEAREST );
    format.setWrap(GL_CLAMP,GL_CLAMP);
    format.setColorInternalFormat( GL_RGBA16F_ARB );

    mFbo[0] = gl::Fbo(PARTICLES,PARTICLES, format);
    mFbo[1] = gl::Fbo(PARTICLES,PARTICLES, format);

    initFBO();

    //fill dummy fbo
    vector<Vec2f> texCoords;
    vector<Vec3f> vertCoords, normCoords;
    vector<uint32_t> indices;

    gl::VboMesh::Layout layout;
    layout.setStaticIndices();
    layout.setStaticPositions();
    layout.setStaticTexCoords2d();
    layout.setStaticNormals();

    mVbo = gl::VboMesh(PARTICLES*PARTICLES,PARTICLES*PARTICLES,layout,GL_POINTS);

    for (int x = 0; x < PARTICLES; ++x) {
        for (int y = 0; y < PARTICLES; ++y) {
            indices.push_back( x * PARTICLES + y);
            texCoords.push_back( Vec2f( x/(float)PARTICLES, y/(float)PARTICLES));
        }
    }

    mVbo.bufferIndices(indices);
    mVbo.bufferTexCoords2d(0, texCoords);

}
Example #12
0
void cApp::setup(){
    
    setWindowPos( 0, 0 );
    setWindowSize( 1080*3*0.5, 1920*0.5 );
    mExp.setup( 1080*3, 1920, 3000, GL_RGB, mt::getRenderPath(), 0);
    
    CameraPersp cam(1080*3, 1920, 54.4f, 0.1, 10000 );
    cam.lookAt( Vec3f(0,0, 1600), Vec3f(0,0,0) );
    cam.setCenterOfInterestPoint( Vec3f(0,0,0) );
    camUi.setCurrentCam( cam );
    
    mPln.setSeed(123);
    mPln.setOctaves(4);
    
    fs::path assetPath = mt::getAssetPath();
    
    {
        // make VectorMap
        Surface32f sAspect( loadImage(assetPath/("img/00/halpha3000_aspect_32bit.tif")) );
        Surface32f sSlope( loadImage(assetPath/("img/00/halpha3000_slope1.tif")) );

        int w = sAspect.getWidth();
        int h = sAspect.getHeight();
        
        mVecMap.assign(w, vector<Vec2f>(h) );

        for( int i=0; i<sAspect.getWidth(); i++) {
            for( int j=0; j<sAspect.getHeight(); j++ ) {
                
                Vec2i pos(i, j);
                float aspect = *sAspect.getDataRed( pos );
                float slope = *sSlope.getDataRed( pos );
                if( slope!=0 && aspect!=-9999 ){

                    Vec2f vel( 0, slope*10.0 );
                    vel.rotate( toRadians(aspect) );
                    mVecMap[i][j] = vel;
                }else{
                    mVecMap[i][j] = Vec2f::zero();
                }
                
                mVelocity.push_back( Vec3f(mVecMap[i][j].x, mVecMap[i][j].y, 0) );
            }
        }
    }
    
    {
        // make point from intensity
        Surface32f sIntensity( loadImage(assetPath/("img/00/halpha3000-skv3264879915580.tiff")) );
        intensityW = sIntensity.getWidth();
        intensityH = sIntensity.getHeight();
        
        Surface32f::Iter itr = sIntensity.getIter();
        float threashold = 0.15;
        float extrusion = 300;
        while ( itr.line() ) {
            while( itr.pixel() ){
                float gray = itr.r();
                if( threashold < gray ){
                    Vec2i pos = itr.getPos();
                    Vec3f v(pos.x, pos.y, gray*extrusion );
                    Vec3f noise = mPln.dfBm( Vec3f(pos.x, pos.y, gray) ) * 2.0;
                    ps.push_back( v + noise );
                    float c = gray + 0.2f;
                    float a = lmap(c, 0.0f, 1.0f, 0.3f, 0.7f);
                    cs.push_back( ColorAf(c, c, c, a) );
                }
            }
        }
        
        
        mPoints = gl::VboMesh( ps.size(), 0, mt::getVboLayout(), GL_POINTS );
        gl::VboMesh::VertexIter vitr( mPoints );
        for(int i=0; i<ps.size(); i++ ){
            vitr.setPosition( ps[i] );
            vitr.setColorRGBA( cs[i] );

            ++vitr;
        }
    }
    
    
    mExp.startRender();
    bStart = true;
    
}