Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an advanced cinematic Depth of Field shader for Reshade 3.x #90

Merged
merged 10 commits into from Aug 12, 2018

Conversation

Projects
None yet
3 participants
@FransBouma
Copy link
Contributor

commented Aug 8, 2018

I implemented a cinematic depth of field shader from scratch for Reshade 3.x.

Features:

  • Near plane bleed into focus plane
  • Advanced focusing helpers with hyperfocal near/far/focus planes blended using colors chosen by the user
  • Fine-grained control over blur in near and far plane as well as blur quality and amount of near-plane bleed
  • Auto focus and manual focus, where auto-focus can be driven by the mouse.
  • Focusing based on real camera aspects like focal length (1-300mm) and f-number (1-22)
  • Highlight extrapolation
  • Resolution stable
  • Circular bokeh only.

Some screenshots:

Focus overlay
rottr_2018_08_08_13_55_03_492

Near-plane bleed into focus plane
rottr_2018_08_08_13_56_55_540

rottr_2018_08_08_15_43_11_494

Highlight extrapolation
rottr_2018_08_08_14_49_59_542

Shader is roughly as fast as Marty's latest qUINT ADOF and in many cases faster (even though it uses 9 passes). I didn't compromise on resolution as I wanted the output to be as good as possible. I cited the papers/presentations I used in the code and commented as much as possible so others might learn from it, as I have learned during the writing of this shader.

I'm not a shader expert, I know I made mistakes somewhere and likely cut corners where I shouldn't have. Although I marked the shader internally as 'beta' I think it's usable in its current state. If there are bugs or other things I have to fix, please let me know :)

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 8, 2018

r57mgm
:/

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2018

@mineo210 I didn't namespace the samplers, will look into that, just a sec...

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2018

@mineo210 Can't reproduce it with the vanilla set of shaders. Do you have additional shaders in your shaders folder? In any case I'll look into adding a namespace to avoid name clashes.

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2018

@mineo210 could you redownload the shader and try again? I wrapped the code (and with it thus its samplers/textures) in its own namespace so no more nameclashes should occur

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 8, 2018

@FransBouma I barely use reshade so i dunno if quint's reshade,fxh file is vanilla or not but thats the only file i got int there combined with yours, ill redownload it and try again and see what happens

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2018

@mineo210 It's d3d9, not something else, see: https://reshade.me/forum/shader-presentation/4535-new-shader-cinematic-depth-of-field#29133

So I don't really know what to do to fix this, as it should work (I read the depth buffer in a vertex shader for optimization, but that causes the problem) other than rewrite lots of code for just d3d9 which I don't really want to do.

@crosire you have any ideas what I can do to work around this problem on d3d9? thanks :)

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 8, 2018

@FransBouma ohh, well as for now ill use it for other games that support directx11, awesome work btw

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 8, 2018

@mineo210 thanks! :)

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 9, 2018

Fixed the issue with d3d9 by adding a workaround for d3d9 with a conditional, so it pulls the depth for autofocus in the pixel shader instead. Less ideal but till the real issue is fixed in reshade, this is the better option .

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 9, 2018

@FransBouma so its working now?!

Tweaked the highlight curve a bit, it's now kicking in more gracefull…
…y and removes a nasty highlighted line on the edge of near and far plane.
@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 9, 2018

@mineo210 yes it should work in a d3d9 game now. I tested it in darksiders 1, a d3d9 game, which gave the same errors before this adjustment, it now works fine :)

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 9, 2018

@FransBouma tested it out right now on cod4 and its working perfectly, love it! good work!

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 9, 2018

@FransBouma oh and i tried to replicate your settings but cant really get it to look as yours does? does the cinematicdof use the already built in dof the game uses?
m0zpwf

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 9, 2018

@FransBouma Oh Nvm, I had to bump up the highlight gain and fiddle with the exposure, it looks beautiful

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 9, 2018

@mineo210 glad it works now! :) Yeah it requires some tweaking sometimes to get the right results. The highlights are something to get used to. I added some tweaks to the latest commit to make it less prominent near the focus plane

@sillycalvin

This comment has been minimized.

Copy link

commented Aug 9, 2018

@FransBouma Yeah I noticed that line as well but thought it was something wrong in my end, awesome work man!

@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 9, 2018

@mineo210 :) Yeah that line should now be gone in the latest code (which I pushed to this PR an hour ago)

@crosire

This comment has been minimized.

Copy link
Owner

commented Aug 10, 2018

On the workaround: You could do the following to enable the fast path on D3D9 again once the next ReShade version is released.

#if __RENDERER__ <= 0x9300 && __RESHADE__ <= 30400
// WAR code
#endif

This ensures the workaround is only active on ReShade 3.4.0 and earlier.

Finetuned the workaround for d3d9 to only affect reshade 3.4 or lower…
…. Finetuned the near highlight extrapolation a bit. Removed highlight threshold as it ruined the blur
@FransBouma

This comment has been minimized.

Copy link
Contributor Author

commented Aug 12, 2018

@crosire done :)

@crosire crosire merged commit 5c4e711 into crosire:master Aug 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.