BF3 Lens flares

Started by
8 comments, last by MrOMGWTF 11 years, 8 months ago
I'm trying to add a similar effect to my engine, but my attempts so far didn't look nearly as good!
I'm able to have a sun occlusion value (0->1) using occlusion queries, my question is how to use that value to drive the effect.

Thanks.
Advertisement
Looking at the screenshot, there's probably at least 3 different effects there.
1) The sun's glowing starburst.
2) The octagonal lens flare to the bottom right of the starburst.
3) The 'dirty lens' effect along the bottom of the screen.

For (1), plug your occlusion value into the scale and brightness of the starburst overlay. N.B. there might be multiple overlapping sprites involved here, possibly rotating in different directions.
For (2), it's an overlay placed somewhere along a line that goes through the sun's location and the centre of the screen. It can use the same effect of being scaled/dimmed with occlusion.
For (3), the "specks of dust" are a static (non-moving) overlay which probably isn't directly tied to the sun's occlusion -- instead it's probably driven by the bloom results.
Thanks!
for (3), do you mean just scale it with average scene luminance?
Thanks!
for (3), do you mean just scale it with average scene luminance?
Yeah that would be a good starting point. I'm not sure exactly how they do it, so another thing I'd try is to use a blurred version of the scene's lumincance (e.g. like an intermediate bloom result), and I'd also try flipping this bloom-result up-side-down and left-to-right -- so that if the top right of the screen is very bright, then the 'dirt' in the bottom left becomes visible.

Thanks!
for (3), do you mean just scale it with average scene luminance?

No, the actual bloom buffer. Looks like it's also flipped/scaled to not occupy the entire screen. As to how it's actually composited, that's an interesting question. It *looks* like it may be alpha-blended (color possibly modulated by bloom color?) with the alpha coming from bloom brightness somehow.

EDIT: I think there's also some extra magic going on with the sun, almost as if they render a lens flare into that buffer somehow.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Mainly regarding (3): I get pretty good results doing as follows:
1) Do a 'bright pass' (downscale + threshold)
2) Take the result and flip left-right top-bottom (as Hodgman says)
3) Apply a radial blur to the flipped bright pass
4) Blend this with the original, unflipped bright pass
5) Apply a gaussian blur to the whole thing
6) Upscale and blend with the original image, modulating with a lens dirt texture

I actually apply another threshold at step 2 so that only very bright pixels get 'flipped'. The flipped, radially blurred results give a soft 'pseudo lens flare' which works best when it's made quite subtle (hence the secondary threshold). The lens dirt texture gives the whole thing an organic look and hides any artifacts (e.g. caused by using a low number of samples for the radial blur). I've included the lens texture I made and some examples; I think overall it works better being more subtle.

As for elements (1) and (2): looking closely in BF3 I don't think the lens flare sprites are modulated by the lens dirt texture. Part of me thinks they should be...
@johnchapman

Your results look really good.smile.png Is the test scene from screenshot 2 and 4 available to download somewhere?
@johnchapman

Wow, cool, I'm gonna try this out!
@TiagoCosta: the geometry for the buddha statuette and the column are available from archive3d.net. The walls of the cornell box I knocked together in 3ds max. I've put the 3DS file up here.

This thread got me thinking about the 'psuedo lens flare' agan and how it might be improved, possibly by modulating it radially by a 1D texture; offsets into the texture are controlled by the camera's rotation. Stylistic, of course, but it might look cool...

This topic is closed to new replies.

Advertisement