Jump to content

  • Log In with Google      Sign In   
  • Create Account


BF3 Lens flares


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 gSharq   Members   -  Reputation: 127

Like
0Likes
Like

Posted 21 February 2012 - 03:52 PM

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.

Attached Thumbnails

  • BF3LensFlare.jpg


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 24014

Like
0Likes
Like

Posted 21 February 2012 - 05:33 PM

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.

#3 gSharq   Members   -  Reputation: 127

Like
0Likes
Like

Posted 21 February 2012 - 06:13 PM

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

#4 Hodgman   Moderators   -  Reputation: 24014

Like
0Likes
Like

Posted 21 February 2012 - 06:21 PM

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.

#5 InvalidPointer   Members   -  Reputation: 1270

Like
0Likes
Like

Posted 22 February 2012 - 12:03 PM

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.

#6 johnchapman   Members   -  Reputation: 416

Like
4Likes
Like

Posted 22 February 2012 - 01:11 PM

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

Attached Thumbnails

  • flare_results.jpg
  • lens_dirt.jpg


#7 TiagoCosta   Crossbones+   -  Reputation: 1697

Like
0Likes
Like

Posted 22 February 2012 - 01:55 PM

@johnchapman

Your results look really good.Posted Image Is the test scene from screenshot 2 and 4 available to download somewhere?
Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development

#8 Litheon   Members   -  Reputation: 240

Like
0Likes
Like

Posted 22 February 2012 - 02:32 PM

@johnchapman

Wow, cool, I'm gonna try this out!

#9 johnchapman   Members   -  Reputation: 416

Like
0Likes
Like

Posted 23 February 2012 - 12:44 PM

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

#10 MrOMGWTF   Members   -  Reputation: 433

Like
0Likes
Like

Posted 20 August 2012 - 12:30 AM

Sorry for bumping this old thread, but I'm really interested how they made this beautiful starburst.
It don't think it's just static texture blended to the sun's position.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS