pass vertexbuffer and indexbuffer into the ssbo #944
-
The ray-tracing code, like this model's vertexbuffer and indexbuffer, is passed into the ssbo as shown in the figure below. How do I pass vertexbuffer and indexbuffer into the ssbo using vsg。 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I have attempted the combination of usage you are trying, the closest example I can think of is vsgcomputevertex that uses VK_DESCRIPTOR_TYPE_STORAGE_BUFFER for passing data from a compute shader to the vertex shader, do a search for all the instances of VK_DESCRIPTOR_TYPE_STORAGE_BUFFER to see it how the DescriptorBuffer is setup and used: |
Beta Was this translation helpful? Give feedback.
-
Hi I'm also trying to create a buffer to read in the closest hit shader. auto colors = vsg::vec3Array::create(
{{1.0f, 0.0f, 1.0f},
{0.0f, 1.0f, 1.0f},
{1.0f, 1.0f, 0.0f}});
VkDeviceSize bufferSize = sizeof(vsg::vec3) * 3;
auto buffer = vsg::createBufferAndMemory(device, bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_SHARING_MODE_EXCLUSIVE, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
auto bufferInfo = vsg::BufferInfo::create();
bufferInfo->buffer = buffer;
bufferInfo->offset = 0;
bufferInfo->range = bufferSize;
bufferInfo->data = colors;
bufferInfo->copyDataToBuffer(device->deviceID); vsg::DescriptorSetLayoutBindings descriptorBindings{ [...], {3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR, nullptr}};
auto storageBufferDescriptor = vsg::DescriptorBuffer::create(vsg::BufferInfoList{bufferInfo}, 3, 0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); And in the closest hit shader I can read the first color with layout(binding = 3, set = 0) buffer Colors { vec3 v[]; } cols;
void main()
{
hitValue = cols.v[0];
} And also I have a completely different issue, if I read a GLTF model I don't know how to get vertices and indices and other data from the scene after it is loaded with |
Beta Was this translation helpful? Give feedback.
-
The author's answer is quite correct. I am currently only in the testing phase, modifying the code of vsg's acceleration structure. From the acceleration structure. This is only for temporary use. The author's way is right. Here's how I do it, |
Beta Was this translation helpful? Give feedback.
I have attempted the combination of usage you are trying, the closest example I can think of is vsgcomputevertex that uses VK_DESCRIPTOR_TYPE_STORAGE_BUFFER for passing data from a compute shader to the vertex shader, do a search for all the instances of VK_DESCRIPTOR_TYPE_STORAGE_BUFFER to see it how the DescriptorBuffer is setup and used:
https://github.com/vsg-dev/vsgExamples/blob/master/examples/state/vsgcomputevertex/vsgcomputevertex.cpp#L77