Blending 2 Lightmap with Slider Needs Help

Hi,

I am trying to do a shader to blend two lightmap with a slider. I will use that shader to make a daylight room and a night room. I'll change the slider's state and it will goes ok for me.

But i confused with my shader. I am trying to fix it but i cant. Got problem with my second lightmap. Slider working well but lightmap completely filling my first lightmap and diffuse. Can someone check my shader? What is wrong with it? I really need a hand to fix that :(


Shader "--BULENT--/Combiner"

{

Properties
{
    _Color ("Color", Color) = (0,0,1)
    _SpecColor ("Spec Color", Color) = (1,1,1,1)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    _MainTex ("Texture", 2D) = "" {}
    _LightMap ("Lightmap", 2D) = "" {}
    _NightMap ("Nightmap", 2D) = "" {}
    _Blend ("Blend", Range(0.0,1.0)) = 0.0
}

Category 
{
    SubShader
    {
        BindChannels
        {
            Bind "vertex", vertex
            Bind "Texcoord", Texcoord0
            Bind "Texcoord1", Texcoord1
            Bind "Texcoord1", Texcoord2
        }

        Material
        {
            Diffuse [_Color]
            Specular [_SpecColor]
            Ambient [_Color]
            Shininess [_Shininess]
            Emission [_LightMap]
            Emission [_NightMap]
        }

        Lighting On
        SeparateSpecular On

        Pass 
        {
            SetTexture[_MainTex] 
            {
                constantColor [_Color]
                Combine texture * constant
            }

            SetTexture[_LightMap] 
            { 
                Combine texture * previous
            }
        }

        Pass 
        {
            SetTexture[_MainTex] 
            {
                constantColor [_Color]
                Combine texture * constant
            }

            SetTexture[_NightMap]
            {
                ConstantColor (0,0,0, [_Blend])
                combine texture lerp(constant) previous
            }
        }

    }
}

}

What your shader does:

Pass {
    SetTexture[_MainTex] { //color = main * color
        constantColor [_Color]
        Combine texture * constant
    }

    SetTexture[_LightMap] { //color = main * color * lightmap
        Combine texture * previous
    }
}

Pass {
    SetTexture[_MainTex] { //color = main * color
        constantColor [_Color]
        Combine texture * constant
    }

    SetTexture[_NightMap] {//color = nightmap * Blend + main * color * 1 - Blend
        ConstantColor (0,0,0, [_Blend])
        combine texture lerp(constant) previous
    }
}

//Your passes are blended together
//so you get something like nightmap * Blend + main * color * 1 - Blend

What you want:

You only need one pass. You want something more like main * color + nightmap * Blend + lightmap * (1-Blend) if you want the lighting to truly be emissive.

First you would get the mapped lighting and then apply it to the main * color

Try something more like:

//Additive
Pass 
{
    SetTexture[_LightMap] 
    SetTexture[_NightMap] {
        ConstantColor (0,0,0, [_Blend])
        combine previous lerp(constant) texture
    }

    SetTexture[_MainTex] {
        constantColor [_Color]
        Combine texture * constant + previous
    }
}

If you wanted something multiplicative, then you could do something like:

//Multiplicative
Pass 
{

    SetTexture[_MainTex] {
        constantColor [_Color]
        Combine texture * constant + previous
    }

    SetTexture[_NightMap] {
        ConstantColor (0,0,0, [_Blend])
        combine previous lerp(constant) texture
    }

    SetTexture[_MainTex] {
        constantColor [_Color]
        Combine texture * constant + previous
    }

    SetTexture[_NightMap] {
        ConstantColor (0,0,0, [_Blend])
        combine texture lerp(constant) previous
    }
}