- Home /
C#-script to shader list variable
Hi,
what I need is a simpley Vector3 / float3 list into my shader. Actually it could also be a an array with variable size.
My goal is to work it like a queue. I 'push' a vector3 / float3 element (into a List / stack / array) on the shader and 'pop' one element from that list each frame!
Is this somehow possible? Doesn't actually sounds that difficult.
Kind regards, Marius
where do you want to do the pushing/popping: in the shader? in scripts?
Answer by Philipp · Dec 03, 2012 at 03:24 PM
I'm not sure I understand the question. If you want to push/pop from within your shader code, then that's not possible (at least not with DX9 shaders), as your shaders can't write arbitrary values in memory. If you want to have a stack in C# and expose the top Vector3 to your shader for read access, you could just write it to a property of your material. If you want to push/pop from C#, but you want every value on the stack read-accessible from your shader code, you could do that by using a texture for the stack, shifting pixels up and down and writing to the top pixel from C# (each pixel could represent a single float).
Am I making sense?
Answer by marius.treu · Dec 04, 2012 at 12:48 PM
As far as I know you can create arrays into GLSL..
I mean you can create a float3 array for example. I use this array to perform actions like I store for all collisions (calculated on C# and sent to shader) the world position into this float3 array. After, I do highlight the area around that collision and remove that element (pop out of array) and highlight the next element etc.
I know that shaders does not provide any object types read out of C# that's not what I wanted to achieve.
What I want is a simple push / pop array command. Are there no?
As far as I know you can create arrays into GLSL..
I mean you can create a float3 array for example. I use this array to perform actions like I store for all collisions (calculated on C# and sent to shader) the world position into this float3 array. After, I do highlight the area around that collision and remove that element (pop out of array) and highlight the next element etc.
I know that shaders does not provide any object types read out of C# that's not what I wanted to achieve.
What I want is a simple push / pop array command. Are there no?
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Use a String Variable to Dynamically Invoke a Method 1 Answer
Are C# Global Variables Safe In Unity? 5 Answers
Script variable can be referenced in Start but not in update. 1 Answer