- Home /
How to colour a mesh according a temperature/heat map?
Hi folks,
I have a mesh and my aim is to color it according a temperature/heat map. Specifically, I have a color value per each centroid of the different triangles in the mesh (the centroid of a triangle is its mean point). Therefore, I'd like to know how to properly color the entire mesh according these values, of course, interpolating between the different color values. Something similar to this effect:
Should I use any particular shader to represent this temperature map? Thank you very much for your help
Answer by robertbu · Oct 21, 2014 at 06:02 PM
Consider having a color per vertex instead of a color per triangle. Then you can use Vertex colors. The following answer has a section on vertex colors:
http://answers.unity3d.com/questions/795049/oafathow-do-i-changer-the-color-of-a-game-object.html
Yes. You've got it. I'm not sure this specific shader is the one you need, but it is a place to start. If all you want is color, then the shader in the answer I gave you will work, but there are a number of other shader that support vertex colors around.
Ok robertbu. The problem now is that I need it to be done per triangle, ins$$anonymous$$d of vertex. Is there any way to interpolate colors per triangles?
$$anonymous$$ind regards!!!
Don't take my thoughts as gospel since this is not my area of expertise, but I don't know of anything in Unity that would allow you to map color to a triangle. Color is mapped to the vertices.
Some untried thoughts:
You could identify all the triangles that share each vertex. Then you could set the color of that vertex based on the average color of the triangles that share that vertex. If your mesh is irregular, you may have to weigh the color based on the distance the center of each triangle is from the vertex.
You could subdivide each triangle into three triangles using the center point of each triangle. This would give you a vertex at the center to assign a color to. You'd still have to interpolate the colors for the other (original) vertices.