FlorianRhiem / VFRendering

A vector field rendering library
https://florianrhiem.iffgit.fz-juelich.de/VFRendering/
MIT License
16 stars 4 forks source link

Alpha-value parameter for transparent renderers #10

Open GPMueller opened 6 years ago

GPMueller commented 6 years ago

Would this be reasonably easy to implement via the shaders, simply giving all a renderer's triangles an alpha value?

It would be useful for all renderers, but especially transparent isosurfaces would be a very cool feature, see for example this: image

FlorianRhiem commented 6 years ago

The big issue with transparency is the draw order dependency, which can cause various artifacts. According to the text in the link, the screenshot shows a completely on-GPU volume rendering feature, that is quite different to the drawing of precomputed triangle meshes.

As long as you are willing to do some manual adjustments to the order of renderers and don't expect mutually intersecting surfaces to be rendered correctly, normal alpha blending can still look acceptable. Here is a screenshot of what the demo looks like if all isosurfaces have 50% transparency: image The draw order dependency shows when I return this scene, as the X-Y-plane completely occludes the two isosurfaces instead of being 50% transparent: image And as the backface lighting and the order of triangles inside a single mesh are also important, artifacts like this can occur: image

If dealing with these issues and adjusting the scene to work around them is okay for you, I would suggest that I will add an OPACITY option of the IsosurfaceRenderer (the alpha value), with a default of 1.0.

FlorianRhiem commented 6 years ago

I have pushed an example implementation to feature-isosurface-transparency branch. This also makes face culling of isosurfaces more configurable. The updated demo shows a transparent isosurface around an opaque one.

GPMueller commented 6 years ago

The first image really looks very nice! This approach seems at least a good initial solution - most of the visualisations I had in mind can still work.

I had not thought of the "hiding" effect you show in the second image - this is quite an unfortunate effect... Could one deactivate this depth check individually (in the sense the arrow-renderer would still hide anything behind it, but the isosurfaces would not)? For 50% opacity that could be a workaround, as the colors would be mixed appropriately.

Do the visual artifacts in the last image only appear when shadowing is used in the shader?

FlorianRhiem commented 6 years ago

The artifacts in the last image are caused by the back facing triangles (the inside of the isosurface in this case) and the order in which triangles are drawn. When these faces are culled with the option added in the feature branch, they aren't drawn and cause no problems. If they are to be drawn for a graphic, one should adjust the lighting or at least flip the normals, and split up the isosurface into parts to ensure the correct drawing order. Shadows are not implemented in VFRendering.

Here is a similar image to the last one, taken with the feature branch: image

The artifacts are gone as the "inside" of the isosurface is not drawn. Splitting the isosurface to ensure a correct drawing order would still provide a better image, but that needs to be done dependent on the view, and this result is still quite nice. Here this would mean drawing the back half of the isosurface (of which we would see the inside) first with flipped normals, then the inner ring, then the front half (of which we see the outside).

The depth write could be disabled, so that transparent surfaces will no prevent the drawing of other objects, but will still be occluded by objects. The drawing order will still be very important for the outcome to look correct. The following image shows that it works, as the Y-Z-plane is now transparent regarding the two ring isosurfaces, but this also shows that the "open" isosurfaces look broken without their inside faces. image

With the inside faces, it appears correct from some angles: image And from other angles the artifacts from the third image appear again: image


I have added disabling of the depth write to the feature branch. Please try to see whether that works for you.