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).
For Loop to iterate through global arrays
- Ricardo Teixeira
- Posts: 954
- Joined: Fri Aug 09, 2013 2:26 pm
Re: For Loop to iterate through global arrays
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:
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!
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:
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!
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Re: For Loop to iterate through global arrays
Oh nice, thanks! Totally forgot about the custom nodes. Gonna try this out tomorrow 