Page 1 of 1

For Loop to iterate through global arrays

PostPosted: Sun Nov 26, 2017 1:01 pm
by Desoxi
Hey there,

is there a possibility to iterate through the indices of a global array somehow?
What i want to do is to give the shader an array of positions and then check if a vertex
is in range of one of these positions and if so, do something specific.
Not entirely sure how to do it with multiple positions thats why im asking for arrays.
One position is no problem but i dont know how to achieve the same behaviour for multiple positions (dynamic in count).

Re: For Loop to iterate through global arrays

PostPosted: Mon Nov 27, 2017 5:23 pm
by Ricardo Teixeira
Hello Desoxi, it's great to hear back from you!

Yes, it's a bit hack'ish but you can access access and iterate over an array.
Please take a look at our example below:

Image

In here we're creating both a Global Array and a Custom Expression ( which will be responsible for all the hard work ).
On the Custom Expression you will create an input which will be used to connect to your global array node. This connection's only purpose is to activate the Global Array node and make it create the array on the shader code. Its result will be ignored.

The second input on the Custom Expression which will be responsible for receiving the vertex position so you can use it to do your own calculations.
Finally the for loop itself must be done by hand inside the Custom Expression code area.

Please let us know if this works for you, we'll be glad to answer any further questions you might have, thanks!

Re: For Loop to iterate through global arrays

PostPosted: Tue Nov 28, 2017 7:27 pm
by Desoxi
Oh nice, thanks! Totally forgot about the custom nodes. Gonna try this out tomorrow :)