Tops glsl Particle system problem

I was wondering if someone would look at my .toe file and help me with this basic tops feedback particle system. Im just trying to get points from their normalized position to be attracted to the edges of an optical flow. But all I can manage is nothing, or particles flying towards the center or outward.

videoImg-instancing.toe (14.1 KB)

I think the main issue is that you’re using the wrong coordinate to lookup into your mask. Currently it’s What you probably want to do is use to lookup into the position buffer, get a world-space position, and convert that into uv again to lookup into the mask. I haven’t examined the other parts of the algorithm.

Another thing is that normalize(vec3(0.)) is undefined so I do

vec3 normx(vec3 a)
    return a == vec3(0.) ? a : normalize(a);

and then use normx as a replacement for normalize.

Thanks for looking into things David. I’ll spend some time trying to redo the coordinates for the mask. I think theres an example in the particles palette thing. I’m sorry I’m not sure what you mean by normalize(vec3(0.0)); Your saying you don’t use the built in normalize and you use the function you have laid out?

Also I found some math error regarding the acceleration and the file is more working now and the intent is more obvious.

videoImg-instancing.toe (14.2 KB)

Yes normalize(vec3(0.0)); is nan so instead I always use that normx function to be safe.

1 Like
`vec3 externalInput(in vec4 posLife)

vec2 currPos = posLife.xy;
vec2 fieldSize = vec2(2.0uInputMap.x,2.0uInputMap.y);
currPos.x = reMap(currPos.x,-fieldSize.x,fieldSize.x,0,1);
currPos.y = reMap(currPos.y,-fieldSize.y,fieldSize.y,0,1);
vec4 externals = texture(sTD2DInputs[MASK], currPos) * 0.01;
return externals.rgb;

Ok sorry, i’m a bit dense. In the particlesGPU tool there is a function in the glslMulti’s frag shader that uses the above function. Are you referring to that when you say ‘transform to world space’ etc?
Or are you saying prep the glslMulti to then go into a Mats Vertex shader to transform to world space then do particles math in the Mats frag shader? or None of the above?

I don’t use that function specifically but it’s the right idea. I recommend using this glsl-map/index.glsl at master · msfeldstein/glsl-map · GitHub for linear remapping functions. Not sure if you’ve seen it, but my Compute Particles walkthrough has some relevant code.

1 Like

Thanks for sharing that Compute Particles. Its really a super thorough example of atomic Counting and texelFetched systems. I am learning a lot from the video as well as the file itself. Unfortunately for my current understanding I’m not sure it’ll help me write a glsl shader that will do something similar with just sampling textures instead of using compute/texelFetch. I’m coming over from Jitter and just trying to work my way into the added functionality. Do you have an example that is more intermediate level? I would greatly appreciate it.

Try out this Physarum example TouchDesigner_Shared/Starters/Physarum at master · DBraun/TouchDesigner_Shared · GitHub Each particle “agent” does lookups into the feedback texture to decide whether to turn left, right or go straight. In your case I think you want to lookup into a texture to get an optical flow velocity. Also I corrected my typo earlier because normx returns a vec3 not a float.

1 Like