Xbox LIVE Indie Games

code sample details

Lens Flare

Submitted
1/17/2008
Code Sample

Description:

This sample shows how to implement a lens flare effect by using occlusion queries to detect when the sun is hidden behind the landscape.

Sample Overview

The visual phenomenon known as lens flare determines how bright lights behave when they shine into a camera lens. Computer games often have a hard time conveying an impression of brightness because monitors and televisions have only a limited brightness range. After all, it's impossible for a pixel to be brighter than white. How can you show the difference between a character wearing a white t-shirt, which is not very bright, and the sun, which is very bright indeed? The solution is to simulate what happens when a movie director points a camera directly at a bright light source. Games can simulate the flares that would be produced inside a physical camera. The flares provide a visual cue to the brightness of the light.

The lens flare effect in this sample is formed of two components: a large, soft glow, plus a row of smaller circular flare shapes.

The sample uses hardware occlusion queries to efficiently detect when the sun is hidden behind the landscape. This enables you to fade out the lens flare effect when the sun isn't visible.


All content and source code downloaded from this page are bound to the Microsoft Permissive License (Ms-PL).

downloads

Framework

GS 4.0

Framework

GS 3.1

find education content
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG