x


Modifying my shader to overlay rather than blend.

Hiya all.

I've modified the LayerShader from Unify so that it maps two textures (with alphas) to one mesh using two different UV maps.

Is there any way I could modify it so that instead of combining MainTex with PathTex, it overlays MainTex over PathTex? The source is below:

Shader "DoubleUV2" { 

Properties {
    _Color ("Color", Color) = (1,1,1)
    _Blend ("Blend", Range (0,1)) = 0.5 
    _MainTex ("Main Texture", 2D) = "" 
    _PathTex ("Path Texture (RGB)", 2D) = ""

}

Category {
    Material {
        Ambient[_Color]
        Diffuse[_Color]
    }

    SubShader {
        Pass {
        BindChannels
        {
            Bind "Vertex", vertex         
            Bind "texcoord1", texcoord0
            Bind "texcoord", texcoord1
            Bind "Color", color
            Bind "Normal", normal
        }

            SetTexture[_PathTex]

            SetTexture[_MainTex]
            {
                combine texture * previous, previous + texture
            }

        }

        Pass {
            Lighting On
            Blend DstColor SrcColor
        }
    }
}

}

Regards, Joel.

more ▼

asked Nov 03 '10 at 07:11 PM

joeltebbett gravatar image

joeltebbett
148 14 14 23

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

1 answer: sort voted first

You should really check the docs on Texturing in ShaderLab.

In the example there, they define a texture blend shader with

combine texture lerp (texture) previous

There are any number of kinds of functions you can use for combining textures and your use of terminology is unspecific.

//multiply (what you're already doing)
combine texture * previous

//add
combine texture + previous

//Alpha blend (previous's alpha will be used to blend previous over texture).
combine previous lerp(previous) texture

Based on the fact that you have a "blend" property, it would seem you want to control using that property. I did something like that here.

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

or if you wanted it to be more of an additive combiner, you could do something like:

SetTexture[_PathTex]
SetTexture[_MainTex]
{
    ConstantColor ([_Blend],[_Blend],[_Blend],[_Blend])
    combine previous * constant + texture
}
more ▼

answered Nov 03 '10 at 07:48 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

Sorry, the blend property was left-over code from the LayerShader code and isn't relevant to what I want. I'll explain what I mean a bit better. Lets say my two textures are different transparent images with a series of random solid lines going through it. At the moment it draws the PathTex texture, and then draws the MainTex texture. If a line in MainTex overlaps a line in PathTex, it will combine the colours of the PathTex image and the MainTex image. How could I make it so that instead of doing this it draws the MainTex lines on top of PathTex lines without combining the colours? Thanks.

Nov 03 '10 at 08:18 PM joeltebbett

That would be an alpha blend shader exactly as described above and given in the docs. Replace 'combine texture * previous, previous + texture' with 'combine texture lerp(texture) previous, previous + texture' in your shader and it should do what you describe.

Nov 03 '10 at 08:56 PM skovacs1

That of course assumes that your "solid" areas have an alpha of 1. If they don't then that's something that you should have mentioned in the question and becomes much trickier.

Nov 03 '10 at 08:59 PM skovacs1

You would get better results where they overlap and either of their alphas are not 1 if you didn't overwrite the alpha with previous + texture.

Nov 03 '10 at 09:02 PM skovacs1
(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:

x1666
x238
x33

asked: Nov 03 '10 at 07:11 PM

Seen: 3083 times

Last Updated: Nov 03 '10 at 07:11 PM