ProBuilder Applying Incorrect Vertex Colors when using Linear Colorspace

My project makes heavy use of vertex coloring and I wanted to give ProBuilder a try since its blocky shape would match my aesthetic. I’m using the linear color space, but I noticed that the vertex colors applied was not resulting in the colors I would expect.

After looking into this, I found a post from bgolus stating that: “vertex colors aren’t gamma corrected when you’re using linear color space.”

I’ve been writing my own mesh generation code lately, and found that if I use the Linear property on the color just before I apply the color to the mesh, I get the correct color. Worth mentioning is that Unity’s own Particle Systems will also send gamma corrected vertex colors, so this seems to be the intended approach to solving this.

My project is very sensitive to coloring, so for me to use ProBuilder in my project, this must be addressed. I found the code in the ProBuilder source where vertex colors are applied, and making a quick one line (two lines, technically) change is enough of a fix for me.

In the file Editor\EditorCore\VertexColorPalette.cs, I changed lines 182 and 194 from this:

colors[i] = col;

To this:

colors[i] = PlayerSettings.colorSpace == ColorSpace.Linear ? col.linear : col;

This new code will make it so that if you are in linear color space, it will apply the correct gamma correction to the vertex. This will not however update any previously assigned vertex colors. In my case, this isn’t an issue since I’m only just starting to use ProBuilder, but this may be of concern to somebody who is looking for a fix.

Nice, thank you for the patch as well. If you’d like to open a PR GitHub - Unity-Technologies/com.unity.probuilder I’d be happy to accept it, or I can do it myself if you’d prefer.

Thanks for the quick reply! I’d prefer if you take care of it. I’m not familiar with ProBuilder’s workflow and I’d rather let an expert handle it.

1 Like
1 Like