For Loop to iterate through global arrays

Node-based Shader Editor

For Loop to iterate through global arrays

Postby Desoxi » Sun Nov 26, 2017 1:01 pm

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).
Desoxi
 
Posts: 9
Joined: Sat Nov 11, 2017 10:35 pm

Re: For Loop to iterate through global arrays

Postby Ricardo Teixeira » Mon Nov 27, 2017 5:23 pm

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!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Ricardo Teixeira
 
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: For Loop to iterate through global arrays

Postby Desoxi » Tue Nov 28, 2017 7:27 pm

Oh nice, thanks! Totally forgot about the custom nodes. Gonna try this out tomorrow :)
Desoxi
 
Posts: 9
Joined: Sat Nov 11, 2017 10:35 pm


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 80 guests

cron