x


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
            }
        }

    }
}

}

more ▼

asked Oct 01 '10 at 05:43 PM

bulentgercek gravatar image

bulentgercek
19 2 2 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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
    }
}
more ▼

answered Oct 01 '10 at 08:25 PM

skovacs1 gravatar image

skovacs1
10k 11 25 92

Thanks for your help my friend. I'll read well your answer. Salute.

Oct 03 '10 at 09:49 AM bulentgercek
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x334
x109
x101

asked: Oct 01 '10 at 05:43 PM

Seen: 1395 times

Last Updated: Oct 01 '10 at 05:43 PM