Dinamically set array in shader
Hello, i'm working on a shader which do something at a certain position. My prob is how to set these positions, since I need to have multiple of it I've been thinking about using array in the Shader so i can set multiple positions and work from that. Since everytime I was generating a new position, it was deleting the old one (which is kinda logic).
The problem is, I need multiple of these effect at the same time, so there is multiple solutions i've been thinking of, like doing multiple shader and materials then change it dinamically, but it kind of sucks.
So I've this line into my shader :
o.dist = distance(worldPos, _CharacterPosition[0].xyz);
which set the position and then (later on the code) do the effect comparate to the distance.
My principal question is : is there a way to modify the " [0] " by " [i] " which is incremented into a script (at every collision, for exemple) so it will set up the position to different cells into array and make the whole thing works. But i've no idea how to put a variable in there since i'm new on Shader.
Greetings, Dreaa.
Answer by Dreaa · Mar 09, 2018 at 11:24 AM
So i've been trying some things, and I have successfully do what I wanted, but from that I have an other issue.
I've been doing that in the shader :
o.dist = distance(worldPos, _CharacterPosition[_IndiceCollision].xyz);
And i pass the value this way : GM.shaderMaterialCollision.SetVector("_CharacterPosition", gameObject.transform.position);
the problem is, it always put it in cell "0" as you can see there :
I'd like to know if there is a way to do something like : GM.shaderMaterialCollision.SetVector("_CharacterPosition", gameObject.transform.position[count]);
but it doesn't work.
Greetings.
Your answer
![](https://koobas.hobune.stream/wayback/20220612154228im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A public list of color in shader. 0 Answers
if ALL items in array are something 1 Answer
Same for each loop with multiple arrays? 1 Answer