Welcome, Guest.
Username: Password: Remember me

TOPIC: Marty McFly's Advanced Depth of Field (standalone)

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #1

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
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! [ Click to expand ]

Shape
Warning: Spoiler! [ Click to expand ]

Shape modifications
Warning: Spoiler! [ Click to expand ]

Chromatic Aberration
Warning: Spoiler! [ Click to expand ]

Other
Warning: Spoiler! [ Click to expand ]


Example screenshots
Aperture and focus visualization

Shape chroma, bokeh weighting and focus visualization

Shape texture:

Lens distortion:


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: 1 year 1 month ago by Marty McFly.
The administrator has disabled public write access.
The following user(s) said Thank You: crosire, Wicked Sick, SiriusHours, NattyDread, fuze, Tom Yum 72, GroinShooter, SpinelessJelly, BillyAlt, klotim and this user have 11 others thankyou

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #2

  • Quentin-Tarantino
  • Quentin-Tarantino's Avatar
  • Offline
  • If there is no struggle, there is no progress.
  • Posts: 351
  • Thank you received: 218
Will this be added to Framework? Looks amazing marty :)
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #3

  • OtisInf
  • OtisInf's Avatar
  • Offline
  • Posts: 122
  • Thank you received: 51
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.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #4

  • mindu
  • mindu's Avatar
  • Offline
  • Posts: 54
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?
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #5

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
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: 1 year 1 month ago by Marty McFly.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #6

Well, cant guarantee anything. (๑´ڡ`๑)
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #7

  • OtisInf
  • OtisInf's Avatar
  • Offline
  • Posts: 122
  • Thank you received: 51
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 administrator has disabled public write access.
The following user(s) said Thank You: mindu

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #8

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
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 administrator has disabled public write access.
The following user(s) said Thank You: mindu

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #9

  • mindu
  • mindu's Avatar
  • Offline
  • Posts: 54
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: 1 year 1 month ago by mindu.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #10

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
Find the GetLinearDepth function and paste the new code there.
The administrator has disabled public write access.
The following user(s) said Thank You: mindu

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #11

  • OtisInf
  • OtisInf's Avatar
  • Offline
  • Posts: 122
  • Thank you received: 51
I've the witcher 3 here with log depth buffer, will see how it turns out later today.
The administrator has disabled public write access.
The following user(s) said Thank You: mindu

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #12

  • mindu
  • mindu's Avatar
  • Offline
  • Posts: 54
Marty McFly wrote:
Find the GetLinearDepth function and paste the new code there.
it works!! its beautiful thanks :cheer:
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #13

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
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: 1 year 1 month ago by Ganossa.
The administrator has disabled public write access.
The following user(s) said Thank You: Marty McFly

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #14

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
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.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #15

  • NattyDread
  • NattyDread's Avatar
  • Offline
  • Posts: 80
  • Thank you received: 85
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.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #16

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
@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 administrator has disabled public write access.
The following user(s) said Thank You: NattyDread

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #17

  • Kleio420
  • Kleio420's Avatar
  • Offline
  • Posts: 216
  • Thank you received: 28
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: 1 year 1 month ago by Marty McFly.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #18

  • Marty McFly
  • Marty McFly's Avatar
  • Offline
  • We've tried nothing and we're all out of ideas!
  • Posts: 609
  • Thank you received: 716
Everything has been said, please don't hang yourself with one phrase of mine. Did you actually try out the shader?
Last Edit: 1 year 1 month ago by Marty McFly.
The administrator has disabled public write access.
The following user(s) said Thank You: jas01

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #19

  • OtisInf
  • OtisInf's Avatar
  • Offline
  • Posts: 122
  • Thank you received: 51
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: 1 year 1 month ago by OtisInf.
The administrator has disabled public write access.

Marty McFly's Advanced Depth of Field (standalone) 1 year 1 month ago #20

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: 1 year 1 month ago by kingeric1992.
The administrator has disabled public write access.