- Home /
Problem with coloring mesh with shaders properly
Hello, everyone. I am making a 2d digging game. At this time I am trying to make an effect, which darkens my vertices of the mesh, by the distance they are from empty mesh squares (photos below). The problem is that I get some not proper color mixing in the corner squares. The soft diagonal line, seen in the corner squares can be the result of the squares division by two triangles (this is due to manualy (by script) generated mesh. I use Sprites/Default shader, because it can support this vertice coloring. ...Is there a way to solve this, to get a nice and smooth color mixing?
Notice the corner squares!
P.S. when I use different shader, which does not support this vertice coloring, console gives me a notification - "Shader wants tangents, but the mesh doesn't have them". I do not do any actions with tangents. Maybe I should do someting, to use other shaders? If you have some knowledge and expierence about this stuff, please, help me to solve this problem.
Thanks .
You could check adjacent cells and generate the triangles in a different orientation based on how they will be lit.
Another solution would be to use a shader which calculates the color per fragment ins$$anonymous$$d of per vertex.
Thanks, today I did the first method you just said there, but it still does not look perfect, because on the corner square one triangle is colored, but another is not. Do you know something more about the second method you told? Some article or what to search for? It's first time I hear something about this type of shaders. Thanks again.
Answer by Dr_Who · Oct 26, 2015 at 09:43 AM
I'm very new to Unity but I have had some skill with modeling meshes. In my experience, when using vertex based shading, the only way to improve quality is to up the vertex count. So try subdividing your mesh a couple of times and it should look better. However, the only way to get a perfectly smooth line without major impact on performance is to use fragment shading like @maccabbe said which is unfortunately beyond my knowledge. I hope this is still of use to @Dainiusss or it helps someone.
Your answer
Follow this Question
Related Questions
Cancel out mesh alpha 1 Answer
Changing vertex colors and mesh leak fix 1 Answer
Material doesn't have a color property '_Color' 4 Answers
Hiding part of mesh 0 Answers
How to efficiently render a 2D grid? 1 Answer