Search Unity

Need Specular Decal Shader-Thingie

Discussion in 'Shaders' started by Maroy, Jan 2, 2011.

  1. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    Howdy all,
    I'm working on a Lego-style MMO and I'm trying to create texture-based clothing for the characters. I need a specular shader with an underlying "skin" color, and then a separately tinted clothing texture. I could probably do it myself eventually, but I haven't had time to gain some experience with ShaderLab yet. If someone could knock up a shader for me, that would be really great ;)

    Edit: Managed to cobble together my own shader from the various decal textures lying around the forums and wiki. I had no idea what I was doing, but as long as it works I'm happy. Here it is, if anyone finds it useful.

    Code (csharp):
    1. Shader "Decal with Tint" {
    2.  
    3. Properties
    4. {
    5.     _Color ("Main Color", Color) = (1,1,1)
    6.     _DecalColor ("Decal Color", Color) = (1,1,1)
    7.     _SpecColor ("Spec Color", Color) = (1,1,1)
    8.     _Emission ("Emmisive Color", Color) = (0,0,0)
    9.     _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    10.     _DecalTex ("Decal (RGBA)", 2D) = ""
    11. }
    12.  
    13. // More than two texture units
    14. SubShader {
    15. Pass{
    16.     Lighting On
    17.     SeparateSpecular On
    18.     Material
    19.     {
    20.         Diffuse (1,1,1)
    21.         Ambient (1,1,1)
    22.         Shininess [_Shininess]
    23.         Specular [_SpecColor]
    24.         Emission [_Emission]
    25.     }
    26.     SetTexture[_DecalTex] {Combine texture * constant constantColor [_DecalColor]}
    27.     SetTexture[_DecalTex]
    28.     {
    29.         ConstantColor[_Color]
    30.         Combine previous Lerp(previous) constant
    31.     }
    32.     SetTexture[_] {Combine previous * primary Double}
    33. }
    34. }
    35.  
    36. // Two texture units
    37. SubShader
    38. {
    39.     Lighting On
    40.     Material
    41.     {
    42.         Diffuse (1,1,1)
    43.         Ambient (1,1,1)
    44.         Shininess [_Shininess]
    45.         Specular [_SpecColor]
    46.         Emission [_Emission]
    47.     }
    48.     Pass
    49.     {
    50.         SetTexture[_DecalTex]
    51.         {
    52.             ConstantColor[_Color]
    53.             Combine texture Lerp(texture) constant
    54.         }
    55.     }
    56.    
    57.     // 'Double' Lighting
    58.     Pass {Blend DstColor SrcColor}
    59. }
    60.  
    61. }
     
    Last edited: Jan 5, 2011
  2. Muddman55

    Muddman55

    Joined:
    Feb 26, 2015
    Posts:
    1
    Hey Maroy,

    Love this shader! Great work! I'm a total shader noob so is there any chance you could provide a version of this that would work with realtime shadows? Longshot i know!

    Cheers! ;0)