Light halos, lens flares, volumetric stuff

Started by
13 comments, last by lipsryme 11 years ago
Lens flare sprites should never intersect with the world, as they're simulating something "inside the camera". Simply turn off depth testing for these.
"Glow sprites" that represent the halo that occurs in our eyes are the same deal -- no depth testing. However, both these effects do need some form of occlusion testing so they fade/disappear as the light is hidden by closer geometry. I like to do this by sampling the depth buffer at the light's position.

In my last game we used old-school sprite based lens flares and image based lens flares, with both effects modulated by an artist-drawn 'dirty lens' mask texture. To determine the sun's occlusion (for fading out the sprite-based lens flare), I did a Boolean depth comparison on a 16x16 area of the depth buffer where the sun should be, and then downsampled these results to a single 8-bit visibility fraction.

For "glow sprites" that represent fog around the light, you need to use "soft depth testing" ("soft particles", "soft billboards", etc might turn up some material). Instead of clipping against the world at intersections, these will then fade out as they approach an intersection, which almost completely hides the fact that they're a sprite (the remaining problem is when the camera enters the "volume").
Advertisement

Sprites could work for fog if you're targeting low power systems. If you're targeting high power systems (the new consoles/high end PCs) you'll want atmospheric scattering EG: http://www.cs.berkeley.edu/~ravir/papers/singlescat/scattering.pdf and for godrays something like: http://download-software.intel.com/sites/default/files/LightScatteringGDC2013_final.pdf

Using a mini depth buffer to approximate visibility sounds smart, got to keep that in mind instead of doing traditional culling.

Hmmm, I tried soft particles before, but usually in narrow crowded spots they wouldn't be visible much, because they would always (almost) collide and therefore fade out. Well, that could be a matter of tweaking.

The biggest problem I had with glow-sprites, soft or not, were rectangular shaped lights such as fluorescent "tubes". The sprite can't rotate with the camera in this case, unless it scales itself depending on the view vector or something. Keep it a fixed rotation did the job for most angles, but as soon as you stand in a 90 degree angle, you still notice the flatness, if you can see the sprite at all.

That's why I was thinking about defining a 3D shape (such a sphere or cube) around lamps and then render a view dependant sprite in it. But I didn't implement anything yet, neither do I have a battle plan. But maybe someone else has experience?

@Frenetic Pony

That's a lot of formula's, usually my brains crash then :) But I'll give it a try and read, I always thought that Atmospheric Scattering, at least in games, was more for bigger scaled (outdoor) fog and skies, rather than doing glow sprites which are a very local effect? Either how, it needs to be a relative cheap effect as in my case I have many lights that can appear everywhere.

Anyway, thanks for the links!

Btw, maybe useful for others, I found this about implementing lens-flares

http://john-chapman-graphics.blogspot.nl/2013/02/pseudo-lens-flare.html

@Frenetic Pony

That's a lot of formula's, usually my brains crash then smile.png But I'll give it a try and read, I always thought that Atmospheric Scattering, at least in games, was more for bigger scaled (outdoor) fog and skies, rather than doing glow sprites which are a very local effect? Either how, it needs to be a relative cheap effect as in my case I have many lights that can appear everywhere.

Works for unlimited lights, err, and highlights, and it's basically what the sprites would be approximating in the first place. But if you need cheap, better atmospheric scattering might not be the way to go.

I think the technique john chapman is describing is exactly the same as the one being used in UE4 (and a few other recent games I've noticed).

It works quite nicely as a post effect on every light source (or rather bright spots like bloom). Needs a bit of fine tuning though...like making the texture look good, plus you might not want to have half of the screen full of lens flares xD

This topic is closed to new replies.

Advertisement