- Home /
What is the best way to go about manipulating vertices?
For example, changing color (for simplicity).
Sometimes I find myself trying to distinguish between whether to write a script, or whether to write/edit a shader. For example, let's say I have a simple primitive, like a sphere. I want all of the vertices to be green. It seems to me that there are two possible approaches:
Write a script that loops through all of the vertices of a Mesh (in the Update function) and change the color to Color.green, or
Write a shader that simply sets the Main Color to green.
Obviously, two is the better choice. Although, I think that #1 also depends on the shader, since not all shaders will respond to vertex-color changes.
But if the question gets more complex, i.e., I'd like to implement some fractal and noise functions. How do I know what I should accomplish in a script, and then what I should do with the shader?
Hope this makes sense. If not, just say so and I'll try to reword it.
Cheers.
Answer by Eric5h5 · Jul 28, 2010 at 07:13 PM
Good question...persistance, perhaps? If you want to change something about a mesh permanently (like applying damage to a car model), it seems to me that changing the mesh in a script is more appropriate. A shader would be better for something where you have a basic state that has an effect applied "on top" of that every frame (like a waving flag shader). You could do that with a script too, but a shader would be faster and use fewer resources.
Ok, so the bottom line is I should consider using a shader when an object's state (per frame) is dynamic. Is that a fair statement?
@jacksmash: seems fair to me, though I'd like to see some more answers.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065947im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shader errors 0 Answers
How to hide script-completed shader properties ? 0 Answers
Change Water via Script? 0 Answers
Full scene speed-based motion blur 2 Answers
Scripting Shader: How to control Alpha with slider? 1 Answer