- Home /
Trying to write a simple mixing 2 textures shader with alpha support on the 2d texture
I have 2 textures :
A background texture with no transparency (for example the earth texture)
A cropcircle texture (black and white texture) showing a simple white symbol over a black background
I can't find any existing CG shader (CG shader is immportant) to be able to display my white cropcircle on my planet earth planet.
I just want the black background of my cropcircle texture to be transparent and to show the earth texture bellow by transparency.
Here is the shader i'm trying to write :
Shader "Custom/SimpleMix"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_BlendTex ("_BlendTex", 2D) = "white" {}
_Blend1 ("Blend between Base and Blend 1 textures", Range (0, 1) ) = 0
}
SubShader
{
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
ZWrite Off
//Blend SrcAlpha OneMinusSrcAlpha
//Blend One One
//Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _BlendTex;
float _Blend1;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
fixed4 texTwoCol = tex2D(_BlendTex, IN.uv_MainTex);
fixed4 output = lerp(mainCol, texTwoCol, _Blend1);
o.Albedo = output.rgb;
o.Alpha = output.a;
}
ENDCG
}
FallBack "Diffuse"
}
if I use Blend SrcAlpha OneMinusSrcAlpha with a png cropcircle with transparency, the earth texture become transparent too :(
Please help...
Thanks a lot
Answer by DarkPixel · Sep 27, 2013 at 08:26 PM
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
fixed4 texTwoCol = tex2D(_BlendTex, IN.uv_MainTex);
fixed4 mainOutput = mainCol.rgba * (1.0 - (texTwoCol.a * _Blend1));
fixed4 blendOutput = texTwoCol.rgba * texTwoCol.a * _Blend1;
o.Albedo = mainOutput.rgb + blendOutput.rgb;
o.Alpha = mainOutput.a + blendOutput.a;
}
(The blend text need to have alpha to work, you can generate it from grayscale if it's a black and white texture)
Your answer
Follow this Question
Related Questions
Blend two texture diffuse shader with alpha 0 Answers
Decal Alpha Blend 0 Answers
Blend 2 Texture with alpha 1 Answer
Scripting Shader: How to control Alpha with slider? 1 Answer