void randomSamplePointsInHemisphere( const vec3& normal, float angle, size_t n, vec3* out, random& seed ) { assert( angle > 0.f && angle <= radians(90.f) ); assert( n > 0 ); assert( check(normal) ); randomSamplePointsOnHemisphere( normal, angle, n, out, seed ); // randomize lengths according to volume distribution (plain *=randomFloat() would put more weight on center) for ( size_t i = 0 ; i < n ; ++i ) out[i] *= length( randomPointInSphere(seed) ); }
void ccSSAOFilter::initReflectTexture() { /*** INIT TEXTURE OF RELFECT VECTORS ***/ /** Fully random texture **/ int texSize = w*h; std::vector<float> reflectTex; try { reflectTex.resize(3*texSize); } catch(std::bad_alloc) { //not enough memory return; } for (int i=0; i<texSize; i++) { double x,y,z; randomPointInSphere(x,y,z); double norm = x*x+y*y+z*z; norm = (norm > 1.0e-12 ? 1.0/sqrt(norm) : 0.0); reflectTex[i*3 ] = static_cast<float>((1.0+x*norm)/2); reflectTex[i*3+1] = static_cast<float>((1.0+y*norm)/2); reflectTex[i*3+2] = static_cast<float>((1.0+z*norm)/2); } glEnable(GL_TEXTURE_2D); if (glIsTexture(texReflect)) glDeleteTextures(1,&texReflect); glGenTextures(1,&texReflect); glBindTexture(GL_TEXTURE_2D,texReflect); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F,w,h,0,GL_RGB,GL_FLOAT,&reflectTex[0]); glDisable(GL_TEXTURE_2D); // According to Wikipedia, noise is made of 4*4 repeated tiles to have only high frequency **/ }
void ccSSAOFilter::initReflectTexture() { /*** INIT TEXTURE OF RELFECT VECTORS ***/ /** Fully random texture **/ int size = w*h; float* p_reflect = new float[3*size]; if (!p_reflect) { //not enough memory! return; } float* _p_reflect = p_reflect; double x,y,z,norm; for (int i=0;i<size;i++) { randomPointInSphere(x,y,z); norm = x*x+y*y+z*z; norm = (norm > 1e-12 ? 1.0/sqrt(norm) : 0.0); *(_p_reflect++) = (float)(0.5*(1.0+x*norm)); *(_p_reflect++) = (float)(0.5*(1.0+y*norm)); *(_p_reflect++) = (float)(0.5*(1.0+z*norm)); } TEX_2D_ON; if (glIsTexture(texReflect)) glDeleteTextures(1,&texReflect); glGenTextures(1,&texReflect); glBindTexture(GL_TEXTURE_2D,texReflect); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F,w,h,0,GL_RGB,GL_FLOAT,p_reflect); TEX_2D_OFF; delete[] p_reflect; // According to Wikipedia, noise is made of 4*4 repeated tiles to have only high frequency **/ }
void CloudsVisualSystemBalloons::setBalloonPositions() { creditStartTime = ofGetElapsedTimef(); balloonFramStartTime = creditStartTime + 4; balloonFramEndTime = balloonFramStartTime + 6; vector<ofVec3f>pos(dimY*dimX); vector<ofVec3f>vel(dimY*dimX); if(releaseType == 0) { //sphere volume for (int i=0; i<dimY; i++) { for(int j=0; j<dimX; j++) { pos[i*dimX + j] = randomPointInSphere(spawnRad, ofVec3f(0,-spawnRad, 0) ); } } pos[0].y = -spawnRad; } else if(releaseType == 1) { for (int i=0; i<dimY; i++) { for(int j=0; j<dimX; j++) { //PLANE pos[i*dimX + j].set( j - dimY*.5, -10, i - dimY*.5); pos[i*dimX + j] *= radius * .5; } } } //cos else if(releaseType == 2) { float iStep = TWO_PI / dimY; float jStep = TWO_PI / dimX; for (int i=0; i<dimY; i++) { for(int j=0; j<dimX; j++) { pos[i*dimX + j].set( j - dimY*.5, -10 + cos(j * jStep) * cos(i * iStep) * 30, i - dimY*.5); pos[i*dimX + j] *= radius; } } } //Bulge else if(releaseType == 3) { float iStep = PI / dimY; float jStep = PI / dimX; for (int i=0; i<dimY; i++) { for(int j=0; j<dimX; j++) { pos[i*dimX + j].set( j - dimY*.5, sin(j * jStep) * sin(i * iStep), i - dimY*.5); pos[i*dimX + j].x *= radius; pos[i*dimX + j].y *= dim * .5; pos[i*dimX + j].y -= dim * .75; pos[i*dimX + j].z *= radius; } } random_shuffle( pos.begin(), pos.end() ); swap(pos[0], pos[pos.size()/2]); } for(int i=0; i<vel.size(); i++) { // vel[i].set(0,ofRandom(-1.5, 3),0); vel[i].set(0,ofRandom(0, 1),0); } //store data //posiiton posFbo0.allocate(dimX, dimY, GL_RGB32F); posFbo0.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); posFbo0.getTextureReference().loadData( &pos[0][0], dimX, dimY, GL_RGB); posFbo1.allocate(dimX, dimY, GL_RGB32F); posFbo1.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); posFbo1.getTextureReference().loadData( &pos[0][0], dimX, dimY, GL_RGB); //velocity velFbo0.allocate(dimX, dimY, GL_RGB32F); velFbo0.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); velFbo0.getTextureReference().loadData( &vel[0][0], dimX, dimY, GL_RGB); velFbo1.allocate(dimX, dimY, GL_RGB32F); velFbo1.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); velFbo1.getTextureReference().loadData( &vel[0][0], dimX, dimY, GL_RGB); //rotations quatFbo.allocate(dimX, dimY, GL_RGBA32F); quatFbo.getTextureReference().setTextureMinMagFilter(GL_NEAREST, GL_NEAREST); //color setBalloonColors(); }