- Home /
Question by
benfattino · Jul 02, 2013 at 01:53 PM ·
shaderalphablend
Blend 2 Texture with alpha
I try to do a shader that blend 2 texture and have alpha channel.
Shader "Blend 2 Textures + Alpha" {
Properties {
_Color ("Color Tint (A = Opacity)", Color) = (1,1,1,1)
_Blend ("Blend", Range (0,1)) = 0.0
_MainTexture1 ("Texture1", 2D) = ""
_MainTexture2 ("Texture2", 2D) = ""
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
Category {
Material {
Ambient[_Color]
Diffuse[_Color]
}
// iPhone 3GS and later
SubShader {
Tags {"Queue" = "Transparent"}
ZWrite On
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass {
Lighting On
SetTexture[_MainTexture1]
SetTexture[_MainTexture2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
SetTexture [_Mask] {combine texture * previous}
SetTexture[_Color] {Combine previous * constant ConstantColor[_Color]}
}}
}}
This shader is similar to this:
Shader "MaskedTexture"
{
Properties
{
_Color ("Color Tint (A = Opacity)", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
SetTexture[_MainTex] {Combine previous * constant ConstantColor[_Color]}
}
}
}
Second shader work perfectly. I have problem with alpha channel of the first shader. There is a black line along border. I don't understand. Somebody can help me?
Comment
Answer by jfa257 · Sep 28, 2020 at 02:53 PM
Hi, I'm no shader expert, and probably I'm resurrecting this post, but I think for you or whoever finds this post, a good idea would be first step: mix each of the textures with the alpha mask by separate, and then, blend them together. Could it be a good idea? Again, just trying to help with a possible very wrong light bulb moment!