Different Uniform values for multiple scene objects #1417
-
Sorry for all the questions, just trying to align my knowledge of VSG with Vulkan... So I've got a single GraphicsPipeline with the standard PBR shaders. I want to use this pipeline to render multiple objects with the same shaders, but with slightly different uniform values. The end objective is to fade in objects by ramping the baseColorFactor's alpha over time. Objects will fade-in only once added to the scene. I'm curious how this can be done in VSG. I've got some code that does all the required set-up for each object, creating a StateGroup and childing a VertexIndexDraw. However I'm a bit lost when it comes to updating the uniforms for just that draw command. From what I've read, this is typically done by issuing a VkCmdUpdateBuffer command, which will update the values on the GPU. Does this command automatically get issued somewhere during Record traversal? How can I make sure that's happening? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I got the shader values updating, which is a step forward. So it's actually very interesting, and I think if someone else is also stuck on this I do advise reading this: It turns out that VSG has a really efficient way of tracking updates to buffers. It only does this when the buffer is marked as So the solution to my problem was the simply find the descriptor from the DescriptorSets (since I used I'll show that code below: auto ds = descriptorConfig->descriptorSets[1];
auto descriptorBuffer = ds->descriptors[0]->cast<vsg::DescriptorBuffer>();
if (descriptorBuffer)
{
auto bufferInfo = descriptorBuffer->bufferInfoList.front();
if (bufferInfo || bufferInfo->data)
{
// Access and modify the material struct
auto pbrValue = bufferInfo->data->cast<vsg::Value<vsg::PbrMaterial>>();
if (pbrValue)
{
// Prepare value for updating
pbrValue->properties.dataVariance = vsg::DYNAMIC_DATA;
}
}
} As a strong reminder, this needs to be done before Once that's done, everything updates like magic. However, this isn't the entire solution, since this will cause all objects in the scene to draw with the faded value. So something still needs to be done between draw calls to push those values out before the next draw call for other objects in the scene (or perhaps I need a different approach, such as using SSBOs or just using a bunch of DescriptorSets 😕) |
Beta Was this translation helpful? Give feedback.
This TransferTask dirty/update mechanism is designed for data that is updated between frames, rather than changes during the record traversal for the same texture/uniform/buffers.
Changing data between rendering calls is something best left to push constants, or data that is updated locally in GPU memory by a compute shader. This applies to general rendering works, not just VulkanSceneGraph applications.
If you want to render the same objects but with different sets of values then you are better off using different uniforms/texture/buffers/push constants.
As a general comment, there is usually lots of different ways to achieve the same end results with rendering algorithms so knowing wher…