Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Colour Channels

Discussion in 'General Discussion' started by Nanako, Mar 3, 2015.

  1. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    I want to make colour channels, and i have no idea how.
    Just to clarify, a colour channel is an area of a model or texture where i can define a "tint", a base colour, and that area would be tinted that colour appropriately, with lightness and darkness preserved. (eg, you make textures and shading in greyscale, and then tint it to make a final colour.


    Take for example, a human eye




    This eye has four areas i'd like to colour.

    The sclera (white area), the inner and outer iris, which are clearly different shades here. And the pupil (that black dot in the centre.) Yes i know sclera and pupil typically never change, but they will in my current project.

    I can think of a way to do this easily, which would be to assign four different materials, spreading them evenly onto the appropriate faces of the eye mesh. That is a pretty sucky implementation though. Four materials just for an eye?

    there has to be a better way. Is there any way to create a material with several defined colour areas, and several colour channels built into it, that i could use? Does unity 5 have any cool features that could help in this regard?

    I'm looking to have somewhere in the region of 10-20 colour channels per actor (or at least to try that and see how scaleable it is)
     
  2. Ostwind

    Ostwind

    Joined:
    Mar 22, 2011
    Posts:
    2,804
    One custom shader with one color ramp/or multiple masking textures or something. Best try would be asking this in the shaders section.
     
  3. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    well it seems i'm not getting too much response here, so i'm starting on researching shaders. I made a thread over here http://forum.unity3d.com/threads/creating-a-shader-with-colour-channels.308326/

    please do post if you might have any idea how to accomplish this x
     
  4. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Your terminology might be a bit off. When I hear colour "channel", I think of one colour component (i.e. Red, Green, Blue, or Alpha). I would call it more of a masked tinting shader.

    The first thing you need is the actual mask which is simply a value of 0 to 1 for every location on your mesh. You can store this in the colour channel of your vertex which is usually unused; most geometry gets its colour from textures nowadays. That would give you per-vertex fidelity for your mask which may be good enough.

    If you want a more detailed mask (i.e. one with grunge, dirt, or noise), you will need to use a texture mask. You will usually want to squeeze this into an unused colour component of one of your existing textures such as the alpha channel of opaque geometry.

    You will also need to define a colour shader parameter ("colorTint"), and then in the shader you can use a lerp to blend the tint on and off.

    It would be something like:
    Code (csharp):
    1. finalColor = lerp(float4(1,1,1,1), colorTint, maskValue) * initialColor;
    In this case, you would be using the tint when your mask was one.
     
  5. ChipMan

    ChipMan

    Joined:
    Mar 4, 2015
    Posts:
    122
    we sure came along way from consoles in the 1980s! when only 4 colors perr 16 chunk were drawable!