Polygon Color Shader

This project was supposed to be a fancy shader project done in Unity. The idea was to recreate the stylized low-poly look of things like Polyworld, but without the use of UV’s and textures, just vertex color data. I still don’t know if it’s possible to do this entirely with a shader, but I couldn’t find a way to do it at the time. If anyone has any ideas of how it could be done, I’d love to know. Instead, it ended up being mostly a geometry manipulation project with just a touch of shaders.

To the right here you can see the highly technical polysplit_diagramdiagram I made to originally describe the idea. You have two colors, and each polygon has a random color that is somewhere between the two. I broke this into three challenges: Figuring out how to shade per- polygon, lerping colors, and implementing randomness.

Lerping ended up being the easy part, since the good people at Nvidia provided color lerp functions in the CG library. Pseudo-randomness ended up being fairly easy as well thanks to the classic Linear Congruential Generator algorithm. The hard part was the polygon situation. My workaround was to break up the geometry in the Editor, making sure each triangle now had its own dedicated three vertices. Each vertex of a triangle was given the same randomly chosen vertex color value. This meant that I could now make a shader that reads in the color data of each triangle individually and uses it as a seed value for the final color.

I technically met all my goals, but the geometry splitting part meant it couldn’t be all condensed into just a shader, so I settled for one hefty editor script and one small surface shader. I do want to tackle it again some time and see if I can get it working how I originally wanted. You can check out a little demo below that lets you play with the materials in the scene using the shader. All the models are from Low Poly Forest Set after running them through the geometry slicer script. Also be sure to check out the GitHub repository below. /Assets/Editor/GeometrySplitter.cs is the geometry slicing script, and /Assets/MainScene/TriColored.shader is the shader.