Hey Everyone,
Having some issues with the which i hope the attached image will explain.
In my game I’m painting the vertices at runtime and have a simple shader to display the vertex colours:
Shader "Vertex Color Lit" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Pass {
Lighting On
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {
combine texture * primary DOUBLE
}
}
}
}
The problem is I liked the colours to blend more naturally and not look so blocky, I’m under the impression this is something I can do with the shader but not having any luck. Tried some of the blend options and they did nothing.
Can anyone point me in the right direction?
Thanks,
Adam
A shader can’t do much here. The GPU generally interpolates all vertex attributes linearly across the rasterized triangles. So if one vertex is white and the other blue the fragments in between will have a linear mix between them. This behaviour can’t be changed. Also it wouldn’t make much sense. A mesh could have any arrangement of triangles. You just have a special case where you use a regular rectangular grid.
Your problem is simply that you only paint two colors. This of course creates a high contrast between two vertices of different colors. If you want a smoother result you basically have to allow painting with an “opacity” setting and a gradient around your brush which you use to paint. If the painting should be that “sharp” (so one could paint a single vertex with a highly different color) the result will look that “sharp”.
If you want a better result you may want to use a single quad mesh and paint on a texture instead of doing vertex painting. Unlike vertex colors, texture color interpolation uses bilinear interpolation and takes the closest 4 texels into account. A slightly better result would be achieved by using a bicubic interpolation (which takes the 16 neighbor texels into account). However the hardware doesn’t really support bicubic filtering. You would need to do that yourself in the shader. However a high contrast blocky image will always be “kind of” blocky since your vertex arrangement is rectangular. Bicubic makes each texel appear a bit more “round”. Note that bicubic requires 4 times as many texture lookups per fragment as bilinear filtering. In most realtime application bicubic isn’t used. It’s commonly used in image processing when you resample an image (up or down scale). (numberphile on bicubic).