mortacious / pyvista-imgui

Pyvista imgui integration
MIT License
13 stars 1 forks source link

Transparency #5

Open sahlbergnielsen opened 2 months ago

sahlbergnielsen commented 2 months ago

Transparency in the ImguiPlotter shows up different than in Plotter from pyvista

from pyvista_imgui import ImguiPlotter
import pyvista as pv
pl = ImguiPlotter()
sphere = pv.Sphere()
pl.add_mesh(sphere, render=False, opacity=0.5)
pl.view_isometric()
pl.show()

image

import pyvista as pv
pl = pv.Plotter()
sphere = pv.Sphere()
pl.add_mesh(sphere, render=False, opacity=0.5)
pl.view_isometric()
pl.show()

image

mortacious commented 2 months ago

Hey, thanks for opening this issue. This different appearance is probably due to a small inconsistency between Pyvista and VTK. Fortunately it can be fixed easily by just enabling depth peeling:

from pyvista_imgui import ImguiPlotter
import pyvista as pv
pl = ImguiPlotter()
sphere = pv.Sphere()
pl.add_mesh(sphere, render=False, opacity=0.5)
pl.view_isometric()
pl.enable_depth_peeling()
pl.show()

By default this is disabled for the default pyvista theme which is also re-used by this package, but the underlying VTK renderer still seems to enable it.

Screenshot from 2024-04-05 15-00-28

sahlbergnielsen commented 2 months ago

Great! Thanks a lot for the trick! Cool library you made!

sahlbergnielsen commented 2 months ago

For large meshes and with depth peeling enabled I notice that the framerate throttles and drops quite a bit every 1-2 second or so. This is the case both with the pyvista plotter and the imgui plotter

from pyvista_imgui import ImguiPlotter
from pyvista import examples
import pyvista as pv

nefertiti = examples.download_nefertiti()

pl = ImguiPlotter()
pl.add_mesh(nefertiti, opacity=0.5, color='lightgrey')
pl.view_isometric()
pl.enable_depth_peeling()
pl.show()

bracket

The same framerate drop is seen also when using the pyvista plotter

from pyvista_imgui import ImguiPlotter
from pyvista import examples
import pyvista as pv

example = examples.download_pump_bracket()

pl = pv.Plotter()
pl.add_mesh(example, opacity=0.5, color='lightgrey')
pl.view_isometric()
pl.enable_depth_peeling()
pl.show()

with no call to pl.enable_depth_peeling() framerate is good and transparency works.

from pyvista_imgui import ImguiPlotter
from pyvista import examples
import pyvista as pv

example = examples.download_pump_bracket()

pl = pv.Plotter()
pl.add_mesh(example, opacity=0.5, color='lightgrey')
pl.view_isometric()
pl.show()
mortacious commented 2 months ago

Unfortunately, I was not able to reproduce the problem. It could be a Windows-specific problem though. As it is happening with the regular Plotter es well, it is likely, that the issue lies deeper within the VTK stack.