Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: The E on August 26, 2016, 04:57:08 pm

Title: New Lensflares
Post by: The E on August 26, 2016, 04:57:08 pm
One thing I've been working on recently is Lensflares. The way we did them previously was rather simple: You could define a couple of lensflare bitmaps for stars, and if that star was in frame, we rendered those bitmaps in vaguely appropriate places.

Now, that is certainly sufficient for some light lensflare action, but sometimes, you do want a bit more. So I looked around, and found this post (https://john-chapman-graphics.blogspot.de/2013/02/pseudo-lens-flare.html) by a gentleman called John Chapman, who presented a relatively easy to use (and performant) solution to generate flares using a shader. I then integrated that into the engine, and voila:


Pay particular attention to the way subspace vortices look now.

Now, this isn't going to go into the nightlies just yet. Before that happens, I want to give mission designers some control over the parameters the shader uses, as well as the ability to add a dirt mask. But once that's done (and it shouldn't take too long), this will find its way into a nightly near you.

IF you want to check this out for yourself, the branch can be found here: https://github.com/The-E/fs2open.github.com/tree/jjabrams_ogl3

Do note that in order to work, you need this texture (https://www.dropbox.com/s/37zzni3l87vsmk4/lenscolor.png?dl=0) in data/effects.
Title: Re: New Lensflares
Post by: Luis Dias on August 26, 2016, 07:40:28 pm
hmm. they behave weirdly. And I am yet to understand its logic... does it do explosions? Is every bright pixel on the screen taking to account? Or just subspace vortices? I notice the star in that video never renders a lensflare...
Regardless, I don't quite like it. Definitely not JJ standard :D
Title: Re: New Lensflares
Post by: Phantom Hoover on August 26, 2016, 07:55:22 pm
Anamorphic bloom would really help the JJ look along, I guess.

e: reference material: this is a raytrace simulation of the lens flare in a normal camera:

(https://upload.wikimedia.org/wikipedia/commons/d/d9/High-quality_lens_flare_rendering.png)

This is an anamorphic lens flare, presumably simulated, which is what you can see everywhere in Abrams Trek:

(https://upload.wikimedia.org/wikipedia/commons/6/63/Mograph_lensflare.png)

vs. the prototype FSO lens flares, it has that really big horizontal bloom where the light is (which, for me at least, is the thing I first think of as 'lens flare') and its ghosts don't really have any chromatic aberration.
Title: Re: New Lensflares
Post by: The E on August 27, 2016, 12:50:18 am
I kinda agree, which is why I am looking into methods for generating more physically correct flares.

Is every bright pixel on the screen taking to account? Or just subspace vortices? I notice the star in that video never renders a lensflare...

For a complete breakdown of how this works, read the article I linked to; short answer: Yes, every bright pixel gets taken into account.

Suns may not count for this at the moment, because rendering things is weird :P But I am looking into fixing this (and tweaking the overall effect to look better).
Title: Re: New Lensflares
Post by: AdmiralRalwood on August 27, 2016, 05:42:57 pm
Suns may not count for this at the moment, because rendering things is weird :P But I am looking into fixing this (and tweaking the overall effect to look better).
Well, if you do make it account for suns, you'd probably also want to disable the bitmap-based lensflares, or you'd get lensflares of lensflares (lensflareception?).
Title: Re: New Lensflares
Post by: The E on August 27, 2016, 06:30:32 pm
That was one of the first things I did :P
Title: Re: New Lensflares
Post by: mjn.mixael on August 27, 2016, 06:35:41 pm
Suns may not count for this at the moment, because rendering things is weird :P But I am looking into fixing this (and tweaking the overall effect to look better).
Well, if you do make it account for suns, you'd probably also want to disable the bitmap-based lensflares, or you'd get lensflares of lensflares (lensflareception?).

The future of JAD, you've found it!
Title: Re: New Lensflares
Post by: Axem on August 27, 2016, 07:05:57 pm
 :cool:
Title: Re: New Lensflares
Post by: Kolgena on August 28, 2016, 02:07:16 pm
Looks a bit like the dirty lens effect from XCOM2. Looks good.
Title: Re: New Lensflares
Post by: Oddgrim on September 06, 2016, 08:31:55 am
:cool:
Seconded! c:
Title: Re: New Lensflares
Post by: The E on September 06, 2016, 08:49:30 am
So I was looking for better lensflare algorithms, but couldn't actually find any (well, any that are entirely shader-based, that is). There are a few very interesting physically based lensflare rendering papers out there, but unfortunately the authors decided to not open-source their solution, but rather patent them. I think I'll just clean this up and then make a PR for it.
Title: Re: New Lensflares
Post by: soresu on September 06, 2016, 03:57:19 pm
Could the source of Unreal engine offer any pointers? I have seen pages with screenshots of lens flares on Epics own learning/reference docs.
Title: Re: New Lensflares
Post by: The E on September 07, 2016, 07:35:35 am
Could the source of Unreal engine offer any pointers? I have seen pages with screenshots of lens flares on Epics own learning/reference docs.

Problem is, I have no experience working with the UE code, and while I know where the relevant source code is, I have no idea what it actually means or how it works.
Title: Re: New Lensflares
Post by: Bryan See on January 28, 2017, 11:43:50 am
To get an inspiration, you may want to see how they look in the 2012 Total Recall remake (http://www.youtube.com/watch?v=nqWYm-EDS8U) and JJ Abrams's Star Trek films.

Regarding engines, what about CryEngine3/CryEngine (3.6-4)/CryEngine V and Unity3D in terms of this topic?

EDIT: I amended to add clarification. BTW, I've viewed The E's video on lensflares in Blue Planet and it's tremendous. I think it would be nice to add them to all flashes and glows depending on intensity and tone.
Title: Re: New Lensflares
Post by: Bryan See on April 04, 2017, 12:42:24 pm
I've implemented (https://github.com/bryansee/fs2open.github.com/commit/8427fb48f3ff7b558ce97c935179ed5a7098e38b) your lens flares in my build.