PDA

View Full Version : problem with flares and halos



uruloki
07-01-2003, 11:54 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
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,v iewport,&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]
&amp;&amp; viewport[2]/300.0*x+sx >= 0
&amp;&amp; viewport[3]/300.0*y+sy < viewport[3]
&amp;&amp; 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,
&amp;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).]

Relic
07-02-2003, 12:46 AM
What's the return value of gluProject in case the sun is behind you?
If the point is behind the viewer the intermediate w-coordinate before screen projection must be negative. Sounds like gluProject always projects, but it should indicate that situation. (Not tried myself.)

uruloki
07-02-2003, 03:17 AM
gluProject always returns GL_TRUE, i guess that's because there is no failure. I really don't really how i could get the w coordinate. Should i make the projection myself, without using gluProject?

Relic
07-02-2003, 03:55 AM
I would give it a try.
You could also do some quick check with
DotProduct(view_direction, Normalize(light_position - eye_position));
If it's in front of you the sign is positive.

uruloki
07-02-2003, 04:13 AM
I'll try the dot product approach.
Is the normalize necessary, since i'm only interested by the sign of the dot product?
About the view_direction vector, its coordinates are (m[2] -m[6] -m[10]),right?
(m is the modelview matrix)

uruloki
07-02-2003, 05:01 AM
ok, it works perfectly with the dot product.
for now i keep it simple, that is i check the sign of dotproduct(view_dir,sun_pos). it works because sun_pos>>> observ_pos

well thank you very much for your help

regards

Relic
07-02-2003, 06:12 AM
If you use normalized vectors the result is the cosine of the angle between the vectors and you can optimize the check to consider only angles in the field of view by having a gross cone clip around your frustum with that.