How to connect DX11.Particles to lines in a sorted way?


#1

The output of the DX11.Particles Layer Emitter visually creates a grid (e.g. in emitter layer help):

I would like to connect the particles to lines, similar to this (which is"LineBuffered (DX11.Layer) help"):

But it seems like the position buffer is not sorted by the XY coordinates of the emitter. Using InstanceNoodles LineBuffered I just end up with jumbled up lines:

@tmp
Is there any way to sort the buffer in such a way? Or is DX11.Particles just not the right tool for this?

Thanks so much in advance!


#2

Due to the parallel execution of the compute shaders the particles are unordered by design.

If you need an ordering, you have to write a custom emitter where you introduce a new attribute (something like “customId” for example). The ids can be assigned with the help of the uv coordinates ( uint customId = uv.x + height * uv.y).

After the particlebuffers got rendered in the particlesystem node, you have to reorder the particlebuffer with a custom compute shader by the new customId. Perhaps you can have a look at existing post-buffer-render-nodes like AsAttributeBuffer or FiiterBuffer.

Unfortunately I have no time for that right now, so you have to try it on your own. But I am quite sure that it will work that way.


#3

Thank you @tmp! Sounds good.

I attempted to write the IDs into the buffer. I think it’s generally working:

p.customId = texId.x + Resolution.y * texId.y;

image

To create the above I used a white FullscreenQuad to fill the whole camera view of the emitter. There is a weird pattern on the grid. I think it’s a bug related to the calculation of textId in the emitter and reported it here already: https://github.com/letmp/dx11-particles/issues/9
I hope this also explains why some of the IDs are doubled up and some are 0. Fixing the bug hopefully fixes those particle IDs too.

Regarding the sorting, I found this old thread Particle Sorting Compute Shader Problems (RWBuffer feedback issue?) where people tried to get a few different algorithms going on the GPU. E.g. Bitonic, but they had issues. I had a play with those patches as well but didn’t manage to make them work. Any help would be highly appreciated!

I was also wondering if sorting the buffer is going to be super expensive?


#4

Hi jerry,

The Particle Sorting in the other thread you mentioned was especially for sorting back to front z-order and would be not possible to adapt to your problem.

it could be that you are also a bit far out already with what you are trying and there might be a much easyer way to achieve what you actually want to do.

What is it that you want to achieve in the end? maybe we can find an easyer way to do it


#5

Hi, i had a related problem with splines where i had to resort the format order of the buffer. Check in here there is a compute shader called sorter or similar there should be notes, you, ll find it. Maybe helpfull for your issue.


#6

@jerry I just fixed the bug in the Layer Emitter. The correct assignment of ids should work now.