How to create a script that swaps vertex color data with uv data?

Hi folks,

I am working on a shader for a small game that I am creating in Unity but I am having performance issues and need to optimize the shader. I require two colors per vertex and at the moment I have a texture that is split into two columns that gets samples two times per rendered pixel.

I can improve the performance of the shader by removing texture sampling entirely if I could simply encode two vertex colors per vertex. Unity only supports one vertex color per vertex; but I could encode the second vertex color as the UV coordinate.

If I can somehow find a way to swap vertex colors with uv coordinates in Blender; then I could encode both of the colors per vertex whilst also easily being able to switch between vertex colors in vertex color painting mode.

How would I approach doing this with Blender scripting?

Many thanks

Well I’m almost there; I have managed to put the following together; it might not be the most efficient script ever performance-wise; but it sort of works. The only trouble is that I am unable to retrieve the alpha value of the vertex color.