1
\$\begingroup\$

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): enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ The question seems unclear. Do you wish to see the path of one or more particles, as in rendering the full curve from start to finish? \$\endgroup\$ Commented Aug 1, 2017 at 14:03
  • \$\begingroup\$ yes, I want to provide as input vertex attributes starting position (and eventually also initial velocity), and the shader should expand it to full path (some number N of iterations of the equation of motion). So if my input vertex buffer (mesh) is composed of 1000 points, I want to draw 1000 curves each with N points. \$\endgroup\$ Commented Aug 1, 2017 at 18:59

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.