Search Unity

Light revealing a second texture

Discussion in 'Shaders' started by KevS, May 21, 2012.

  1. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    Hi all,

    Here is my problem. I want to create objects which react to light by displaying an different texture.
    Something like the clues in Alan Wake :)

    I think I need to write a shader, with 2 textures, the first would be rendered when no light, the other would be rendered when the object is enlightened.
    I'm just starting wirth "shader stuff" and I'm not sure it's possible. Am I in the right way ?
    Any advice are welcome :)
    Thank you !
     
  2. Martin-Kraus

    Martin-Kraus

    Joined:
    Feb 18, 2011
    Posts:
    617
    It's possible but if you use Surface Shaders (and also in other cases ;) ) you will have to implement a special "light" for this because all lights in Surface Shaders are supposed to be additive while you need a light that replaces the color of one texture by the color of another texture. (I don't see how you could implement this by adding colors; except maybe with negative intensities but those are probably not possible.)
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    If you are using deferred lighting you can do this quite easily in a custom surface shader. In your shader write two 'textures' to the surface output (for example have a albedo1 and albedo2). In the lighting portion of the shader you will have a final per texel light value, you can use this to pick how much of each albedo channel to use :)

    You should be able to hook something similar up for forward rendering also as it is additive and will work also, but might require a bit more work :)
     
  4. KevS

    KevS

    Joined:
    Apr 21, 2010
    Posts:
    51
    Thanks !
    stramit, this is what I was thinking to do it, but I just don't know how to code it :) I never wrote a shader, so I need to study a bit :)