Hi
I’m doing some flare rendering, using the following code snippet. Everything works fine, except that i get flare in both directions: when i’m facing the light, and when i’m backing the light. I’d like to have the effect only in the light direction, and i’ve tried to look where the error is but unfortunately i haven’t found yet. Any help would be welcome
regards
Nicolas
float sunx,suny,sunz; //light coord
GLdouble modelMatrix[16]; // model matrix.
GLdouble projMatrix[16]; // projection matrix.
GLdouble sx,sy,sz; // light screen coord
float brightness=0; //brightness factor
float depth; //depth
GLint viewport[4]; // viewport.
//compute the screen coord glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); glGetIntegerv(GL_VIEWPORT, viewport); gluProject(sunx,suny,sunz,modelMatrix,projMatrix,viewport,&sx,&sy,&sz); // Find out where the light is on the screen. (sz>1.0)?sz=1.0:sz=sz;//clamp the depth light for(int x=-4;x<=4;x++) // look around the light for(int y=-4;y<=4;y++){ if(viewport[2]/300.0*x+sx < viewport[2] && viewport[2]/300.0*x+sx >= 0 && viewport[3]/300.0*y+sy < viewport[3] && viewport[3]/300.0*y+sy >= 0 ) // If the point is on the screen { glReadPixels( (int)(viewport[2]/300.0*x+sx), (int)(viewport[3]/300.0*y+sy), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth); // read the depth component. if(depth >= sz) brightness += 0.009; // If there is nothing in front of the point, increase brightness } } //clamp sx and sy on [-1,1] sx = sx/(float)viewport[2]*2.0-1.0; sy = sy/(float)viewport[3]*2.0-1.0; //finally, draw a halo, of flares
[This message has been edited by uruloki (edited 07-02-2003).]
[This message has been edited by uruloki (edited 07-02-2003).]