Guidance using lights

109 views
Skip to first unread message

role...@gmail.com

unread,
Apr 17, 2022, 9:30:27 AM4/17/22
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi Robert,

I'm trying to convert my existing code to use vsg::Lights and StateComposer. I think I understand most of it, but I'm confused about the lights. As an example, I've modified the vsgstatecomposer example (see attached) in an attempt to use a modifiable directionalLight.

Firstly, I added the light:

auto directionalLight = vsg::DirectionalLight::create();
directionalLight->name = "Sun Directional";
directionalLight->color.set(1.0, 1.0, 1.0);
directionalLight->intensity = 0.15;
directionalLight->direction.set(-0.58, -0.58, -0.58);

scenegraph->addChild(directionalLight);

Then I added a define:

auto& defines = graphicsPipelineConfig->shaderHints->defines;
defines.push_back("VSG_VIEW_LIGHT_DATA");

It already uses createPhongShaderSet, so the shader should be OK.

This results in the following errors after running ./vsgstatecomposer --debug

UNASSIGNED-CoreValidation-DrawState-DescriptorSetNotBound(ERROR / SPEC): msgNum: -840888189 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-DescriptorSetNotBound ] Object 0: handle = 0x55555719fbe0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xcde11083 | vkCmdDrawIndexed(): VkPipeline 0xe7713700000000ae[] uses set #1 but that set is not bound.
    Objects: 1
        [0] 0x55555719fbe0, type: 6, name: NULL
VUID-vkCmdDrawIndexed-None-02697(ERROR / SPEC): msgNum: -1735852301 - Validation Error: [ VUID-vkCmdDrawIndexed-None-02697 ] Object 0: handle = 0xe7713700000000ae, type = VK_OBJECT_TYPE_PIPELINE; Object 1: handle = 0xed367200000000ab, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; Object 2: handle = 0xed367200000000ab, type = VK_OBJECT_TYPE_PIPELINE_LAYOUT; | MessageID = 0x9888fef3 | vkCmdDrawIndexed(): VkPipeline 0xe7713700000000ae[] defined with VkPipelineLayout 0xed367200000000ab[] is not compatible for maximum set statically used 1 with bound descriptor sets, last bound with VkPipelineLayout 0xed367200000000ab[] The Vulkan spec states: For each set n that is statically used by the VkPipeline bound to the pipeline bind point used by this command, a descriptor set must have been bound to n at the same pipeline bind point, with a VkPipelineLayout that is compatible for set n, with the VkPipelineLayout used to create the current VkPipeline, as described in Pipeline Layout Compatibility (https://vulkan.lunarg.com/doc/view/1.2.189.0/linux/1.2-extensions/vkspec.html#VUID-vkCmdDrawIndexed-None-02697)

Most errors in the modified vsgstatecomposer and my own application refer to the shader using light data in slot 1 that isn't in the layout. The lighting data uses slot 1, whereas everything else uses slot 0. Am I missing something in the layout? Or, completely off track?

Thanks for your help.

Regards,
Roland
 

vsgstatecomposer.cpp

Robert Osfield

unread,
Apr 17, 2022, 10:35:42 AM4/17/22
to vsg-...@googlegroups.com
I'm only online briefly so can't check through your example.  As a general note when you want to use lights you'll need to enable to enable the light define and add the viewDescriptorLayout before the GraphicsPipelineConfig::init() so it's take into account, and add BindViewDependentState to the StateGroup.  Both the vsg::Builder and vsgXchange::assimp implementations have all the required code for setting this up so I would recommend looking at them.

With the vsgstaetcomposer example, it's been written for the purposes of testing the new code as it's been developed rather as an example that is easy to follow.  I'm thinking that we probably need several examples showing how to use ShaderSet/GraphicsPipelinConfig/SharedState. 

Robert Osfield

unread,
Apr 18, 2022, 6:01:36 AM4/18/22
to vsg-...@googlegroups.com
Hi Roland,

I've added the required code to configure the GraphicsPipelineConfig and assign the BindViewDescriptorSets() to the StateGroup.  I also added test code to disable the assignment of the default headlight and ambient light that the createCommandGraph(..) provides by default.  The modified example is attached.

The results suggest things are functional but they are still a bit odd, with the lighting saturating very quickly, it's not behaving like vsgbuilder does so something is amiss with the material or something else.  Flat quads aren't particularly interesting so I might be just expecting too much. I have other tasks to get on with today so I won't keep tinkering.

Cheers,
Robert.
vsgstatecomposer.cpp

Roland Hill

unread,
Apr 18, 2022, 9:15:10 PM4/18/22
to vsg-...@googlegroups.com
Hi Robert,

Thanks for your help! 

After your first hint a couple of days ago, I had much the same as you and kept getting crashes. The problem was that I was trying to just get it working and was going to put the SharedObjects in later. This use case is for a quadtree terrain, so the first zoomed out tile was working and then it would crash when I zoom in. So, this doesn't work for more than 1 (or a limited number of) tiles.

    vsg::ref_ptr<vsg::ViewDescriptorSetLayout> vdsl;
    vdsl = vsg::ViewDescriptorSetLayout::create();
    graphicsPipelineConfig->additionalDescrptorSetLayout = vdsl;

This does work
    vsg::ref_ptr<vsg::ViewDescriptorSetLayout> vdsl;
    vdsl = siApp::get()->_vsg->_sharedObjects->shared_default<vsg::ViewDescriptorSetLayout>();
    graphicsPipelineConfig->additionalDescrptorSetLayout = vdsl;

Also, I'm setting up an empty scene, viewer->compiling it, then adding subsequent branches using a DynamicLoadAndCompile setup, which might be causing issues as well. Before StateComposer I was able to run the entire scene without calling viewer->compile() and just using DynamicLoadAndCompile, but with the implementation of StateComposer I had to run viewer->compile at least once (even on an empty scene). 

I'm still having a few problems in that my texture isn't being displayed and I get a crash on exit, but that's the next issue to try and track down. My lighting also looks odd, but again, I can move on to these issues now.

Regards,
Roland




--
You received this message because you are subscribed to a topic in the Google Groups "vsg-users : VulkanSceneGraph Developer Discussion Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vsg-users/aQPcuhrocXQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vsg-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vsg-users/CAFN7Y%2BXVi0ettyaq4wmbk81YNVH8oELkhdQ6v8Ft5jy4x4MtfA%40mail.gmail.com.

Roland Hill

unread,
Apr 19, 2022, 1:11:40 AM4/19/22
to vsg-...@googlegroups.com
Hi Robert,

I found a problem with the ambient lighting calculation and sent a PR. 

Regards,
Roland


On Mon, 18 Apr 2022 at 20:01, Robert Osfield <robert....@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages