Game Development Community

Lens Flares: Claculating and rendering.

by Paul Robertson · in Technical Issues · 09/09/2001 (5:35 pm) · 6 replies

I was wondering exactly how are lens flares calculated. I know it has something to do with the angle of the light source in relationship to the direction the camera\player's view is facing, but what's the math involved? Also, how are they displayed? Is it a 2d system of over-lays or what?

I'm also looking for info regarding light-source glare.

Thanks in advance for any help.

#1
09/09/2001 (10:04 pm)
Ok, what you'll want to do is cast a ray from the sun to the head of the player. This would be a vector, we'll call it vector L. The player has a view heading vector, which we'll call vector H, and a view pitch vector we'll call vector P. (Simulate this by turning your head, not your body right, left, up, down) Now take the dot product of L and H. Then take the dot product of L and P. If either of those are less then the players FOV angle, then the player has the sun in his FOV, and you'll want to do some glare effects. As for a lens flare, they are billboards visable only to the player, I would render it as a hud object actually...hey that's a good idea...maybe I'll make one of those...anyway, now that you have the angle that the ray from the sun is from the center of the players face, project that line into 2d space, then you can place the billboards that contain the lens flair graphics on that line, and you have a lens flair =)

(It's kind of late, and I'm supposed to be typing a lit paper, so if that didn't make sense, I'll try to elaborate)
#2
09/10/2001 (1:18 am)
One thing to remember with Lenzflare is this.

Although they are meant to create a realistic feel to the game they often tend to do the opposite.

Lenzflare is the result of a light source passing through multibel lenzes of a camera, the curve and thichness of each lenz giving each lenz a different shape and color. These could be round or 5- or 6-sided etc....

If manufatores of lenzes could get rid of these "realistic" lenzflares they would.

The human eye on the other hand don't have this flaw and do NOT have lenzflares.

SO if you are making a FPS where you look through the persons eyes, lenzflares will NOT be realistic at all.

If you however made a racing game and added lenzflare to the replay option making it look like camera footage it would look realistic.

My point is that Lenzflare is only something we see on television and in movies and are instantly recognizable which will make most people think "Wow, this game is so realistic" when infact it isn't.
But we do not see them in real life.

It's kinda sad that people think movies are more realistic that real life.

// Clocks out.
#3
09/10/2001 (2:48 am)
Thanks for the info Pat, that's exactly what I was needing to know.

Those are things I've already considered Karsten. They're good points though. I'm not sure to what extent we'll impliment lens flares for our first game yet.
#4
09/10/2001 (2:12 pm)
Even though lens flares is an artifact of lenses and doesn't happen with normal human vision, you have to take into account the fact that we're all (well, probably all of us) are looking through a monitor to read this board/play games/etc etc... So in a way it's like you're viewing the world through a lens (why else would there be so many invisible cameras in games ;p) Plus a lot of people actually like the way lens flares work and can inspire a sense of awe in your scene (like a lens flare when the sun peeks out from behind a dark planet in space, a lens flare would be perfect). If you're going for a realistic reason, a lens flare could be used to simulate pupil dialation almost. If you sit in a pitch black room for a few minutes then go out into the sun, everything will seem brighter because your eyes are letting in more light. The lens flare would be the extra brightness... you could make it fade to pure alpha if you wanted to over time.

They're easy to add really, and they look good. What other reason is there to put stuff in video games? =)

-nohbdy
#5
09/10/2001 (3:29 pm)
"If you sit in a pitch black room for a few minutes then go out into the sun, everything will seem brighter because your eyes are letting in more light. The lens flare would be the extra brightness... you could make it fade to pure alpha if you wanted to over time."

That's actually why I was asking about glare (thanks again Pat! You saved me some headaches :). My own personal plans are to use lens flares only in "from the camera" scenes. Glare will apply to both player POV and camera POV though.

My plan may get thrown out in favor of "popular opinion" once our first demo hits the testing crew though. I may just take the time to make it a menu controlable option :)
#6
09/10/2001 (4:24 pm)
If you put it in, just make it easy to disable it =)