Really wierd lens flare problem

Hey people,

I just finished writing my lens flare class but I’m having a few problems with it. I do lens flare occulsion culling by simply reading in the depth buffer at the screen x,y coords of the sun to determine if the sun is blocked or not.The wierd part is that the lens flare still draws although my terrain is covering the sun,but it disappears when my gun gets infront of the sun.I can’t figure out why this is happening.The lens flare is the last thing that I’m rendering in my scene.

And another problem is,the lens flare draws infront of my character as well as BEHIND my caracter.I know there is a simple fix for this but I’m not sure what.Any suggestions?

Thanx for any help

Silly questions first… you definitely have depth-buffer writes enabled when rendering the terrain, right? I’ve seen a few (older) engines that didn’t zbuffer terrain, because it’s very easy to use Painter’s for a regular grid.

Not sure what you mean by the in front/behind character bit - can you elaborate?

Lens flares are crap. Special effects like this take way too much time and nobody cares.

Besides, you didn’t say anything specific. What’s wrong?

MikeC: Yes,I do have zbuffer enabled while rendering my terrain.ZBuffer is enabled throughout the whole rendering process.Yet I can only block out the lens flare using my gun and not my terrain.

As for my other problem,when I say that there is a lens flare effect infront of and behind the player, I mean just that.If my sun was at (0,0,-300) and I look at it,there is a lens flare effect.But,If I also look at (0,0,300) the effect is there as well. It’s like there are 2 suns.Not sure why this is happening.It prolly has something to do with the 2d drawing of the flares in ortho mode.

you should take the dotproduct between your view-direction and the you_to_sun_direction to determine the cosine of this angle. then you can fade directly with this value. that way you will have a full lenzy when you look directly into the sun, and the lenzy fades out when turning, and is away when looking backwards. then you don’t even have to draw it…

Heeeyyyy…you’re pretty smart!

Then use NV_Occlusion_query, to work out how many pixels of the actual sun get rendered, and fade on this too, for really cool “Halo-Sun-through-trees” effect.

I personally, dont use dot-product. I do my lens-flares in screen-space, and just interpolate the values from the centre of the screen. Manually project the position of the sun, and if Z is negative ignore, and if the X And Y are off screen ignore.