Slashdot Mirror


Simulating Lens Flares?

spectecjr asks: "Everyone's seen lens flare effects being used in various 3D games recently (including Half Life, Unreal Tournament, etc); but typically, these effects are simulated using Photoshop to create textures which are then billboarded to the screen. So how do the people who write Photoshop plug-ins simulate lens flares? All the tutorials on the 'net seem to be of the nature of the fake-out method used above. So if you were going to write a lens flare simulation from scratch, how would you do it?" Interesting question. It would be interesting to know the mathematics behind modeling lens flares, using the Photoshop model and more realistic models, if they exist.

20 comments

  1. Hmm. by Tomun · · Score: 3, Informative

    this page says that the appearance of the flare depends on the kind of camera that produced it. So if you want to simulate a flare the first question should be "what type of camera am I trying to simulate?"

    1. Re:Hmm. by CyberLife · · Score: 5, Informative
      Actually, the camera has almost nothing to do with it. It's internal reflections within the lens, hence the name. Essentially, it all boils down to the fact that glass isn't a perfect conductor of light.

      As light enters a lens, most of it is refracted towards the optical center. Some however is specularly reflected back towards the source just like it bounced off a mirror. When this happens on the outer lens element, the light just goes back into the scene. But when it happens on an inner element, it has to go back through other pieces of glass, each of which has the potential to re-reflect it back towards the film.

      Most light in a scene isn't strong or coherent enough to cause any noticable effect. If however you have a strong, concentrated stream of light (e.g. the sun) then you will see a series of reflections arranged in a line intersecting the light source and the optical center of the lens. That's why in moving images lens flares always seem to pivot around the center of the frame.

      Not all lens flares look the same either. The construction of the lens and the aperture settings can affect how it looks. Some flares consist of multi-faceted shapes such as octogons. This is caused by the aperture of the lens (made of many straight pieces) being less than fully-open.

      One of the more popular flares is oval shaped with bright, blue horizonal lines. The oval shape is a result of using an anamorphic image format. In this kind of system, the lens compresses the image horizontally to fit more information into a small frame area, and then a complementary lens is used on the projector to stretch it back out for presentation. If a flare happens inside the camera lens after the compression stage, it's recorded on film as a circular image. But when that circle is projected, it's streched out with the rest of the frame and becomes an oval.

      The blue lines effect seems to be an artifact that's unique to Panavision lenses. Although due to it's popularity I have heard of other lens makers trying to copy it.

      Even strong lights outside the frame can cause problems. This stems from the fact that lenses and frames are different shapes. The round lens draws in more light than what is actually recorded in the rectangular frame. This extra light can still bounce around the lens and get reflected into the shot. This is why higher-end photographers (especially those in the motion picture industry) use matte boxes. These rectangular housings fit around the front of the lens and hold black, opaque masks called mattes between the lens and the scene. These mattes have a rectangular hole in them just big enough to be oustide the frame line. The point is to keep all light out of the lens except what is necessary to fill the frame.

      - Milo Hyson
      CyberLife Labs/CyberLife Pictures

    2. Re:Hmm. by Anonymous Coward · · Score: 0

      Not to nit pick or anything, But I find it amusing that Cyber life starts the first sentance with Actually, the camera has almost nothing to do with it and then goes on to say The construction of the lens and the aperture settings can affect how it looks and The blue lines effect seems to be an artifact that's unique to Panavision lenses. Although due to it's popularity I have heard of other lens makers trying to copy it which indicates to me that the camera indeed has a lot to do with it.

    3. Re:Hmm. by CyberLife · · Score: 1

      In the world of professional photography, cameras and lenses are two different items, typically sold separately. Except for the shutter, there is very little inside a camera that affects the final outcome of the picture. Different lenses attached to the same camera can however give you quite different imagery.

  2. Gamedev.net by John+Jorsett · · Score: 3, Informative

    Take a look at this article on gamedev.net. It might contain what you're after.

    1. Re:Gamedev.net by eXtro · · Score: 1

      How in the world was this flame bait? The referred page does talk about constructing lens flares, there's not a goat.cx image to be seen and even seems fairly well written.

  3. What's the point of simulating an aberration? by TheLink · · Score: 3, Flamebait

    Sure simulating fog, heat mirages would make things look more realistic but why are people simulating lens flares? When was the last time you got lens flares in your normal vision?

    If you are seeing weird stuff like that in real life maybe you have glaucoma or need to consult an eye doctor ASAP :).

    --
    1. Re:What's the point of simulating an aberration? by CyberLife · · Score: 1

      We're used to seeing lens flares in movies and TV. Intentionally adding them to games and other CGI makes the experience more cinematic, giving it a little edge of fantasy.

    2. Re:What's the point of simulating an aberration? by toast0 · · Score: 1

      well... when my glasses and windshield are dirty enough, i get some approximation of a lens flare

    3. Re:What's the point of simulating an aberration? by Transcendent · · Score: 1

      You can get a "flare" in your normal vision... after all light does go through a lens in your eye. I know it's nothing like the ones we see in movies and TV, but if you stare at the right light, you'll get a glow or some streaking effect (especially if your eye is a little watery... try it with christmas lights) Ummm... last time that I got a lens flare in my normal vision was when I was driving home today from the bright lights of a car, and I have perfect vision, so I'm not gonna be rushing out to my eye doctor soon...

      There's always a reason to do something...

    4. Re:What's the point of simulating an aberration? by Transcendent · · Score: 1

      Little after-thought...

      What if the guy wanted to use it for a game where you have a movie clip or some sort of cinematic event? Or say they're looking through glass in goggles, a helmit, cockpit, or anything (...driving in a car...), and the glass isn't perfectly clear, which might produce a streak/flare.... again, there's always a reason to do something...

    5. Re:What's the point of simulating an aberration? by unitron · · Score: 2

      Isn't it obvious? He's trying to insert Forest Gump into the Zapruder film.

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

    6. Re:What's the point of simulating an aberration? by Anonymous Coward · · Score: 0

      again, there's always a reason to do something...

      Ok, Mr. Smarty Pants - please tell me a reason to allow a system of numbers where we can set 1=3 ?? In this sense our general understanding of number thoery and the basis there in of the universe would runravel...

    7. Re:What's the point of simulating an aberration? by spectecjr · · Score: 2

      Ok, Mr. Smarty Pants - please tell me a reason to allow a system of numbers where we can set 1=3 ?? In this sense our general understanding of number thoery and the basis there in of the universe would runravel...

      You use it all the time. It's called binary (except when you add numbers, you don't carry the 1). Modulo 2 arithmetic.

      XOR is based on this. CRC checksums are based on this. Most crypto appears to be based on this. It's not exactly 'useless'.

      Simon

      --
      Coming soon - pyrogyra
    8. Re:What's the point of simulating an aberration? by Transcendent · · Score: 1

      In this sense our general understanding of number thoery and the basis there in of the universe would runravel...

      First off... where the hell did you get that form?? 1=3?? (without changing bases)

      Second, If discovering a new way to do something "runravel"'s (???) the universe, then the system of the universe that we believed in wasn't true to begin with.

  4. Use the source, Luke. by Bazman · · Score: 4, Informative

    Gimp has a lens flare simulator in its FlareFX plug-in. Why not get the gimp source and find out how it does it? An option not available for the Photoshop version.

    Baz

  5. factors in lens flare by Anonymous Coward · · Score: 0

    Any lens flare simulator would have to take into account a lot of factors including, the number of elements in a lenses, often you see lens flare with multiple spots, each one of these spots is caused by a flaring lens elements. Another factor would be the shape of the lens flare which is caused by the apeture diagphram of the lens. If the lens is wide-open (no apeture present) you would get a perfectly round lens flare spot. If it was stopped down to f/8 or so you would get a more hexagon lens flare. I'm not sure about the size of the lens flare with relation to the apeture but I would assume a smaller apeture would yield smaller lens flare spots. So a lens stopped down to f/16 would probably yield a very small lens flare spot as opposed to a wide-open apeture. It's hard to say what a lens flare should really look though like since most photographers go out of there way to avoid them.

  6. Not only flares but distortion etc by dogbot · · Score: 1
    People are used to this camera artifacts, and think something is wrong if they are missing.

    Maya (http://www.aliaswavefront.com) for example not only offers lens flares but field of view (so the backgroung and foreground are blury, and only the mid-ground is in focus - or whatever you want).

    Alias also has some code to add or remove the distortion from panavision cameras (camera used by movie companies).

  7. visual overload by anon29 · · Score: 1

    As an artist, I have seen entirely too many lens flare effects used in print and other static media. It seems to me that people try to use the addition of a flare to add excitement to an image, but it has become too much.... As far as games and other interactive media are concerned, however, I think that the use of the lens flare could be nice.... Think about driving a car up a hill towards the west in the evening...as you crest the hill, you are temporarily blinded. This could be another interesting use for lens-flare like image manipulations.... I do not have any idea how the math behind the photoshop filter works, but it could be very useful to explore, and possibly create new ways of manipulating the virtual in ways that cannot yet be done in the physical world.... This kind of visual stimulus could really change perceptions! Now thats exciting.

  8. Check out POVRay by Andronicus · · Score: 1

    POV-Ray is a great freeware raytracing engine for Win, Mac, and Unix. It makes use of an easy to learn text-format scene description language. There was a set of include files available for POV-Ray that you could use in your scene description to describe the "camera" lenses and thus yield up many teriffic lens flares. I forgot the name of the package, but I think you can still find it in the contrib section. Very impressive!

    http://www.povray.org/

    --
    USNG: 14TPU4605