PDA

View Full Version : Lens flare-- SIMPLE Lens flare


Raptisoft
01-11-2006, 12:28 PM
Hey, can someone explain to me how to do a really simple lens flare? Like, how the flare is supposed to move? I know you use like four circles, a starburst, two triangles, and a smiley face and move them in a certain way and poof, it looks like a lens flare... but I'd like to know the actual theory of why things move the way they do.

And BTW, the DirectX lens flare example is horribly lame. It looks like a lens flare in the land of the LSD mushroom eaters.

Robert Cummings
01-11-2006, 01:05 PM
The flare will move opposite your sun image. Each consecutive flare image is divided or multiplied by a fudge number so that when the sun image is in the middle of the screen, so are all the flares.

Flare x = res - sun x for example.

Savant
01-11-2006, 01:48 PM
This was the article that made it clear for me:

Click (http://www.opengl.org/resources/features/KilgardTechniques/LensFlare/)

The code is pretty simplistic once you realize what's going on, visually.

Edit: Actually, I guess that wasn't the article. Sorry...

illume
01-11-2006, 04:00 PM
...land of the LSD mushroom eaters.

What a great game idea!

Edit: oh, it's already been done in nintendo games.

Sharkbait
01-12-2006, 01:17 AM
I'm sure there must be an accurate theoretical model for lens flares but I don't think anyone bothers trying to model it accurately. You know how it goes in game dev.. cutting corners is the order of the day as long as it looks realistic enough to the player.

So the basic idea is to find the screen co-ordinates for the light source in question, say, the sun, and determine a straight line running through the light source co-ordinates, the centre of the screen, and up to a point opposite the light source co-ordinates. The lens flares can then be additively blended as quads facing the camera onto the scene at regular intervals on this line. The flares could optionally be scaled up closer to the centre of the screen so they appear to swell up and down as you sweep the camera past the light source.

There's a decent tutorial here:
http://www.gamedev.net/reference/articles/article813.asp

soniCron
01-12-2006, 01:29 AM
The flares could optionally be scaled up closer to the centre of the screen so they appear to swell up and down as you sweep the camera past the light source. Not that it matters, but: That is not an accurate phenomenon. ;) Though the flares closer to the light source will be smaller than those further away, the flares do not change size as their position changes. (And incidentally, are in ROYGBIV color order, from in to out, and in the shape of the aperture.) In addition, the halo (glow) around the source itself will grow the closer it is to the center of the screen. You can also brighten the whole image the closer source is to center for dramatic effect. Oh, and the spacing is not regular.

Fost
01-12-2006, 02:12 AM
those further away, the flares do not change size as their position changes.
I've always noticed the opposite using using film cameras:

Flares actually get larger the further they are from the screen centre, in a non linear way, and I think this is down to lens distortion, since it happens across the width of the individual flare (making it appear to get stretched at the edges).

Also, widescreen film is usually anamorphic, so the flare becomes squashed and is elliptical rather than sperical.

There's a really good pan round a field with a big fat naturally occuring lens flare in the closing scene of 'The Long Kiss Goodnight' that is worth studying.