Exemple #1
0
void Scene::Render(ci::Surface8u *surface) {
	Surface8u::Iter iter = surface->getIter();
	int width = surface->getWidth();
	int height = surface->getHeight();
	float aspectRatio = width / (float)height;
	Color8u bgColor(25, 25, 25);
	while (iter.line()) {
		while (iter.pixel()) {
			ColorA aaColor(0, 0, 0);
			int count = 0;
			int numSamples = 4;
			float deltaX = 1.0f / (width * numSamples);
			float deltaY = 1.0f / (height * numSamples);

			for (int i = 0; i < numSamples; i++) {
				for (int j = 0; j < numSamples; j++) {
					float inDist = 10000.0f;
					float u = iter.x()/(float)width + deltaX * i;
					float v = iter.y()/(float)height + deltaY * j;
					ci::Ray ray = m_camera->generateRay(u, v, aspectRatio);
					aaColor += Raytrace(ray, 0, inDist, 1.0f);
					count++;
				}
			}

			ColorA color = aaColor / (float)count;

			iter.r() = ci::math<float>::clamp(bgColor.r * (1.0f - color.a) + color.r * 255.0f, 0.0f, 255.0f);
			iter.g() = ci::math<float>::clamp(bgColor.g * (1.0f - color.a) + color.g * 255.0f, 0.0f, 255.0f);
			iter.b() = ci::math<float>::clamp(bgColor.b * (1.0f - color.a) + color.b * 255.0f, 0.0f, 255.0f);
		}
		//iter.line();
	}
}
Exemple #2
0
void RayMarcher::render( ci::Surface8u *surface )
{
	Surface8u::Iter iter = surface->getIter();

	// transform the spheres

	int width = surface->getWidth();
	int height = surface->getHeight();
	float imageAspect = width / (float)height;
	Color8u backgroundColor( 0, 95, 249 );
	while( iter.line() ) {
		while( iter.pixel() ) {
			ColorA color = march( mCamera->generateRay( iter.x() / (float)width, 1.0f - iter.y() / (float)height, imageAspect ) );
			iter.r() = backgroundColor.r * ( 1.0f - color.a ) + color.r * 255;
			iter.g() = backgroundColor.g * ( 1.0f - color.a ) + color.g * 255;
			iter.b() = backgroundColor.b * ( 1.0f - color.a ) + color.b * 255;
		}
		iter.line();
	}	
}
void _TBOX_PREFIX_App::setup()
{
	mCubeRotation.setToIdentity();

	// Create a blue-green gradient as an OpenGL texture
	Surface8u surface( 256, 256, false );
	Surface8u::Iter iter = surface.getIter();
	while( iter.line() ) {
		while( iter.pixel() ) {
			iter.r() = 0;
			iter.g() = iter.x();
			iter.b() = iter.y();
		}
	}
	
	mTex = gl::Texture( surface );
}
Exemple #4
0
void RayMarcher::renderScanline( int scanline, ci::Surface8u *surface )
{
	int width = surface->getWidth();
	int height = surface->getHeight();
	float imageAspect = width / (float)height;
	Color8u backgroundColor( 0, 95, 249 );
	Surface8u::Iter iter = surface->getIter( Area( 0, scanline, surface->getWidth(), scanline + 1 ) );
	while( iter.pixel() ) {
		ColorA color = march( mCamera->generateRay( iter.x() / (float)width, 1.0f - scanline / (float)height, imageAspect ) );
		iter.r() = backgroundColor.r * ( 1.0f - color.a ) + color.r * 255;
		iter.g() = backgroundColor.g * ( 1.0f - color.a ) + color.g * 255;
		iter.b() = backgroundColor.b * ( 1.0f - color.a ) + color.b * 255;
	}
}
Exemple #5
0
Surface8u colorizeBodyIndex( const Channel8u& bodyIndexChannel )
{
    Surface8u surface;
    if ( bodyIndexChannel ) {
        surface = Surface8u( bodyIndexChannel.getWidth(), bodyIndexChannel.getHeight(), true, SurfaceChannelOrder::RGBA );
        Channel8u::ConstIter iterChannel	= bodyIndexChannel.getIter();
        Surface8u::Iter iterSurface			= surface.getIter();
        while ( iterChannel.line() && iterSurface.line() ) {
            while ( iterChannel.pixel() && iterSurface.pixel() ) {
                size_t index				= (size_t)iterChannel.v();
                ColorA8u color( getBodyColor( index ), 0xFF );
                if ( index == 0 || index > BODY_COUNT ) {
                    color.a					= 0x00;
                }
                iterSurface.r()				= color.r;
                iterSurface.g()				= color.g;
                iterSurface.b()				= color.b;
                iterSurface.a()				= color.a;
            }
        }
    }
    return surface;
}
Exemple #6
0
void ShapeContainer::update(Surface8u* _surf, int _tNow)
{
	Surface8u::Iter pixelIter = _surf->getIter();
    
    if (p_aniMode == NULL) return;
    
    AnimationMode           aniMode     = *p_aniMode;
    
    int                     interval    = *p_interval;
    float                   frontarea   = *p_frontarea;
    float                   backarea    = *p_backarea;
    
    float                   contrast    = *p_contrast;
    float                   afactor     = *p_alpha;
    
    bool                    showColour  = *p_showColour;

	// update!
	for( vector<Shape>::iterator shapeIt = m_shapes.begin(); shapeIt != m_shapes.end(); ++shapeIt) 
	{
        
        if (!shapeIt->m_isActive) 
            continue;

        vector<ColorA> faceColours;
        
        for (int i = 0; i < m_faceModes.size(); i++) {
            
            float alpha = 1.0f;
            float rc = 1.0f;
            float gc = 1.0f;
            float bc = 1.0f;
            
            if (aniMode == VIDEO || aniMode == VIDEO_RADAR)
            {
                rc = pixelIter.r()/255.f;
                gc = pixelIter.g()/255.f;
                bc = pixelIter.b()/255.f;
                
                alpha *= (rc + gc + bc) / 3.f;
            }
            
            if (aniMode == RADAR || aniMode == VIDEO_RADAR)
            {
                float progress = (_tNow%interval)/(float)interval;
                
                // to be sure, add twice area size
                float radarY = -max(backarea, frontarea) + progress*(14.f + max(backarea, frontarea)*2);
                
                float factor = 0;
                float diff = shapeIt->m_k - radarY;
                
                if (diff > 0)
                {
                    if(diff < frontarea) 
                        factor = 1 - diff/frontarea;
                }
                if (diff <= 0)
                {
                    if(diff > -backarea)
                        factor = 1 - diff/-backarea;
                }
                
                alpha *= factor;
            }
            
            if (!pixelIter.pixel()) {
                if(pixelIter.line())
                {
                    pixelIter.pixel(); // reset x to 0
                } else {
                    return;
                }
                
            }
            
            ColorA col = ColorA(0, 0, 0, 0);
            alpha = (alpha - .5f)*contrast + .5f;
            if(alpha < 0) alpha = 0;
            if(alpha > 1) alpha = 1;
            
            alpha *= afactor;
            
            
            switch (*m_faceModes[i]) {
                case ACTIVE:
                    col = (showColour) ? ColorA(rc, gc, bc, alpha) : ColorA( 1.0f, 1.0f, 1.0f, alpha);
                    break;
                case DICHROIC1:
                    col = ColorA(0.3f, 0.8f, 1.0f, .1f);
                    break;
                case DICHROIC2:
                    col = ColorA(1.0f, 0.8f, 0.3f, .1f);
                    break;
                case GLASS:
                    col = ColorA(1.0f, 1.0f, 1.0f, .015f);
                    break;
                case NONE:
                    col = ColorA(1.0f, 1.0f, 1.0f, 0.f);
                    break;
                default:
                    col = ColorA(1.0f, 1.0f, 1.0f, 0.f);
                    break;
            }
            faceColours.push_back(col);
            
        }
        
        shapeIt->updateFaces(faceColours);


	}
	
}
Exemple #7
0
void cApp::update(){

    if( !bStart ) return;
    
    parts.clear();
    vbo.resetAll();
    
    if(0){
        if(!mov){
            fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"mov"/"7.1_simu_5_c_linear_rect.mov";
            mov = qtime::MovieSurface::create( path );
            mov->seekToStart();
            mov->play();
        }
        mov->seekToFrame(frame);
        sur = mov->getSurface();
    }else{
        fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"img"/"simu_1"/"c"/"polar"/"linear"/"simu_1_idump100_c_linear_polar.png";
        //fs::path path = mt::getAssetPath()/"sim"/"supernova"/"2d"/"img"/"test.png";
        sur = Surface8u::create( loadImage(path) );
    }
    
    if(sur){
        frame++;

        Surface8u::Iter itr = sur->getIter();
        while (itr.line()) {
            while (itr.pixel()) {
                
                vec2 pos = itr.getPos();
                pos.x -= itr.getWidth()/2;
                pos.y -= itr.getHeight()/2;

                float val = itr.r()/255.0f;
                float min = 0.4f;
                float max = 0.99999f;
                if( min < val && val < max ){
                    float gray = lmap(val, min, max, 0.3f, 1.0f);
                    Particle pt;
                    pt.pos = vec3(pos.x, pos.y, gray*200.0f) + mPln.dfBm(frame*0.0001f, pos.x*0.001f, pos.y*0.001f)*0.3f;
                    pt.dist = glm::distance(eye, pt.pos);
                    pt.val = val;
                    
                    //pt.col = Colorf(gray,gray,gray);
                    pt.col = mt::getHeatmap( gray );
                    parts.push_back(pt);
                    
                    if(0){
                        for( int k=0; k<round(pt.pos.z); k+=5){
                            vec3 pp = pt.pos;
                            pp.z = k;
                            Particle pt;
                            pt.pos = pp + mPln.dfBm(frame*0.0001f, pos.x*0.001f, pos.y*0.001f)*0.3f;
                            pt.dist = glm::distance(eye, pp);
                            pt.val = val;
                            //pt.col = Colorf(gray,gray,gray);
                            pt.col = mt::getHeatmap( gray );
                            pt.col.a = k*0.01;
                            parts.push_back(pt);
                        }
                    }
                }
            }
        }
        
        std::sort(parts.begin(), parts.end(), [](const Particle&lp, const Particle&rp){ return lp.dist > rp.dist; } );
        
        for( int i=0; i<parts.size(); i++){
            vbo.addPos(parts[i].pos);
            vbo.addCol(parts[i].col);
        }
        vbo.init(GL_POINTS);
    }
}