1
votes

For a physics particle system simulation, I'm wanting to optimize a WebGL2 program. I want to know if it is faster to adjust vertice positions using a transformfeedback accessing a 3D-texture, setting my position to be, for example, "color.r" from a pixel of the texture, or alternatively, dumping the entire 3D-texture back to the CPU and extracting position values for all the vertices from the texture, and resubmitting the new vertice array to the GPU for processing on the subsequent draw cycle.

Being a beginner, I'm clueless as to what would be faster. I need to use a texture because my position calculation requires knowing the positions of 26 neighbor particles relative to the vertex being calculated.

I have no code to show. I'm hoping for guidance for an approach before I write code for either approach.

My intuition says that staying on the GPU rather than pumping 1,000,000 vertices (minimum) worth of data back and forth each draw cycle would be faster, but this is a newbie intuition and I prefer to get guidance from someone who has confidence in his knowledge.

In WebGL2 you can easily access in texel in a texture with the texelFetch instruction. vec4 color = texelFetch(someSamper, ivec3(intX, intY, intZ), mipLevel); use ivec2 if it'd 2D texture. Given the values are in a texture though it seems like you'd render with fragment shaders, one draw call per N slices. Seems like you asked that question here stackoverflow.com/questions/55815145/…. I can't imagine how transform feedback would be faster for this case but maybe I don't understand what you're trying to dogman
I'm using the fragment shader (per your other answer) to generate the texture each cycle in a transformfeedback framebuffer. Can I also change my vertex position array in the fragment shader? I AM using POINTS in my transformfeedback, so there is a 1-1 correspondence to times VS and FS are invoked. If I can change my vertex position array from the FS, I can do all the work in the FS. I had assumed that I could NOT change my vertex position array in the FS, and so I was envisioning extracting the new vertex position from the texture and then saving it to the vertex position array in the VS.billvh
I use POINTS to generate my new vertex positions (first stored in a texture in FS using a framebuffer, and then transferred to altered vertex positions in a transformfeedback in VS), I'm then using LINES to render the connections between all the vertices.billvh
I'd guess skipping the transform feedback step and using the texture directly for positions would be faster but you'd have to testgman