- Home /
Change specific mesh's triangle color through shader
Hey unityers! I'm new to shaders So, I have a mesh. Mesh has triangles, formed across vertices. I wanna select a certain triangle in a script and change it's color through a frag shader, however I have no idea how to pass such data to it. I'm aware I could do it by using mesh.meshColors, but it doesn't fit my purpose. Any help is appreciated!
Answer by ThomasAqtl · Sep 27, 2021 at 09:39 AM
Hi,
To set the color of a triangle to a given color , you need to set the color of all its vertices to that color.
Mesh's vertices are stored in an array, mesh.vertices
, and they are stored in an order that depends directly how you built your mesh. If the 3 vertices of your triangle has different colors, the triangle's color will result as an interpolation of each vertex' color. So for instance, if your triangle has a red vertex, a blue vertex and a green vertex, then your triangle will look like this :
Shaders process basically every vertex of your object and AFAIK there is no built-in way to write to a specific vertex (or set of vertices) using them, except using conditions on their properties (normals, positions, etc.)
Regards
Answer by Renardjojo · Sep 26, 2021 at 06:48 PM
Hi ! In your mesh filter, you can access to the mesh and change the vertice color buffer. I was doing an example for you when I see this post in Stack overflow that fit perfectly with your answer ^^
Your answer
Follow this Question
Related Questions
How to return from shader the indexes of triangles/vertices that was actually rendered? 1 Answer
Adding texture to vertex ,I don't want to apply texture each vertex 0 Answers
Cube botttom transparent with shader? 1 Answer
3d model with lower poly count than another model causing tons of lag 0 Answers
Detailed gradient shader 0 Answers