- Home /
Can a GLSL shader fetch GameObject properties?
I have a game object with a propery "Radius" and that radius is later displaced in the class. I was wondering if it is possible for the shader to grab the original radius value defined in the game object to find the displacement amount.
Answer by Julien-Lynge · May 15, 2013 at 01:05 AM
The answer is no. Shaders are executed as part of the rendering pipeline on the GPU, while Unity's game logic is on the CPU. So not only are shaders executed outside of Unity, they're on an entirely separate piece of hardware.
FYI: If you write a custom shader, you can add a Radius property, and set this property from Unity. So in that way you can bring outside information to the shader.
Can I have the radius property set within Unity to equal that deter$$anonymous$$ed by the object created by the script? So whenever one of these gameobjects is generated I won't have to manually make these equal.
You could certainly attach a script to the game object that would automatically keep the material property synced with the value of your public variable. See http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.SetFloat.html
Just use renderer.material to access the material attached to the current game object.