Jump to content

Color/Tint correction


Quistess Alpha
 Share

You are about to reply to a thread that has been inactive for 630 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Broadly speaking, 'Things that come in lots of colors' (usually clothing) come in 2 varieties, either a single texture for each color variation, or a single grayscale texture and the ability to 'tint' the object by changing its color property in the build window or via a HUD.

Making individual textures for all the color variations under the sun is tedious and expensive (less so if you're a premium plus member), but the results from directly tinting a white texture don't always look quite right.

Enter this simple script example! If you know the rough 'base color' of your textures, it's not all that difficult to pick out the one that's closest to some desired target color, and tint it just a small amount to get it spot on.

list gTexColor = 
["001fb953-90df-fde5-748d-0050b93c7c3c", <1.0,0.576,0.924>, // not actual valid textures on the main grid.
 "d6e6756e-567d-de78-c136-7697da808595", <0.098, 0.533, 0.87>
 // there will be some 'out of bounds' colors unless you have a pure white (<1,1,1>) texture.
];

list suggest_texture_color(vector color, list texcol)
{   string tex_fin;
    vector col_fin;
    float dist = 9999;
    vector diff; // temp working variables
    float d_check;
    integer index = llGetListLength(texcol)+1;
    while(index-=2 >=0)
    {   vector col = llList2Vector(texcol,index);
        if(col.x>=color.x)
        {if(col.y>=color.y)
         {if(col.z>=color.z)
          { diff = color-col;
            if((d_check=diff*diff) < dist)
            {  dist = d_check;
               col_fin = <color.x/col.x, // it would be better to just 'col_fin=col;' and do this division in the return statement.
                          color.y/col.y, // but I don't want to break the version I tested in-world (briefly), so leaving it as-is.
                          color.z/col.z>;
               tex_fin = llList2String(texcol,index-1);
        }}} }
    }
    if(dist!=9999)
    {   //llOwnerSay((string)[tex_fin,col_fin]);
        return [tex_fin,col_fin];
    }
    return [];
}

default
{
    state_entry()
    {
        vector color = <0.0,0.5,0.3>;
        list texcol = suggest_texture_color(color,gTexColor);
        llSetTexture(llList2String(texcol,0),0); // using named functions for clarity over llSLPPF. 
        llSetColor(llList2Vector(texcol,1),0); // 
        llSetColor(color,1); // using face 1 as a refference to compare with a direct tint from white.
    }

    touch_start(integer total_number)
    {	// test a random color on touch.
        vector color = <llFrand(1.0),llFrand(1.0),llFrand(1.0)>;
        list texcol = suggest_texture_color(color,gTexColor);
        if(texcol)
        {   llSetTexture(llList2String(texcol,0),0);
            llSetColor(llList2Vector(texcol,1),0);
            llSetColor(color,1);
        }else
        {   llRegionSayTo(llDetectedKey(0),0,"No suitable base texture found for color: "+(string)color);
        }
    }
}

The 'suggest_texture_color' function takes a color and a strided list of texture-color pairs, and returns either a list containing one of the textures and the color that texture should be tinted to in order to achieve the input color, or an empty list if none of the base colors are suitable.

It should be noted that this is only a sensible thing to do if your textures are not just a solid color layer multiplied over the base texture. In that case, you'd probably get the exact same results just tinting the base texture in SL.

Edited by Quistess Alpha
  • Like 2
  • Thanks 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 630 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...