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

@perminder-17 In the recent days, I used the optional edge outline, and ambient occlusion of the view → rendering menu you introduced to Avogadro. Are you going to amend the documentation (for instance view menu for/on https://two.avogadro.cc) accordingly?

A general overhaul of the documentation is ongoing, as there is a lot to change and add to get it up to scratch for 2.0. But yes, I’ll make sure this gets added.

Yes, and I just merged a bunch of patches from @perminder-17 including depth-aware blur and fog. :rocket:

Keeping the docs up-to-date is sadly a never-ending quest right now.

1 Like

I mean, when the docs are so far behind the current development status, it tends to be quite daunting, and making small updates to reflect small additions or changes to the program is difficult without a base already in place. So I’m hoping that once the docs are in a good place (which I promise I’ll get them to) then keeping them up-to-date will be a lot more manageable.

1 Like

@matterhorn103 In case of the depth-of-blur and fog, I didn’t see PR 86 but now and only because of a visit of the GitHub page, i.e. leaving the two.avogadro.cc page. It doesn’t display the widget though (but on the other hand, doesn’t refer to the elder Avogadro1 GUI either, too).

Yep, it needs covering somewhere other than just “What’s New” though right, as people will only visit those pages a maximum of once, so they are a poor reference.