MovingBlocks / Terasology

Terasology - open source voxel world
http://terasology.org
Apache License 2.0
3.69k stars 1.34k forks source link

Lens Flares Node #3047

Open emanuele3d opened 7 years ago

emanuele3d commented 7 years ago

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

Tertiary Goals - for highly committed lens-flare developers

Resources

Cervator commented 7 years ago

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

lens-flares-into-darkness

manas96 commented 6 years ago

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

Cervator commented 6 years ago

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 :-)