Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Colorify Asset Help -- Realtime color changing

Discussion in 'Scripting' started by HunterHunter150, Mar 14, 2019.

  1. HunterHunter150

    HunterHunter150

    Joined:
    Mar 9, 2019
    Posts:
    2
    Hey everyone,

    I searched all over for an answer to how to change colors in real-time with this asset and for the longest time, I came up very short. I finally got my answer after a decent amount of learning and manipulation and I figured I would share my findings with you.

    First of all, this is a fantastic tool once you figure out how to use it. It is incredibly powerful.
    I attached a very small example picture of how to change one color in the inspector.

    Firstly, you want to create a material with your desired object texture.

    Next, go under shaders and set your shader to "Colorify/Realtime/(How many colors you want to change)/(How you want the material to be shaded)".

    Next, select the "Pattern Color" you want. This is the color you will be replacing.
    Then, select your "New Color". This is the color you will be initializing the textures with. This color will be replacing the pattern color.

    Change the "Range" and "Hue Range" sliders to your own discretion. Range determines how distant, RGB-wise, you want the color being replaced. Hue, well, same... but with hue!

    Note: All of what is stated above is just for general colorify use (excluding "Colorify/Realtime").

    Finally, on the editor-side, if you want to change the way this object looks (color-wise) in real-time, make sure you have a Mesh Renderer component of some sort attached to the object. The type of mesh renderer is up to you (ex: Skinned Mesh Renderer is fine).

    Now here's the part why you probably came here. You need the code to actually control the color changing:

    I have put together a very small example program for you to control this. It is written below.

    public class ColorSet : MonoBehaviour
    {

    // All color values should be between 0 and 1
    public float redVal;
    public float greenVal;
    public float blueVal;
    const float RANGE = 0.56f;
    const float HUE = 4f;

    Renderer rend;

    void Start()
    {
    rend = GetComponent<SkinnedMeshRenderer>();

    // Use the Bumped Diffuse shader on the creature material
    rend.material.shader = Shader.Find("Colorify/Real-time/1 color/Bumped Diffuse");
    rend.material.SetFloat("_Range", RANGE);
    rend.material.SetFloat("_HueRange", HUE);
    rend.material.SetColor("_NewColor", new Color(redVal, greenVal, blueVal));
    }
    }

    Obviously, make sure to change "SkinnedMeshRenderer" to whatever type of mesh renderer you are using. Also, range and hues do not have to be constants. The only restriction is the range you pass is between (0-2) and the hue range you pass is between (0-4). This will dynamically change the colors of the texture to what you want on the initialization of this component. Alternatively, you can put the "rend.material.shader = Shader.Find()" in the "Start()" method and then put the rest in another function.

    There is something very wonky (at least in my experience) with setting the color. You can try experimenting with your assets, but in my experience, the color values NEED to be between 0 and 1 (in my experience you are best off keeping between 0 and 9 though). If you go outside this color value range, textures start to look absolutely disgusting.

    Additionally, there is a colorify manual that is located inside of the colorify asset.

    With one final note, if you are looking to save a recolor of a texture as a new texture,
    check out this link by the creator
    .

    I hope this was helpful to someone, this took quite a bit of research, testing, and time so it seemed necessary that someone make a tutorial for this!
     

    Attached Files:

    HalBar_Wick likes this.