Add depth-of-field fog or blurring rendering options

@ghutchis Thank you for taking this into consideration. I would be delighted to incorporate this feature into the codebase.

1 Like

For others, this is in regards to this long-standing issue: Add depth-of-field fog or blurring rendering options · Issue #347 · OpenChemistry/avogadrolibs · GitHub

As an example, Speck has blurring options to indicate depth of field (e.g., an out-of-focus look)

This would be great - much appreciated!

Hello @ghutchis , apologies for the delay; I’ve been occupied with work. I plan to delve deeper into the codebase and contemplate the shader logic required for our task. We’ll develop a shader, integrate it with the framebuffers, and ensure all necessary uniforms are appropriately passed. This is just a preliminary thought and might evolve as I gain more insight into the codebase. Perhaps I could create a Pull Request when the work is halfway done and commit the changes whenever I find time. You may also have a look into my PR:)

The logic which I was thinking for the shaders which will look for depth-blur was:-

  1. We’ll find the z value at the target pixel.
  2. Calculate the target pixel’s blur radius given that z.
  3. Sample nearby pixels within the maximum blur radius.
  4. For each nearby Pixels;-
    a. We will be getting the sample’s z value.
    b. Get the sample’s blur radius from its z.
    c. To blur this pixel’s colour with nearby colours that are behind it: if the sample
    is farther back than the target pixel add the sample’s colour to the mix if it’s
    within the target pixel’s blur radius.
    d. To make sure blur from nearby pixels in front of us are still visible on top: if the
    sample is closer than the target pixel, add the sample’s colour to the mix if it’s
    within the sample pixel’s blur radius.

If I have any doubts, I’ll ask for assistance here. Let me know if you think I’m on the right track. Also do you think I should consider some extra things before implementing the plan?

Also just to note @ghutchis, the logic above is for single-pass blur and I want to explain why I’m considering adding a single-pass blur instead of a two-pass blur in the shader. Maybe a single-pass blur could be better in this case because:

Upon further consideration, I’ve come to realize some challenges with implementing a two-pass shader for blur effects. Firstly, an unexpected issue arises where small holes in the model result in a faint cross-shaped pattern in the blur. This occurs because the blur is applied both vertically and horizontally, creating a hazier “plus” pattern.

Secondly, after some research, it becomes apparent that in a two-pass blur, the information from each blurred pixel referenced in the second pass contains contributions from multiple samples and depths from the first pass. This makes it difficult to replicate the blur with the same precision in subsequent steps.

As a result, it appears that many PC games opt for a single-pass depth blur, likely due to these complexities encountered with the two-pass approach.

The idea of an adjustable selective focus as in the example/preview of speck would really be an attractive feature (a bit like the tilt-shift lens scenes about Hudson river, central park etc. of NYC in Colbert’s intro). At first glance, I thought speck continues some of the work of QuteMol which aimed for proteins.

Apologies for the delay in completing this task. I’ve been occupied with drafting a proposal and managing my university exams.
So, Hi @ghutchis and @Thomas , I’ve implemented depth blur in our project and would like your input on how users will interact with it.

When molecule is too far from the camera, it appears blur.

When The molecule is too near to the camera, it appears blur.

Currently, I’ve added a checkbox below the ambient occlusion option to enable/disable depth blur. However, considering our plans to introduce fog in the future, I’m wondering if this placement works or if you have alternative suggestions.

I propose that we keep the number of samples, near and far planes hardcoded, as they align with our requirements. For user interaction, I suggest providing a slider for adjusting blur intensity. What are your thoughts on this? To ensure smooth user experience, how can one easily toggle the blur effect on and off, and adjust its intensity as needed?

Currently that dialog is under View ⇒ Rendering:

The code is in avogadroapp: (renderingdialog.*)

Personally, I might want to disable this – I guess I’d have to try it on a few molecules to get a feel for it.

Okay, so the PR is ready. I’ll still do the optimization and some cleanups left but would be great @ghutchis if you share your review on how the blur works. Mind looking at how the result looks like, let me know what changes you need? Also, still needs some work on the pr on adding strength, new-uniforms, adjusting the samples etc etc.

Is there any way I can share you the .Appimage or .dmg file after adding depth-of-field so that you can check that out and let me know what’s required next? It would be easy for you to review the PRs🙂

Those come up from the auto-builds. Unfortunately it’s the end of our semester, so things have been incredibly busy. Things will become less busy soon.

Thanks for your work and your patience!

1 Like