Search Unity

Combining two shaders

Discussion in 'Shaders' started by DylanYates, Dec 13, 2014.

  1. DylanYates

    DylanYates

    Joined:
    May 9, 2013
    Posts:
    2
    Hi,

    I am trying to combine a custom shader with the default Bumped Specular shader. My custom shader is similar to this example code from the documentation:
    Code (CSharp):
    1. Shader "Examples/2 Alpha Blended Textures" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _BlendTex ("Alpha Blended (RGBA) ", 2D) = "white" {}
    5.     }
    6.     SubShader {
    7.         Pass {
    8.             // Apply base texture
    9.             SetTexture [_MainTex] {
    10.                 combine texture
    11.             }
    12.             // Blend in the alpha texture using the lerp operator
    13.             SetTexture [_BlendTex] {
    14.                 combine texture lerp (texture) previous
    15.             }
    16.         }
    17.     }
    18. }
    My goal with this is to take a base color like so:

    Then overlay a texture on top of it that contains transparency:

    To create a new texture that combines both of them:


    The code above can get me to this point, but I want to combine this functionality with the Bumped Specular shader. Any suggestions would be greatly appreciated.

    Thanks!
     
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    You need to learn cg/surface shaders, it is something like the below.

    col1 = tex2d(your main texture, uv);
    col2 = tex2d(your blend texture, uv);
    s.Albedo = lerp(col1, col2, 1.0 - col2.a);
    s.normal = do your normal as it is done in the bumpmap shader
    s.Alpha = col1.a + col2.a;