I am currently making a low poly game, flat shaded. I’m wondering if I had a material with this texture:
And then for lets say an apple, set the UV of all the red parts of the apple to a single point, and then put that point onto the red area on the texture. The same for the green part as well.
Will having tiny UV’s mess with anything else? Is this a good idea?
You might run into issues with the colors shifting as the object gets close or far away due to mip-mapping.
Generally you would use vertex colors for this purpose instead of a texture, which would also be more efficient to render.
For Dino Frontier we used a single 128x128 swatch texture for almost everything in the game. Why did we use a swatch instead of a vertex colors? It gave us a little more consistency and let us modify colors of objects after the fact if needed with out taking a lot of work. It also let us easily define colors for in and out of shadow, and get multi-color transitions mid-face rather than only between vertices.
We had the texture roughly sectioned into human skin & hair colors, clothing colors, dino colors, environment colors, prop colors, and UI colors. Each set of colors was in a column, so for example two hair color shades and three skin color shades for each complexion; light skin, tan skin, red head, various Asian and African skin tones, etc. each had a column of colors 5 pixels high. Each time you made a new object or character you either picked from the colors you needed (keeping to the proper section) or appended some extra colors on the end of the section. More than half the texture was still blank at the end.
The main trick to get this to look right was to set the texture to uncompressed so each pixel’s color wasn’t lost to compression, and disable mips to avoid the issue @joshenes mentioned. The artists also found it easier to work with UVs than vertex colors, though you had to be careful about keeping the UVs aligned to each column of colors or you got bleeding (which some artists started to do intentionally near the end).
For the color gradient you have above, that could be done with a texture just 6 pixels wide, and 2 pixels high. Each pixel across the top row being the significant color from the rainbow and the bottom row just being black. However that limits you only to fully saturated colors; no pink, no greys, etc. You’re probably better off using vertex colors if you want more flexibility.
One word of caution when using vertex colors. You’ll want to stick to gamma color space rendering when using them, otherwise the colors will not match what you see in your modeling program as vertex colors are not gamma corrected for linear space rendering. It’s an advantage textures have in this regard.
Minions Art uses this technique to great effect and has some great tutorials on exactly this:
She actually uses gradient textures and paints models by arranging the uvs themselves.
One thing to consider is light mapping— if you plan on generating lightmap uvs, might want to make your uvs not the size of a single dot, but a little bit bigger so you can get some fidelity. Or have a separate set of uvs for lightmapping.
The vertex color could be converted to linear space in the shader, basically what had to be done to textures before there was hardware support for linear rendering. I agree it might be more artist friendly to use a texture. It’s unfortunate that many 3d packages don’t consider vertex painting tools an important feature.
The technique bgolus described is essentially what I’m doing in my game (sig) though with a much smaller palette, for the entire game. All assets, environment and characters, will use one 32x32 texture swatch/palette.
I’m also intentionally using color bleeding for gradients stretched across polygons. It works well.
This bottom image is a quick re-texture of an asset store (placeholder) model using this technique.