Search Unity

Transparency - Shader - Noob question - [SOLVED]

Discussion in '2D' started by davide_vitussi, Jul 3, 2015.

  1. davide_vitussi

    davide_vitussi

    Joined:
    Jun 23, 2015
    Posts:
    2
    Hi all,
    i got a little question about shaders.

    I googled and searched a lot but i'm really stuck..

    I got a simple game object with a sprite renderer. (the image is a Trunk)
    I want to add another game object inside the trunk (a Cut) that renders on the edge of it.

    The hard part for me is applying the transparency of the Cut sprite ON the Trunk sprite (so that the background becomes visible through both).

    I already managed to write (by cutting and pasting some code and playing a bit with it) a shader to make a single color transparent on a sprite, so my hope is that i can manage to apply the transparency EVEN on objects on the back of the object itself.

    I searched / tested / read about many shader commands and such but i don't even know if what i'm looking for is possible(Cull, ZTest, Queue, Blend etc..).
    (i'm totally noob with shaders and started from just 2 weeks ago with unity2d in spare time)

    Attached the idea explained in the image and the two zombie-shaders i stealed from the web.


    Please be patient and remember that i'm a noob! (and my english is not so good :) )


    thanks a lot,
    David
     

    Attached Files:

  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    I don't have time to get into it (sorry!) but the shader technique you'll want to use is stenciling. If you draw your cut first, you can stencil the area of the cut (kinda like making a cookie cutter the shape of your cut), then you can draw the tree trunk and tell it not to draw inside the stenciled area.
     
  3. davide_vitussi

    davide_vitussi

    Joined:
    Jun 23, 2015
    Posts:
    2
    thank you very much!
    i googled a bit about stenciling and it's exactly what i need!
    sorry for replying that late and thanks again!