# 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 vUV.st. What you probably want to do is use vUV.st 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