Search Unity

How to combine Shaders?

Discussion in 'Shaders' started by chips, May 30, 2008.

  1. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Hi!
    I'm trying to combine the Transparent/Diffuse shader with the Reflective/VertexLit shader. To do a simple glass that has reflection.

    Is there any way to do that?

    TXS!
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
  3. chips

    chips

    Joined:
    Nov 30, 2007
    Posts:
    138
    Thanks Daniel!
    This shader, solved perfectly my problem!

    []s Chips
     
  4. jan1984

    jan1984

    Joined:
    May 30, 2008
    Posts:
    43
    hey Daniel that was pretty sweet.however a couple of questions.
    1)this particular way requires that u name passes.so how would u handle the fallback mechanism out here?Isn't there a way so that u can simply call a shader by its name(that shader could have multiple subshaders) and then use watever the output of that shader with my current shader.That way the called shader will take care of the fallback mechanism by itself.
    2)also i tried to follow wat u suggested and my unity keeps on crashing.here is wat i'm doin.

    create a new shader and paste the following in it

    Shader "TestShader2"{
    Properties{
    _Color ("Main Color", Color) = (1,1,0,0)
    _SpecColor("Specular Color", Color) = (0,1,0,1)
    _Emission("Emmisive Color",Color) = (1,0.5,0.5,1)
    _Shininess("Shininess",Range(0.01,1)) = 0.5
    _MainTex("Base (RGB)",2D) = "white" {}
    }
    SubShader{
    UsePass "ts1"
    Pass{
    Name "ts2"
    Blend SrcColor DstColor
    Material{
    Diffuse[_Color]
    Ambient[_Color]
    Shininess [_Shininess]
    Specular [_SpecColor]
    Emission [_Emission]
    }
    Lighting On
    SetTexture [_MainTex]{
    constantColor[_Color]
    Combine texture * primary
    }
    }
    }
    }

    where ts1 is a named pass in another shader

    Shader "TestShader"{
    Properties{
    _Color ("Main Color", Color) = (1,1,1,0)
    _SpecColor("Specular Color", Color) = (1,1,1,1)
    _Emission("Emmisive Color",Color) = (1,1,1,1)
    _Shininess("Shininess",Range(0.01,1)) = 0.7
    _MainTex("Base (RGB)",2D) = "white" {}
    }
    SubShader{
    Pass{
    Name "ts1"
    Material{
    Diffuse[_Color]
    Ambient[_Color]
    Shininess [_Shininess]
    Specular [_SpecColor]
    Emission [_Emission]
    }
    Lighting On
    SeperateSpecular On
    SetTexture [_MainTex]{
    constantColor[_Color]
    Combine texture * primary
    }
    }
    }
    }
    I'm using TextMate for editing all my code
    Both these shaders are in the same folder.Any ideas on this plz?
    Thx