Terasology: Lens Flares Node

Created on 4 Aug 2017  路  3Comments  路  Source: MovingBlocks/Terasology

Introduction

Lens Flares: one of the most beloved and most easily overused features of computer graphics.

Lens flares in real cameras are generated by slight imperfections in the individual lenses composing an objective. The imperfections will generally be invisible, but bright enough lights, i.e. the sun during the day or even car headlights at night, will make them apparent, typically as circles and polygons of various transparency and level of completeness (sometimes just an arch will be visible).

Digital cameras are affected just as much as film cameras (the lenses and objectives are the same!), but computer graphics cameras tend to be lens-less and generally produce no lens flares!

For this reason, if needed, lens flares are generated as a post-production step, and overlaid on top of an existing image.

Visual Description

From a visual perspective lens flares effectively consist of a number of artifacts arbitrarily but statically positioned along a dynamic imaginary axis, starting from the light source causing the flare, through the center of the frame and beyond, until out of frame. As the light changes position, the axis changes with it, dragging all the artifacts on it around the screen. Furthermore, the further out from the screen center the light is, the more transparent the artifacts will be, to the point of disappearing completely if the light is far out of frame (a light that is -just- out of frame will normally still produce a flare).

Primary Goal - The bare minimum

Assuming a single light source for simplicity and given the description above, all we need is an arbitrary number of texture mapped quads positioned in screen-space at arbitrary points along the light -> frame center axis. A [0.0-1.0[ factor would tell the node where along the axis to draw each quad, with 0.0 being right on the light source and 1.0 right in the frame's center.

UV-coordinates associated with each quad would then allow the reading of a specific portion of a texture atlas, so that all types of artifacts can be stored in a single texture passed to the node on construction and made available via the SetInputTexture2D state change.

The shader would then receive additional information, such as the angle between the camera forward vector and the camera-light, for the artifacts to be most opaque when the light source is at the center of the frame and fully transparent beyond some threshold angle.

The rendering of the quads would be executed with blending enabled, directly on an existing image in normal circumstances or starting on a black background for debugging purposes.

Secondary Goals - Nice-to-have

  • Additional per-vertex color information could be used to colorize artifacts, perhaps to reuse the exact same portion of the texture atlas multiple times - think of circle or ring artifacts in slightly different colors but all using the same portion of the texture.
  • The angle between the camera forward vector and the camera-to-light vector would also be an input to implement chromatic aberrations on the artifacts.
  • Also useful could be the screen-space angle between the up vector of the camera and the camera-to-light direction, for each single artifact to be somewhat brighter toward the light, radially fading out the texture values beyond a set angle. Or to simulate aperture shapes.
  • Anamorphic lens flares: this could be achievable simply having wide/short or narrow/tall textures in the atlas, and accordingly sized quads.

Tertiary Goals - for highly committed lens-flare developers

  • A system capable of generating the right lens flare for each light in the scene, for example one generating a lot of artifacts when looking at the sun and perhaps just an anamorphic flare when looking at near enough torches.
  • A system capable of handling totally or partially obstructed light sources: all things equal a light source half behind an obstacle should have half as bright artifacts compared to an unobstructed light source. And a light source completely obstructed should generate no lens flare.

Resources

Rendering

Most helpful comment

Just a small correction here - this issue has a distinct lack of actual embedded lens flare images of superior quality!

lens-flares-into-darkness

All 3 comments

Just a small correction here - this issue has a distinct lack of actual embedded lens flare images of superior quality!

lens-flares-into-darkness

Hi! Newbie here.
I'd like to work on this feature. However, can this perhaps be considered a GSOC - level feature? @Cervator @emanuele3d

Hey @manas96 - I answered with more details in the forum, while I'm not entirely certain I expect the answer is no, but it could be part of a GSOC item :-)

Was this page helpful?
0 / 5 - 0 ratings