-
Notifications
You must be signed in to change notification settings - Fork 807
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
DoF optimisation #8057
base: master
Are you sure you want to change the base?
DoF optimisation #8057
Conversation
Thanks for this. Could you please provide some more detail on what testing has been done and on what plaforms? |
I'm still experimenting with various optimisations before testing more platforms. Once ready, I will likely test on Android (GLES - Vulkan), iOS (Metal, iPhone 8), macOS, Windows (D3D11, D3D12, Vulkan, GL), PS5, Switch. Unfortunately I don't have access to XR devices, so will do on emulator instead (virtual HMD). |
That sounds great, thank you! 👍 |
The original blending formula between DoF texture and source image is flawed but this fix tries to keep the new results as similar as possible.
Purpose of this PR
The main optimisation is to dynamically select the number of samples to generate the bokeh, depending on the max amount of bokeh around neighbouring pixels.
This makes the performance of the effect scales depending on the number of blur on screen. The performance is improved by 40% for usual DoF setup when using KERNEL_VERY_LARGE option (4 rings, 71 samples).
This requires an extra step to downsample the CoC texture a few mip levels. The cost of the extra step is compensated by the performance gain when generating the bokeh.
The shader code was also further optimised:
Testing status
DoF output is mostly changed.
A slight difference is the blending between foreground out-of-focus pixels into in-focus pixels. The original code uses a solution which generate different results depending on the number of kernel samples. As the number of kernel samples is now dynamic, I implemented a slightly different blending strategy but which gives very close results.
Note that the original solution to decide the blending is flawed, so there was no possible clean fix for it.
TODO: test on many platforms
Comments to reviewers