Page 2 of 2

Re: Having an array of positions for a desired effect

PostPosted: Tue May 08, 2018 10:42 am
by Ricardo Teixeira
Giantswing wrote:Sure! Here it is: https://drive.google.com/open?id=1X6fOiq4VXz62EwBMnjxoz8F1l1kgsgbr
The nodes are super messy I'm sorry about that, I was just trying stuff out
About the for loop yeah I thought about a dynamic system because this effect was meant for some enemies in a FPS and I wouldnt know from the get go how many of them there would be in a given moment, also if they die the array should update so maybe a for loop is just a necessary evil in this case


Fantastic, glad to know you were able to find a viable solution!

Sounds like a tricky situation, I hope the loop is not detrimental to your game performance down the road.

Be sure to let us know if you ever run into any additional issues.

Re: Having an array of positions for a desired effect

PostPosted: Fri Feb 15, 2019 12:55 pm
by Jar
Hey ho,

i tried a simple grass shader where multiple players and enemies can react with.

When i use

Code: Select all
// for loop above
Shader.SetGlobalVectorArray("positionsArray", vectorPositions);


nothing seems to work correctly.

But if i tried Ricardo Teixeira approach, i can manipulate the "Global Array" from my c# script.
Code: Select all
// for loop above
materialProperty.SetVectorArray("positionsArray", vectorPositions);
myRenderer.SetPropertyBlock(materialProperty);


Is it possible to use SetGlobalVectorArray?
I just want one simple script which send the vectorPositions to all grass materials instead of caching and extending a list of meshRenderers to use SetVectorArray()


Image

Btw. how should this generated code work?^^
Code: Select all
      float ForLoop345(  )
      {
          for(int i=0; i<positionsArray.Length; i++){
         return i;
         }
      }


Maybe my real question is, how can i iterate through an global array.
If i edit the generated code, i can simple insert a for loop, but i can't edit my shader after that :(

I revived this thread because its the number one hit if i google this topic.

Best regards,
Jar

Re: Having an array of positions for a desired effect

PostPosted: Fri Feb 15, 2019 4:49 pm
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

We've shared a sample on how to iterate through an array using a Custom Expression node in this topic, which was also referenced in this thread.

This post is also a good source of information regarding what you intend to do.

Re: Having an array of positions for a desired effect

PostPosted: Fri Feb 15, 2019 5:02 pm
by Jar
Thank you for the fast replay. I'll will take a look. The second link is totally new for me :D