سؤال

I'm trying to make a deformable voxel terrain for a project for University. I'm currently using a number 3DTextures to hold my voxel data in "chunks". My plan was to use the compute shader to perform the marching cubes algorithm on said voxel data and output vertices into a buffer that can then be rendered each frame.

The problem is that in order to set up a UAV for the structured buffer I'm using I need to know how many elements it will have for the D3D11_BUFFER_UAV's NumElements. I can make a guess as to the maximum it's likely to contain, but I have no way of knowing how many it actually will until after the compute shader is finished and it's occurred to me that this might not be the best way of solving the problem.

All I really need to do is get the compute shader to ouput an arbitrary number of vertices which can be stored and rendered later, any ideas on the best way to do this?

هل كانت مفيدة؟

المحلول

Seems like the best way to do this is using an append buffer. You have to be careful that you're not relying on the order that you're appending elements as the multi-threadedness is designed specifically to allow things to be added in at random. I had to append the data one Triangle at a time, which stops me from using an index buffer but I couldn't see any other way to do this.

If anyone comes up with a better solution I'd be happy to hear it.

نصائح أخرى

In my voxel engine I had the same problem, initially I allocated the buffers to be able to contain the maximum number of vertices which could possibly be generated.

After I had things working, I play tested it with the noise functions I planned to use and made a note of the highest number of vertices which were required by a vertex buffer.

I then just added a bit on and used that value as the size of all vertex buffers in my application.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top