- Home /
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.
Answer by skovacs1 · Nov 03, 2010 at 07:48 PM
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
}
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 $$anonymous$$ainTex texture. If a line in $$anonymous$$ainTex overlaps a line in PathTex, it will combine the colours of the PathTex image and the $$anonymous$$ainTex image. How could I make it so that ins$$anonymous$$d of doing this it draws the $$anonymous$$ainTex lines on top of PathTex lines without combining the colours? Thanks.
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.
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.
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.
Your answer
Follow this Question
Related Questions
UI shader; get simple UV 0 Answers
TexGen'ed UVs - how to access in surface shader? 1 Answer
Apply an affine transformation 2 Answers
How to scale and offset UV coordinates from the center of the texture? 1 Answer
Shaders: Overwrite something? 1 Answer