I want to visualize flow of particles in some forcefield e.g. electromagetic, gravitional or potential flow in fluid (streamlines);
I was thinking to use Geometry Shader which would look like this (not tested, just sketch):
#version 330 core
layout (points) in;
layout (line_strip, max_vertices = 64) out;
uniform float dt;
vec3 getForce(in vec3 pos){ /* ... don't care now ... */ }
void main() {
vec3 pos = gl_in[0].gl_Position;
for( int i=0; i<64; i++ ){
pos += getForce(pos) * dt; // it's actually velocity field but who cares
gl_Position = pos;
EmitVertex();
}
EndPrimitive();
}
However, I read that Geometry shaders are very slow (I did not yet tested). So I wonder if it would be helpful in this situation?
Or would Tesselation shaders or Compute shaders be suitable for this job and achieving better performance?.
background: I have experience with vertex-shaders, fragment-shaders, OpenCL ... but I have never tried geometry-,tesselation- nor compute-shaders.
EDIT: there is my simple example implementation using geometry shader in 2D https://github.com/ProkopHapala/SimpleSimulationEngine/blob/ca16b6f8d72864a8a572ed2a21ded99c5c2cc3e4/cpp/sketches_SDL/OGL3/test_GeometryShader.cpp
which plots this (for velocity field defined by dipole):
