Blender Git Commit Log
Git Commits -> Revision 000a340
Revision 000a340 by Clément Foucault (master) February 12, 2021, 21:35 (GMT) |
EEVEE: Depth of field: New implementation This is a complete refactor over the old system. The goal was to increase quality first and then have something more flexible and optimised. |{F9603145} | {F9603142}|{F9603147}| This fixes issues we had with the old system which were: - Too much overdraw (low performance). - Not enough precision in render targets (hugly color banding/drifting). - Poor resolution near in-focus regions. - Wrong support of orthographic views. - Missing alpha support in viewport. - Missing bokeh shape inversion on foreground field. - Issues on some GPUs. (see T72489) (But I'm sure this one will have other issues as well heh...) - Fix T81092 I chose Unreal's Diaphragm DOF as a reference / goal implementation. It is well described in the presentation "A Life of a Bokeh" by Guillaume Abadie. You can check about it here https://epicgames.ent.box.com/s/s86j70iamxvsuu6j35pilypficznec04 Along side the main implementation we provide a way to increase the quality by jittering the camera position for each sample (the ones specified under the Sampling tab). The jittering is dividing the actual post processing dof radius so that it fills the undersampling. The user can still add more overblur to have a noiseless image, but reducing bokeh shape sharpness. Effect of overblur (left without, right with): | {F9603122} | {F9603123}| The actual implementation differs a bit: - Foreground gather implementation uses the same "ring binning" accumulator as background but uses a custom occlusion method. This gives the problem of inflating the foreground elements when they are over background or in-focus regions. This is was a hard decision but this was preferable to the other method that was giving poor opacity masks for foreground and had other more noticeable issues. Do note it is possible to improve this part in the future if a better alternative is found. - Use occlusion texture for foreground. Presentation says it wasn't really needed for them. - The TAA stabilisation pass is replace by a simple neighborhood clamping at the reduce copy stage for simplicity. - We don't do a brute-force in-focus separate gather pass. Instead we just do the brute force pass during resolve. Using the separate pass could be a future optimization if needed but might give less precise results. - We don't use compute shaders at all so shader branching might not be optimal. But performance is still way better than our previous implementation. - We mainly rely on density change to fix all undersampling issues even for foreground (which is something the reference implementation is not doing strangely). Remaining issues (not considered blocking for me): - Slight defocus stability: Due to slight defocus bruteforce gather using the bare scene color, highlights are dilated and make convergence quite slow or imposible when using jittered DOF (or gives ) - ~~Slight defocus inflating: There seems to be a 1px inflation discontinuity of the slight focus convolution compared to the half resolution. This is not really noticeable if using jittered camera.~~ Fixed - Foreground occlusion approximation is a bit glitchy and gives incorrect result if the a defocus foreground element overlaps a farther foreground element. Note that this is easily mitigated using the jittered camera position. |{F9603114}|{F9603115}|{F9603116}| - Foreground is inflating, not revealing background. However this avoids some other bugs too as discussed previously. Also mitigated with jittered camera position. |{F9603130}|{F9603129}| - Sensor vertical fit is still broken (does not match cycles). - Scattred bokeh shapes can be a bit strange at polygon vertices. This is due to the distance field stored in the Bokeh LUT which is not rounded at the edges. This is barely noticeable if the shape does not rotate. - ~~Sampling pattern of the jittered camera position is suboptimal. Could try something like hammersley or poisson disc distribution.~~Used hexaweb sampling pattern which is not random but has better stability and overall coverage. - Very large bokeh (> 300 px) can exhibit undersampling artifact in gather pass and quite a bit of bleeding. But at this size it is preferable to use jittered camera position. Codewise the changes are pretty much self contained and each pass are well documented. However the whole pipeline is quite complex to understand from bird's-eye view. Notes: - There is the possibility of using arbitrary bokeh texture with this implementation. However implementation is a bit involved. - Gathering max sample count is hardcoded to avoid to deal with shader variations. The actual max sample count is already quite high but samples are not evenly distributed due to the ring binning method. - While this implementation does not need 32bit/channel textures to render correctly it does use many other textures so actual VRAM usage is higher than previous method for viewport but less for render. Textures are reused to avoid many allocations. - Bokeh LUT computation is fast and done for each redraw because it can be animated. Also the texture can be shared with other viewport with different camera settings. |
Commit Details:
Full Hash: 000a340afa67a12a38c103e19f7d52ed42c4492e
Parent Commit: dd2ff26
Lines Changed: +3478, -586
12 Added Paths:
/source/blender/draw/engines/eevee/shaders/effect_dof_bokeh_frag.glsl (+101, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_dilate_tiles_frag.glsl (+117, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_downsample_frag.glsl (+37, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_filter_frag.glsl (+93, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_flatten_tiles_frag.glsl (+57, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_gather_frag.glsl (+293, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl (+631, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_reduce_frag.glsl (+179, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_resolve_frag.glsl (+212, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_scatter_frag.glsl (+85, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_scatter_vert.glsl (+138, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_setup_frag.glsl (+65, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_dilate_tiles_frag.glsl (+117, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_downsample_frag.glsl (+37, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_filter_frag.glsl (+93, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_flatten_tiles_frag.glsl (+57, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_gather_frag.glsl (+293, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_lib.glsl (+631, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_reduce_frag.glsl (+179, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_resolve_frag.glsl (+212, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_scatter_frag.glsl (+85, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_scatter_vert.glsl (+138, -0) (View)
/source/blender/draw/engines/eevee/shaders/effect_dof_setup_frag.glsl (+65, -0) (View)
2 Deleted Paths:
/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl (+0, -254)
/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl (+0, -109)
/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl (+0, -109)
17 Modified Paths:
/release/scripts/startup/bl_ui/properties_render.py (+9, -2) (Diff)
/source/blender/blenloader/intern/versioning_290.c (+8, -0) (Diff)
/source/blender/draw/CMakeLists.txt (+12, -2) (Diff)
/source/blender/draw/engines/eevee/eevee_depth_of_field.c (+931, -121) (Diff)
/source/blender/draw/engines/eevee/eevee_effects.c (+3, -5) (Diff)
/source/blender/draw/engines/eevee/eevee_engine.c (+9, -4) (Diff)
/source/blender/draw/engines/eevee/eevee_private.h (+114, -18) (Diff)
/source/blender/draw/engines/eevee/eevee_render.c (+1, -1) (Diff)
/source/blender/draw/engines/eevee/eevee_shaders.c (+198, -38) (Diff)
/source/blender/draw/engines/eevee/eevee_temporal_sampling.c (+58, -5) (Diff)
/source/blender/draw/engines/eevee/shaders/common_utiltex_lib.glsl (+6, -0) (Diff)
/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl (+2, -7) (Diff)
/source/blender/draw/intern/shaders/common_math_lib.glsl (+41, -11) (Diff)
/source/blender/draw/tests/shaders_test.cc (+23, -6) (Diff)
/source/blender/makesdna/DNA_scene_defaults.h (+3, -0) (Diff)
/source/blender/makesdna/DNA_scene_types.h (+5, -1) (Diff)
/source/blender/makesrna/intern/rna_scene.c (+47, -2) (Diff)
/source/blender/blenloader/intern/versioning_290.c (+8, -0) (Diff)
/source/blender/draw/CMakeLists.txt (+12, -2) (Diff)
/source/blender/draw/engines/eevee/eevee_depth_of_field.c (+931, -121) (Diff)
/source/blender/draw/engines/eevee/eevee_effects.c (+3, -5) (Diff)
/source/blender/draw/engines/eevee/eevee_engine.c (+9, -4) (Diff)
/source/blender/draw/engines/eevee/eevee_private.h (+114, -18) (Diff)
/source/blender/draw/engines/eevee/eevee_render.c (+1, -1) (Diff)
/source/blender/draw/engines/eevee/eevee_shaders.c (+198, -38) (Diff)
/source/blender/draw/engines/eevee/eevee_temporal_sampling.c (+58, -5) (Diff)
/source/blender/draw/engines/eevee/shaders/common_utiltex_lib.glsl (+6, -0) (Diff)
/source/blender/draw/engines/workbench/shaders/workbench_effect_dof_frag.glsl (+2, -7) (Diff)
/source/blender/draw/intern/shaders/common_math_lib.glsl (+41, -11) (Diff)
/source/blender/draw/tests/shaders_test.cc (+23, -6) (Diff)
/source/blender/makesdna/DNA_scene_defaults.h (+3, -0) (Diff)
/source/blender/makesdna/DNA_scene_types.h (+5, -1) (Diff)
/source/blender/makesrna/intern/rna_scene.c (+47, -2) (Diff)