Marty McFly's Advanced Depth of Field (standalone)

  • Marty McFly
  • Topic Author
More
9 years 1 month ago - 9 years 1 month ago #1 by Marty McFly Marty McFly's Advanced Depth of Field (standalone) was created by Marty McFly
As requested by a lot of my fellow facebook followers, today I release my DoF shader (or better, a slightly toned down variant of it).
Why another DoF, you may ask:
Well, first of all, it is very scalable and allows small blur at little fps cost up to screenarchery blur at a performance that could only be achieved by separable filters like Magic DoF. The focussing works a little different to the one in MasterEffect/McFX but you'll see, it allows much more control of the blur than any other one!

Most noteable features are
  • Extreme quality:
    Shaders like gp65cj042 DoF have a quality modifier that controls how many "rings" the DoF blur draws. Usually, after 12 or more rings, internal limits are reached and performance is unbearable. This shader can (virtually) draw up to 255 rings without compiler errors. Of course values like these kill the framerate but even a quality setting of 20 runs comparably fast.
  • Extreme performance:
    If you want little farblur and other DoF shaders are too heavy for that (after all they are developed for heavy blur), this is the right thing for you. The sheer amount of features might be baffling but the shader is also optimized to produce lightweight results. On the other hand, if you want to make elaborate screenshots with huge out of focus blur that covers large areas of the screen, this is the one for you. While other solutions struggle to produce such results at all, this shader here runs comparably fast. I could be naming some abstract impact in ms/frame but that never beats personal experience, does it.
  • Extreme scalability:
    You can modify your blur shape in almost any way you can imagine! This DoF features rotation, curvature (for circular DoF), aperture deformation, anamorphic ratio, lens distortion, shape diffusion (to roughen up the shape and get rid of moire patterns), weighting, different chromatic aberration modes. If that's not enough, you can customize your shape by using a texture mask.


Complete documentation of control values
Focussing

Warning: Spoiler!

Shape
Warning: Spoiler!

Shape modifications
Warning: Spoiler!

Chromatic Aberration
Warning: Spoiler!

Other
Warning: Spoiler!


Example screenshots
Aperture and focus visualization
[img

Shape chroma, bokeh weighting and focus visualization
[img

Shape texture:
[img

Lens distortion:
[img


Download
mediafire.com


Whoever finds optimizations can keep them (I'm looking at you kingeric ) I have neither time nor interest anymore to work on this shader but I also dislike people meddling with it. There may be small improvements that can further improve performance but the overall structure provides striking performance already so these changes will be minor. Plus, 99% of a DoF shader's performance overhead are the huge amount of samples anyways. Of course, bugfixes will be made. If you want to use parts of this code in other projects, please ask me first.

Short note about external textures: bokehmask is new, while the noise texture is identical to MasterEffect/McFX one.
Last edit: 9 years 1 month ago by Marty McFly.
The following user(s) said Thank You: crosire, Wicked Sick, SiriusHours, NattyDread, fuze, Tom Yum 72, GroinShooter, SpinelessJelly, BillyAlt, klotim and 12 other people also said thanks.

Please Log in or Create an account to join the conversation.

  • Quentin-Tarantino
More
9 years 1 month ago #2 by Quentin-Tarantino Replied by Quentin-Tarantino on topic Marty McFly's Advanced Depth of Field (standalone)
Will this be added to Framework? Looks amazing marty :)

Please Log in or Create an account to join the conversation.

  • OtisInf
More
9 years 1 month ago #3 by OtisInf Replied by OtisInf on topic Marty McFly's Advanced Depth of Field (standalone)
Nice!

Quick question (because it's one of the main reasons I don't like the current DoF in reshade): (If it's already there and thus I overlooked it: forget I asked) could you add a parameter which defines the focus range? So in effect a near and far plan after which the blurring kicks in. This is IMHO easier to configure than a blur curve and more natural with what a human experiences elsewhere: if the range around the focused point (nearer towards the camera and further away from the camera) is configurable, it's easier to control what is out of focus. At least that's what's my experience with other DoF's, including Kingeric1992's one for ENB.

TIA.

Please Log in or Create an account to join the conversation.

  • mindu
More
9 years 1 month ago #4 by mindu Replied by mindu on topic Marty McFly's Advanced Depth of Field (standalone)
Best DoF ever, fast, customizable and beauty, this is just perfect, thanks for share Marty <3

I have a question how can I use logarithmic depth? or any other way for V?

Please Log in or Create an account to join the conversation.

  • Marty McFly
  • Topic Author
More
9 years 1 month ago - 9 years 1 month ago #5 by Marty McFly Replied by Marty McFly on topic Marty McFly's Advanced Depth of Field (standalone)
Quentin-Taranrino
Problematic because it does not fit the render chain I set up for the DoF's. Either I migrate all DoF's to this focussing and masking and break all existing configs in the process or I set up a separate chain which is what I wanted to prevent when I unified the DoF shaders in the first place.
OtisInf
Focussing will stay that way.
mindu
Currently no option for logarithmic depth yet, as I have no game right now to test this on (I have GTA 5 but installation is broken and 60 gb, well...).
Last edit: 9 years 1 month ago by Marty McFly.

Please Log in or Create an account to join the conversation.

  • kingeric1992
More
9 years 1 month ago #6 by kingeric1992 Replied by kingeric1992 on topic Marty McFly's Advanced Depth of Field (standalone)
Well, cant guarantee anything. (๑´ڡ`๑)

Please Log in or Create an account to join the conversation.

  • OtisInf
More
9 years 1 month ago #7 by OtisInf Replied by OtisInf on topic Marty McFly's Advanced Depth of Field (standalone)

Marty McFly wrote: OtisInf
Focussing will stay that way.

Bummer, but ok

mindu
Currently no option for logarithmic depth yet, as I have no game right now to test this on (I have GTA 5 but installation is broken and 60 gb, well...).

You could use the linearized depth buffer which works with either logarithmic depth buffers or normal ones? (haven't checked whether you're using that already, haven't looked at the code yet)
The following user(s) said Thank You: mindu

Please Log in or Create an account to join the conversation.

  • Marty McFly
  • Topic Author
More
9 years 1 month ago #8 by Marty McFly Replied by Marty McFly on topic Marty McFly's Advanced Depth of Field (standalone)
Yes I could but if I recall right, the function used for logarithmic buffer is inverted so all the depth calculation stuff won't work. I cannot test my shader on such a game and therefore I won't add such a function yet, hoping it works.
The following user(s) said Thank You: mindu

Please Log in or Create an account to join the conversation.

  • mindu
More
9 years 1 month ago - 9 years 1 month ago #9 by mindu Replied by mindu on topic Marty McFly's Advanced Depth of Field (standalone)
just tried with Lucifer's code

depth = saturate(1.0f - depth);
depth = (exp(pow(depth, 150 * pow(depth, 55) + 32.75f / pow(depth, 5) - 1850f * (pow((1 - depth), 2)))) - 1) / (exp(depth) - 1); // Made by LuciferHawk ;-)
with your scenecoc instead but yeah doesn't work, I'm too noob to do it properly :blush:

edit: also tried to invert near/far depth like I did with old ME to make it work without logdepth but with this dof doesn't work that way either :(
Last edit: 9 years 1 month ago by mindu.

Please Log in or Create an account to join the conversation.

  • Marty McFly
  • Topic Author
More
9 years 1 month ago #10 by Marty McFly Replied by Marty McFly on topic Marty McFly's Advanced Depth of Field (standalone)
Find the GetLinearDepth function and paste the new code there.
The following user(s) said Thank You: mindu

Please Log in or Create an account to join the conversation.

  • OtisInf
More
9 years 1 month ago #11 by OtisInf Replied by OtisInf on topic Marty McFly's Advanced Depth of Field (standalone)
I've the witcher 3 here with log depth buffer, will see how it turns out later today.
The following user(s) said Thank You: mindu

Please Log in or Create an account to join the conversation.

  • mindu
More
9 years 1 month ago #12 by mindu Replied by mindu on topic Marty McFly's Advanced Depth of Field (standalone)

Marty McFly wrote: Find the GetLinearDepth function and paste the new code there.

it works!! its beautiful thanks :cheer:

Please Log in or Create an account to join the conversation.

  • Ganossa
More
9 years 1 month ago - 9 years 1 month ago #13 by Ganossa Replied by Ganossa on topic Marty McFly's Advanced Depth of Field (standalone)
See no problem with my LogDepth code in the Framework.
I included the ADOF code and it works like a charm in GTA V e.g.

Last edit: 9 years 1 month ago by Ganossa.
The following user(s) said Thank You: Marty McFly

Please Log in or Create an account to join the conversation.

  • Marty McFly
  • Topic Author
More
9 years 1 month ago #14 by Marty McFly Replied by Marty McFly on topic Marty McFly's Advanced Depth of Field (standalone)
Well...if the log depth is just linearizing, then it's fine. I just remembered that the old code had black as background and white as foreground color while the usual linearizing function did it vice versa, how I expect it to be.

Please Log in or Create an account to join the conversation.

  • NattyDread
More
9 years 1 month ago #15 by NattyDread Replied by NattyDread on topic Marty McFly's Advanced Depth of Field (standalone)
Inverted DB is fine for DoF but it's horrible for AO. Can you guys PLEASE do something about this. Most of the log depth ones are inverted.
I guess it would be ideal if we could set the pure black (furthest point) and pure white (closest point) our selves on a per game basis so we can use the DB to it's full potential.

Please Log in or Create an account to join the conversation.

  • Ganossa
More
9 years 1 month ago #16 by Ganossa Replied by Ganossa on topic Marty McFly's Advanced Depth of Field (standalone)
@Marty, right, that was fixed with the recreated function. :) I think it was actually most new games flipping the log depth compared to the common depth, so we have a standard flip now in case of log depth .oO

@NattyDray, as far as I remember, AO shader might not use the global depth linearization functions in your release yet. I think I tried it though when integrating Marty's new version into the framework. However, I am rather unsure/unfamiliar when it comes to the AO code so I am sure Marty needs to check first whether everything works as intended (plus I think he has even a later version already :cheer: )
Anyhow, I will remember to add flip options for that global linearization fuctions and leave some information how you can do that yourself shortly :)
The following user(s) said Thank You: NattyDread

Please Log in or Create an account to join the conversation.

  • Kleio420
More
9 years 1 month ago - 9 years 1 month ago #17 by Kleio420 Replied by Kleio420 on topic Marty McFly's Advanced Depth of Field (standalone)
so are you saying you would be against someone optimizing the code more if there is anything to be done ? and if not would posting the updated code on here be best or another form of contact

//admin edit: don't quote huge posts, a simple @username is enough.
Last edit: 9 years 1 month ago by Marty McFly.

Please Log in or Create an account to join the conversation.

  • Marty McFly
  • Topic Author
More
9 years 1 month ago - 9 years 1 month ago #18 by Marty McFly Replied by Marty McFly on topic Marty McFly's Advanced Depth of Field (standalone)
Everything has been said, please don't hang yourself with one phrase of mine. Did you actually try out the shader?
Last edit: 9 years 1 month ago by Marty McFly.
The following user(s) said Thank You: jas01

Please Log in or Create an account to join the conversation.

  • OtisInf
More
9 years 1 month ago - 9 years 1 month ago #19 by OtisInf Replied by OtisInf on topic Marty McFly's Advanced Depth of Field (standalone)

NattyDread wrote: Inverted DB is fine for DoF but it's horrible for AO. Can you guys PLEASE do something about this. Most of the log depth ones are inverted.
I guess it would be ideal if we could set the pure black (furthest point) and pure white (closest point) our selves on a per game basis so we can use the DB to it's full potential.

It depends on whether the Z axis is positive (D3D) or negative (OpenGL) into camera space, I think. Max depth against camera location (so camera space) should IMHO always positive (as that's more natural, as max depth==highest depth value so furthest away from the origin, which is the camera), but in the coordinate system of the rendering api might mean it should be negative and that could lead to e.g. lower values for max depth.

For a generic shader that has to work on opengl and d3d, I think you can only linearize in one way: depth in camera space with positive Z into the camera space, so max depth is positive and a higher value than min depth. The shaders then can anticipate on that being always the case and there's just 1 location to take care of linearization instead of in each shader.
Last edit: 9 years 1 month ago by OtisInf.

Please Log in or Create an account to join the conversation.

  • kingeric1992
More
9 years 1 month ago - 9 years 1 month ago #20 by kingeric1992 Replied by kingeric1992 on topic Marty McFly's Advanced Depth of Field (standalone)

OtisInf wrote: It depends on whether the Z axis is positive (D3D) or negative (OpenGL) into camera space


This is not true, opengl is also positive into screen depth, it is just ranged [-1,1].
However in d3d, there is a trick using inverted/reversed depth buffer (ie, map far clip plane to 0 and near to 1) to distribute float precision more evenly.
gl, on the other hand, can not be benefit from such trick.
here is a detail info and visualization on reversed-z developer.nvidia.com/content/depth-precision-visualized

a example of reversed-z is Mad Max, with the linearization function:
zF = 40000;
zN = 0.1;
    lineardepth = zF * zN / (zN + depth * (zF - zN));

I think the macro _RENDER_ is used to tell the shader what api it is using, so there shouldn't be any problem converting gl depth buffer to directx range.
Last edit: 9 years 1 month ago by kingeric1992.

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.