Jump to content
Kerfuffles

Vertex Toolbar improvement

Recommended Posts

In messing about with the vertex toolbar code, I stumbled across how colors are set for the swatch previews and noticed that they inaccurately display what color they are set to. To fix this, and the performance seems alright up until about 30 swatches, is to generate 1 or 2px textures and set their colors instead.

You would comment out any GUI.color code inside the loop drawing the swatches, and add this:
 

Texture2D swatchTex = new Texture2D( 2, 2, TextureFormat.ARGB32, false, false );

for( int x = 0; x < swatchTex.width; x++ )
{
    for( int y = 0; y < swatchTex.height; y++ )
    {
        swatchTex.SetPixel( x, y, USER_COLORS[i] );
    }
}

swatchTex.Apply( false, false );

and then draw it normally with the existing DrawPreviewTexture() call.
 

EditorGUI.DrawPreviewTexture( layoutRect, swatchTex, null, ScaleMode.StretchToFill, 0 );

This will then display accurately what color the user has set without noticeable overhead.

Share this post


Link to post
Share on other sites

Thank you for the patch, I appreciate your taking the time to do so.

However I'm not sure I follow - the Vertex Color Palette & Painter windows both show the correct colors on my computer. I tested by taking a screenshot and comparing the pixel colors of the swatch and button. Are you seeing something different on your machine?

Share this post


Link to post
Share on other sites
Just now, karl said:

Thank you for the patch, I appreciate your taking the time to do so.

However I'm not sure I follow - the Vertex Color Palette & Painter windows both show the correct colors on my computer. I tested by taking a screenshot and comparing the pixel colors of the swatch and button. Are you seeing something different on your machine?

7af3cd6419ad1e3378df6034a88a2c57.png

This is using the default code. Using my patch, I get this:
9ac5d4d7d26289511005594042b8bbac.png

It seems like GUI.color adds whatever color you set as a tint (logically), causing the colors to appear washed out when not full saturation colors.

Share this post


Link to post
Share on other sites

Ah, I see. That actually looks like a bug in the gamma pipeline to me (which I have a bug report open for actually). If in the Player Settings you change the rendering mode from Linear to Gamma do things look correct?

Share this post


Link to post
Share on other sites
3 hours ago, karl said:

Ah, I see. That actually looks like a bug in the gamma pipeline to me (which I have a bug report open for actually). If in the Player Settings you change the rendering mode from Linear to Gamma do things look correct?

Actually, that is exactly the issue! I had completely forgotten about that bug until you had mentioned it. Going back over my code, I noticed I set the texture to use gamma space explicitly, which is why it was exempt from the gamma correction bug. Perhaps a possible workaround until the bug is resolved?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×