Glsl importing with a Buffer and imagine ,error

Hey Guys, i am trying to import a Glsl boid simualtion from this example :

but i got the error " indexes beyond end of input vector (length 2)" in the the buffer A.
I never import a glsl code with a buffer and an imagine and i don’t really understand if i am using correctly my TexelFetch.
Here the toe that i am working on …fishes Boids.toe (5.7 KB)
Thank you in advance for any tips:)

Hey @Tizy0,

quickly looking at it, shadertoy’s iMouse is defined as a vec4 while you have it coming in as a uniform vec2 u_Mouse - as a result when it tries to get to the w swizzle it fails as that is representative of the 4th component in the u_Mouse uniform.

Generally speaking, there are a few things to watch out for when converting from shadertoy to TouchDesigner:

  • shadertoy’s uv is in absolute pixels while TouchDesigner thinks of vUV as 0-1 normalized values. So to get to shadertoy’s uv you’d have to multiply vUV.st with the glsl TOPs resolution.
  • shadertoy’s iResolution is the shaders output resolution in absolute pixels. In TouchDesigner you set the resolution via its Resolution parameter and inside the shader you can get access to it via uTDOutputInfo.res. This uniform contains 4 items: (1.0 / width, 1.0 / height, width, height). See the docs for a bit more info on that: Write a GLSL TOP - Derivative
  • when shadertoy is reading back in the output of it’s shader as an input, in TouchDesigner you’d have to build a little TOP feedback loop.
  • iTime and iSeconds in shadertoy can be interpreted as TouchDesigner’s python variables absTime.frame and absTime.seconds but in order to be able to easily reset these counters, you can mimick them by creating a CHOP network that just counts frames and seconds up.

The attached tox here works for me now - i hope with the above notes this is fairly good to understand. There are also some very useful tutorials to be found here: https://alltd.org/?s=shadertoy that explain the process in more detail.

Best
Markus

shoalOfFish.tox (3.5 KB)

1 Like

Hey Markus,
Thank you so much for your replay and all the clarifications,this really helped me to better understand.
The only thing that is still quite difficult for me to get it, it’s why do i need a constant top with a feedback as input on my Glsl buffer.
It is a sort a loop holding information after the forces get applied or??
Again much thank you for all your help.
Best,
Tiziano

Hi @Tizy0,

yup, the calculation for the positions and velocity of the fish is a loop as the current position needs to take the previous condition into account. The Feedback input’s Constant TOP is the initial data for the feedback loop as for the first frame theoretically there is no data yet to be fetched by the Feedback.

Hope this makes sense
Best
Markus