Lens Flares |
A lens flare is an effect caused by a camera lens when looking at bright light. A lens flare usually consists of multiple elements which move across the screen depending on the position of the light source: bloom and halo around the light source, light streaks, secondary rings, hexagonal patterns caused by the lens' aperture blades.
This topic contains the following sections:
A lens flare effect is defined by creating a LensFlare. The elements of a lens flare (e.g. rings, halos, ...) are defined using the LensFlareElement. The LensFlareElements need to be added to the Elements collection. The LensFlareNode positions a lens flare within a scene. (Lens flare effects in DigitalRune Graphics are not bound to cameras or light sources - they can be placed anywhere within a scene.)
This section explains how to render lens flare effects using the LensFlareRenderer.
The LensFlareRenderer is SceneNodeRenderer that handles LensFlareNodes. The renderer performs hardware occlusion queries to determine the visibility of the lens flares. The query results are delayed by one or more frames, which means that lens flares need at least two frames to become visible.
Lens flares need to be rendered in two passes:
Occlusion Query: The method UpdateOcclusion needs to be called after the scene is rendered. The Z-buffer of the current render target needs to contain the depth information of the scene. The method performs a hardware occlusion query to check the visibility of the light source. In a deferred lighting renderer the method can be called at the end of the "Material" pass. No pixels are rendered into the current render target during the occlusion queries.
Rendering: The method Render needs to be called to render the lens flares into the current render target. The method can be called at any point after the occlusion queries.
The following code illustrates the usage within the rendering pipeline.
// Here: Render all opaque objects... // At this point the Z-buffer should contain the depth information of the scene. // Perform occlusion queries to determine the visibility of the lens flare nodes. lensFlareRenderer.UpdateOcclusion(query.SceneNodes, context); // Render other stuff... // Render lens flares. lensFlareRenderer.Render(query.SceneNodes, context);
The LensFlareRenderer has certain limitations:
It is further possible to customize the size and intensity of a lens-flare effect by deriving a custom lens-flare type from LensFlare and overriding the method OnGetSizeAndIntensity. This method is called by the LensFlareRenderer during Render.