Search Unity

Transparency Shader for Character Art

Discussion in 'Shaders' started by TorianoBr, May 28, 2017.

  1. TorianoBr

    TorianoBr

    Joined:
    Nov 27, 2012
    Posts:
    6
    We're in a pickle at the moment as there's a need for a simple solution for ridding skeletal meshes of clipping from it's clothing layer. Is there a way to script in a secondary transparency into the shader that basically overrides( like an overlay) that overrides the character mesh below?

    Ex; I have pants that have a completely different form and topology than the character mesh resulting in the knees, for instance, protruding through. Can I use an alpha to override that part of the leg area or that entire portion of the leg that's covered to mask the area?

    Expanding upon that idea, can the alpha simply be called when the clothing type(the pants) be placed on? Like an automatic process or a tag that says "When worn, use said transparency mask"? We're(NinjaTensei) trying to find solutions for character elements and we're very entry-level to this part.
     
  2. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    So if I understood correctly:
    - Its 2D style game with character layered clothing.
    - It has different type of 2D characters that differs in topology quite a bit. (etc. skeleton?)
    - You want to reuse some of your cloths on same 2D characters (etc. pants).
    - And for some special characters like skeletons you want to make same cloths look teared and holey (So you could see bones)

    If its correct, when its pretty easy to implement. I'm not sure which shader ure a using so I will write small segment:

    Example.shader
    Code (csharp):
    1.  
    2. ...
    3. sampler2D _SecondTransparencyTex;
    4. ...
    5. float4 frag (v2f i) : SV_Target
    6. {
    7.     ...
    8.      // Lets say its you shader final color
    9.      float4 finalColor;
    10.      ...
    11.      // Here is all code where you probably fill finalColor
    12.      ...
    13.      finalColor.a *= tex2D(_SecondTransparencyTex, i.uv);
    14.      return finalColor;
    15. }
    16. ...
    17.  
    And with C#/UnityScript you would change material texture _SecondTransparencyTex according the current character.
     
  3. TorianoBr

    TorianoBr

    Joined:
    Nov 27, 2012
    Posts:
    6
    My apologies! I wasn't clear on that part. It's actually a 3D 3rd person game.
     
  4. LukasCh

    LukasCh

    Unity Technologies

    Joined:
    Mar 9, 2015
    Posts:
    102
    So If I was correct about rest of the points, u can still use same technique for 3d as 2d, as you are going to need only a bit more complicated transparency texture.
     
  5. TorianoBr

    TorianoBr

    Joined:
    Nov 27, 2012
    Posts:
    6
    Thank you for the quick reply and help! I'll have my mates try it out later today.