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.

4 of 20 comments (clear)

  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. Gamedev.net by John+Jorsett · · Score: 3, Informative

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

  3. 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