Sign in to follow this  
gSharq

BF3 Lens flares

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='gSharq' timestamp='1329869630' post='4915333']Thanks!
for (3), do you mean just scale it with average scene luminance?[/quote]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.

Share this post


Link to post
Share on other sites
[quote name='gSharq' timestamp='1329869630' post='4915333']
Thanks!
for (3), do you mean just scale it with average scene luminance?
[/quote]
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
@TiagoCosta: the geometry for the buddha statuette and the column are available from [url="http://archive3d.net/"]archive3d.net[/url]. The walls of the cornell box I knocked together in 3ds max. I've put the 3DS file up [url="http://www.john-chapman.net/blog/envmap_gi1/tier_wall.max"]here[/url].

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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this