Transparency

318 views
Skip to first unread message

Denis Taniguchi

unread,
Feb 23, 2022, 4:56:49 AM2/23/22
to vsg-...@googlegroups.com
Hi Robert,

Should transparency be working? I know we currently have alpha clip, but
do we have alpha blend?

Cheers,


Denis

Robert Osfield

unread,
Feb 23, 2022, 5:07:29 AM2/23/22
to vsg-...@googlegroups.com
On Wed, 23 Feb 2022 at 09:56, 'Denis Taniguchi' via vsg-users : VulkanSceneGraph Developer Discussion Group <vsg-...@googlegroups.com> wrote:
Should transparency be working? I know we currently have alpha clip, but
do we have alpha blend?

Yes, blending is working, you can also depth sort transparent subgraphs. The vsgExamples/data/model/lz.vsgt model illustrates both.
 

Robert Osfield

unread,
Feb 23, 2022, 5:55:03 AM2/23/22
to vsg-...@googlegroups.com
I probably need to add that while the core VSG might support transparency if a loader isn't setting blending a model won't have blending on it.  For blending in Vulkan you need to set up the vsg::GraphicsPipeline so that it uses a vsg::ColorBlendState (which maps to VkPipelineColorBlendStateCreateInfo when setting up the pipeline):

vsg::ColorBlendState:

VkPipelineColorBlendStateCreateInfo:

Note how exactly the same types and order are used in vsg::ColorBlendState, this is generally how the VSG maps to Vukan - as directly as possible, and if exactly the same data structure is not possible then an equivalent one with same data types etc is used, plus all the scene graph related integration.

Writing a file out to .vsgt and then having a browse through it, doing a search for keywords like ColorBlendState will be helpful when working out whether the settings you are expecting are being used. i.e:

   vsgconv mymodel.gltf mymodel.vsgt
   myfavoriteeditor mymodel.vsgt

Hope this helps,
Robert.

Denis Taniguchi

unread,
Feb 23, 2022, 1:08:10 PM2/23/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi Robert,

Thanks for clarifying.
Apparently the assimp loader doesn't yet allow transparent materials. Is that correct?
assimp.cpp:833 doesn't set enableBlend parameter for createPipeline function, and the default is false.
I have checked that for gltf files, assimp puts blend mode in a material property named "$mat.gltf.alphaMode".
I could check that and enable blending, but that would work just for gltf files.
material->Get(AI_MATKEY_OPACITY, opacity) and material->Get(AI_MATKEY_BLEND_FUNC, blendMode) are not present.
Can I add a function in assimp.cpp for checking for alpha blending that will look for keys like "$mat.gltf.alphaMode" and act accordingly?
Cheers,

Denis

Robert Osfield

unread,
Feb 23, 2022, 1:48:06 PM2/23/22
to vsg-...@googlegroups.com
Hi Denis,

On Wed, 23 Feb 2022 at 18:08, 'Denis Taniguchi' via vsg-users : VulkanSceneGraph Developer Discussion Group <vsg-...@googlegroups.com> wrote:
Apparently the assimp loader doesn't yet allow transparent materials. Is that correct?
assimp.cpp:833 doesn't set enableBlend parameter for createPipeline function, and the default is false.
I have checked that for gltf files, assimp puts blend mode in a material property named "$mat.gltf.alphaMode".
I could check that and enable blending, but that would work just for gltf files.
material->Get(AI_MATKEY_OPACITY, opacity) and material->Get(AI_MATKEY_BLEND_FUNC, blendMode) are not present.
Can I add a function in assimp.cpp for checking for alpha blending that will look for keys like "$mat.gltf.alphaMode" and act accordingly?

I'm not the original author of the Assimp loader, so like you, have to read the source and look at Assimp headers, and what the loader generates for different models.  What you describe sounds sensible but I can't confirm it's definitely the best approach without reviewing the relevant code and trying out some models.

tt's probably most efficient for you to modify vsgXchange to get it working in the way you think is correct for your models, generate a PR for this on vsgXchange on github and I then can do a review and check up on Assimp code and do some testing at my end.  It's be useful if you could probably pointers to which models you expect to have transparency and which ones don't so I can test things out.
 
Cheers,
Robert.

Gao ZhiHua

unread,
Feb 23, 2022, 8:47:10 PM2/23/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Pretty good result : 
alpat.png

Gao ZhiHua

unread,
Feb 23, 2022, 8:50:49 PM2/23/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Major change is to add depth sort node:

                const auto material = scene->mMaterials[mesh->mMaterialIndex];
                aiString alphaMode;
                float opacity = 1.0;
                if ((material->Get(AI_MATKEY_GLTF_ALPHAMODE, alphaMode) == AI_SUCCESS && alphaMode == aiString("BLEND"))
                    || (material->Get(AI_MATKEY_OPACITY, opacity) == AI_SUCCESS && opacity < 1.0))
                {
                    vsg::ComputeBounds computeBounds;
                    stategroup->accept(computeBounds);
                    vsg::dvec3 center = (computeBounds.bounds.min + computeBounds.bounds.max) * 0.5;
                    double radius = vsg::length(computeBounds.bounds.max - computeBounds.bounds.min) * 0.5;

                    auto depthSorted = vsg::DepthSorted::create();
                    depthSorted->binNumber = 10;
                    depthSorted->bound.set(center[0], center[1], center[2], radius);
                    depthSorted->child = stategroup;
                    xform->addChild(depthSorted);
                }
              ......

Denis Taniguchi

unread,
Feb 25, 2022, 7:26:10 AM2/25/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi,

Google was reporting vsg-users emails as spam, so hadn't got notified about this. :(
Thanks for this! Has this been pushed already?
Cheers,

Denis

Robert Osfield

unread,
Feb 25, 2022, 8:11:03 AM2/25/22
to vsg-...@googlegroups.com
On Fri, 25 Feb 2022 at 12:26, 'Denis Taniguchi' via vsg-users : VulkanSceneGraph Developer Discussion Group <vsg-...@googlegroups.com> wrote:
Google was reporting vsg-users emails as spam, so hadn't got notified about this. :(
Thanks for this! Has this been pushed already?

I haven't received any PR for vsgXchange so nothing has been merged with the main vsgXchange repo.
 

Denis Taniguchi

unread,
Feb 25, 2022, 8:16:03 AM2/25/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
On that matter, what is the best way to contribute?
Fork and PR from there, or directly from vsg-dev/vsg? But second option requires write access to vsg I think.
Cheers,

Denis

Robert Osfield

unread,
Feb 25, 2022, 9:23:32 AM2/25/22
to vsg-...@googlegroups.com
Hi Denis,

On Fri, 25 Feb 2022 at 13:16, 'Denis Taniguchi' via vsg-users : VulkanSceneGraph Developer Discussion Group <vsg-...@googlegroups.com> wrote:
On that matter, what is the best way to contribute?
Fork and PR from there, or directly from vsg-dev/vsg? But second option requires write access to vsg I think.

Fork and PR is the way for vsg-dev/vsg.  I am the only writer to the core VSG project, this way I can review and manage all changes to the core VSG and make sure that they form a coherent whole, or at least tend towards one.

If some of the additional vsg libraries begin to be heavily contributed to/handled by members of the VSG community then it may be appropriate for them to take over management of that project, or to get direct write access.

Cheers,
Robert.

Denis Taniguchi

unread,
Mar 7, 2022, 5:08:56 AM3/7/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi Robert,
Forgot to mention I did a pull request for this a couple of days ago:
Thanks,

Denis

Robert Osfield

unread,
Mar 7, 2022, 5:53:22 AM3/7/22
to vsg-...@googlegroups.com
On Mon, 7 Mar 2022 at 10:08, 'Denis Taniguchi' via vsg-users : VulkanSceneGraph Developer Discussion Group <vsg-...@googlegroups.com> wrote:
Hi Robert,
Forgot to mention I did a pull request for this a couple of days ago:

I am aware of the PR - I get notified as well as check regularly.  If I'm working on a complex work I'll defer merging till I have cleared that work so I don't end up with a frazzled brain from trying to multi-task topics too much.

I'll merge today or tomorrow.  Is there a good test model I should use to confirm before/after results?

Cheers,
Robert.
 

Denis Taniguchi

unread,
Mar 7, 2022, 6:14:23 AM3/7/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
FlightHelmet! :)
With the patch:
Screenshot from 2022-03-07 11-04-07.png
Without:
Screenshot from 2022-03-07 11-06-06.png

Robert Osfield

unread,
Mar 7, 2022, 7:58:23 AM3/7/22
to vsg-...@googlegroups.com
Thanks for the pointer and screenshot, a useful QA for when I do my review.
Reply all
Reply to author
Forward
0 new messages