- Home /
How do I modify a very basic blend shader to allow both transparent textures?
I am making an iOS game and need to blend two textures with alpha back and forth.
I don't need lots of control, there are no lights or anything affecting this shader. I found a very basic blend shader that I've seen referenced several times, but I don't know how to enable transparency for both _MainTex and _Texture2.
This shader does everything I need except allow textures with transparency.
Shader "Custom/Blend 2 Textures" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
SubShader {
Pass {
SetTexture[_MainTex]
SetTexture[_Texture2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
}
}
}
Here's all that the texture needs to do: 1)Texture A is visible 2)Texture B is visible. 3) For .3 seconds they blend from A to B and at other times blend for 0.3 seconds B to A.
As you can see in the image below, there are numbers in focus and out of focus. Rather than a blurring shader to fake depth of field (since I'm using Unity Basic), I just want to fade back and forth between blurred and unblurred textures.
I get the feeling that as soon as I add transparency there's a lot more I have to do. Any help is very much appreciated. I'm new to custom shaders, so not sure if I bit off too much. So can I easily make both textures A and B contain transparency?
Answer by robertbu · Feb 11, 2013 at 03:31 AM
I've not spent much time with shader to date, but this should give you what you want:
Shader "Custom/Blend 2 Textures" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
SubShader {
Tags {"Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Pass {
SetTexture[_MainTex]
SetTexture[_Texture2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
}
}
}
You're right, thank you! I did not realize that would be so straightforward, just adding a tag and the blend line.
When I tried this, everything behind the transparency of the image appears black.. Any idea how to solve this?
Your answer
![](https://koobas.hobune.stream/wayback/20220613092434im_/https://answers.unity.com/themes/thub/images/avi.jpg)