Skip to content

Volumetric-rendering in avogadro project. #1979

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

perminder-17
Copy link
Contributor

@perminder-17 perminder-17 commented Mar 14, 2025

Some results which are good.

When the alpha is low.

simplescreenrecorder-2025-03-14_23.50.15.mp4

When the alpha is high.

simplescreenrecorder-2025-03-14_23.46.00.mp4

You can see I have changed the loop order in the cube, which is still not perfect and will break the flying-edges code so we need to find any workaround for it. Which means (different loop order for flying edges and different loop-order for volumetric rendering).

With original flying-edges loop order for cube data (BENZENE)

Screenshot from 2025-03-14 23-31-28

With updated loop order for cube data (BENZENE)

Screenshot from 2025-03-14 23-38-39

SOME TODO'S

  1. Resizing the framebuffers when we resize the screen.
  2. Updating the cube's data with correct loop order
  3. Scaling the volumetric mesh compared with the actual molecule rendered on the screen.
  4. Adding colors support from UI.
  5. Adding different sets of colors texture (2 colors, one for positive and one for negetive, @ghutchis will help in this. :) ).
  6. Cleanup in the code and removing unnecessary code blocks.

Signed-off-by: Perminder <[email protected]>

auto* volume = new VolumeGeometry;
qDebug() << "Volume data size: " << cube->data()->size();
// volume->initialize(800,600);

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@perminder-17
Copy link
Contributor Author

perminder-17 commented Mar 16, 2025

I tried fixing the looping order of the cube's data, still some work is left but here's the result. Let me know how it looks @matterhorn103 @ghutchis @cryos

Water (once we get different color maps, it will look more better (h2o-dense.cube)

Screencast.from.16-03-25.10.16.23.PM.IST.webm

Ammonia

Screencast.from.16-03-25.10.18.28.PM.IST.webm

crh206

Screenshot from 2025-03-16 22-21-45

Also, for water if you use h2o-elf.cube

You get Noel's version. here(https://baoilleach.blogspot.com/2011/08/electron-density-is-not-isosurface.html)

If color mappings are different, you can get the exact same appearance.

Screenshot from 2025-03-16 23-51-07

Screenshot from 2025-03-16 23-59-38

@ghutchis
Copy link
Member

Here's the compile issue.
cube.patch

@ghutchis
Copy link
Member

I'm running into some crashes on Mac with the VAO in the volume render. I think it's Mac-specific, so I'll do some reading / debugging.

  // Box geometry for front/back pass
  glGenVertexArrays(1, &d->volumeBoxVao);
  glBindVertexArray(d->volumeBoxVao);

The first line crashes. I'll investigate further.

@perminder-17
Copy link
Contributor Author

No problem geoff, I can also help. But, can you undo all the changes at cube.cpp file. (Like replacing cube.cpp file from actual main branch of cube.cpp file.) This will change the looping order and will crash some of the molecules, but you could still work on small molecules. Since the compile issue is with cube.cpp file.

@ghutchis
Copy link
Member

I mean, you can grab the cube.cpp file yourself: https://raw.githubusercontent.com/OpenChemistry/avogadrolibs/refs/heads/master/avogadro/core/cube.cpp

Or you can git checkout master then copy the cube.cpp file to another directory, switch back to your branch and move the cube.cpp file, etc.

(There are other ways to do this in git, but these are easy.)

@perminder-17
Copy link
Contributor Author

perminder-17 commented Mar 22, 2025

mean, you can grab the cube.cpp file yourself: https://raw.githubusercontent.com/OpenChemistry/avogadrolibs/refs/heads/master/avogadro/core/cube.cpp

Oops, I thought this will fix the compilation issue in your mac, but I think it's not related to the change I did in cube.cpp file.

Screencast.from.23-03-25.04.26.00.AM.IST.webm

This is the colorMapping I am trying @ghutchis @matterhorn103 @cryos

@perminder-17
Copy link
Contributor Author

Screencast.from.23-03-25.05.20.25.AM.IST.webm

Here's the structure for caffeine from caffeine.cube file.

@@ -0,0 +1,88 @@
#version 330 core
Copy link
Contributor Author

@perminder-17 perminder-17 Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to change the version. I'll fix this very soon, but @ghutchis do you think this could be the reason of compilation issue in macOS? Also, if not, I think we could include some more libraries as we did in other files
#include <GL/glew.h> or maybe more to fix this issue?

@perminder-17
Copy link
Contributor Author

perminder-17 commented Mar 23, 2025

Btw, @ghutchis I have lower the version in shaders. Can you take a look and also, I have link the colors (here's the result)

Screencast.from.23-03-25.09.44.34.AM.IST.webm

I could probably add a resolution as well as opacity meter in the future. Low resolution ( high fps) , High resolution (low fps).
I think for opacity meter, @ghutchis do you think it's necessary?

Signed-off-by: Perminder <[email protected]>
@ghutchis
Copy link
Member

I don't think it's needed to go back to an old shader version. The problem on the Mac isn't the shader version, it's that glGenVertexArrays, etc. are only available in 3.x or newer and Apple only provides 2.x in compatibility mode or 4.x in core profile.

So I'll set this up to only build for Windows and Linux right now, and push to update the remaining bits of code to use core profile.

@avo-bot
Copy link

avo-bot commented Mar 23, 2025

This pull request has been mentioned on Avogadro Discussion. There might be relevant details there:

https://discuss.avogadro.cc/t/volumetric-rendering-progress/6865/1

@ghutchis ghutchis added enhancement feature changes / API changes rendering labels Mar 25, 2025
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using some really old bits of code. Please replace this:
https://gist.github.com/ghutchis/41ab922e800a7c2f14a2cb64ad65cd20

Copy link
Member

@ghutchis ghutchis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor thing - it would be great to fix the qtplugins/CMakeLists.txt - you're using an old version for some reason...

@@ -0,0 +1,9 @@
#version 120
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably leave all these shaders as 330 core

@ghutchis
Copy link
Member

I'm trying on an Ubuntu VM - it seems when I resize the window, the volumetric cloud gets misaligned from the molecule:

Screenshot From 2025-03-25 16-33-22

@perminder-17
Copy link
Contributor Author

Screencast.from.28-03-25.06.20.00.AM.IST.webm

I think we were already having the correct width and height in the volumeGeometry class :"). I was thinking very complex logic to find it out but had an oversight that we already have them.

Signed-off-by: Perminder <[email protected]>
@perminder-17
Copy link
Contributor Author

Hi @ghutchis , do you mind checking it once again then I could probably work on code cleanups.

@matterhorn103
Copy link
Contributor

matterhorn103 commented Mar 28, 2025

I'm trying on an Ubuntu VM - it seems when I resize the window, the volumetric cloud gets misaligned from the molecule:

Screenshot From 2025-03-25 16-33-22

I believe this is actually part of an existing problem and applies to all displayed orbitals, it's not isolated to the volumetric renderer. Does it also happen for you with isosurfaces?

I noticed it a little while ago and just hadn't got round to making an issue for it yet.

(I figured there's enough more urgent issues that I didn't need to rush with the bug report.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature changes / API changes rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants