Search Unity

Help on illuminating specific regions of texture (glowing 2d sprite character chest)

Discussion in 'Shaders' started by fgielow, May 27, 2013.

  1. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Hello!

    I am a complete beginner regarding unity3d shaders and I have a doubt on the best approach to achieve what I need.
    I have a sprite for my protagonist, we are working with 2d sprite animations. The protagonist ideally would need to emit ligh from its chest (ideally as if light particles came out from its chest, at least glowing around it) and its eyes may also change colors according to the character's tendency.

    Hence, I thought about coloring his chest with #0000FF so I could try masking the blue channel of the texture, making it emit light.

    What kind of shader would I need here? Self-Illumin? Also, would it be better to use just one texture with the glowing areas marked or another texture showing that? I tried playing with the default Self-Illumin shaders, but none achieved anything near what I want. As a further note, I currently do not employ lightning sources, I want the character to emit its own illumination from its chest.

    Any idea on a good approach here or any tips?


    Thanks in advance!
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    If its a 2D game, you dont need any unity lighting, im sure you are doing your own custom way of lighting the environment and characters. So, self-illum shaders or any surface shader wont do any good for you. All you need is some nice texturing.
     
  3. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Yeap, that would be the common approach, but we want a much more customizable illumination.

    For instance, the light emitted from the character's chest could vary in color and intensity. We cannot create sprites for every color and every intensity because then we would have like 8~16 variations of every single sprite, huge atlases would be needed. If possible, I would like to indeed use a shader, even though it is not the standard procedure. Of course we could also create another sprite sheet just for the lightning overlapping it on the common sprite and changing the color and intensity there, but that is still a backup plan, if I can, I am willing to use shaders for the flexibility. Do you think it is feasible? Thanks for the input!


    Fernando.
     
  4. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Do you have Pro ?
    On which platform do you wish to publish ?
     
  5. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    I do not have PRO, but we intend to acquire it within the next 9 months.
    We are aiming to publish on Win/OSX/Linux, not mobile platforms.
     
  6. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Have you considered using particles to accomplish the effect you describe ?
    Also, would you like to share some photoshop mockups of what you try to achieve ?
     
  7. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Particles would be problematic in our case because we are using sprite animations, hence, the "place" where the particles should be emitted from would change from frame-to-frame, hence it would be easier to indicate it on the original sprites.

    Here are some in-game actions of a neutral character: http://jotun-dev.tumblr.com/post/50511164982/some-new-in-game-actions

    You can see a kind of sphere on the characters chest, where the light should come from. Its place can vary a lot depending on the animation, hence a particle system would not be trivial.

    Here we have a concept art of the evil version of the protagonist: http://jotun-dev.tumblr.com/image/50741414878 - Of course, it is a concept art, but the in-game corresponding sprites of that version should emit no light, while good versions could emit light from its chest.

    Since I am the programmer, I do not have an easy mockup here, but I will speak with the designers so you can see exactly how the outcome should look like. I think you can understand well what we need from the links I gave, though.


    Thanks for the attention!
     
  8. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Well, if you must really go for a shader, the light in the chest thing will have to have a distinctive color in the base texture. Then in your shader you can do a color selection(forexample a pure red color for the chest and the rest of the character should not include any red at all) and then intensify the area.

    Search the forums for "selective color", "color mask" or something like that, i posted some code and shaders before.