"For" statement / loop / iteration function in Spark AR

Hi brilliant creators!
I’ve been experimenting to read some shader code and implement it in patch editor.
I’ve able to create some uv transformation and procedural noises patch learned from the book of shaders.
Radial Color Wheel

Kaleidoscope Tunnel

Spiral Tunnel

Grain - Value Noise

Grain smooth - Value Noise

Gradient Noise

But I found something that i still can’t figure out how to accomplish it.
It’s the for statement or looping. How to do it in spark?
I’ve tried to send the value to script, do the looping in script, and then pass the result from script to patch editor, but still it gives me an error or no values.
I hope someone can guide me on how to do it properly.

  1. Input the value/vector from patch to script.
  2. the for statement.
  3. Output the result from script to patch.

so whenever i want to do looping, i can just drag and drop the script to the project, create the input and output, and change some parameter in it. no need to automatically apply it to some material or something.

My plan is to create these tools to help beginner creators expand their creativity without having to struggle learning some technical stuff, by sharing this patch to the Spark AR library for free if spark ar allow me, or to sugar site if popul-ar interested.

Well, there’s technically no for-loops in patches, but if you need a continuous stepped value for a shader, you could use a UV (tex coord or function vec2) with some math.

Generally I will use Spark SL if I really need to do a lot of loopy stuff.

1 Like

yes i know about this steppy stuff since we’ve talked about this in other thread. i’m just curious about this loopy stuff cuz it seems like a feature where some advance stuffs require this method to do some iterations.

There are iterator patches in cables.gl and lens studio (I think), but for some reason spark never exposed that in the patch editor. The solution proposed by the devs was to use patch groups, but that only helps so much. You could always submit feedback in the app. I’ve asked for this feature several times :slight_smile:

Got it, done it with also some bug report. thanks josh!

1 Like