Hello! I am trying to make a shader that takes in 2 textures and blends them together, and then the final output needs to have opacity as a variable. To that end, I have gotten it all worked out, EXCEPT, whenever one of the inputs has transparency, the opacity element removes the transparency and replaces it with this:
my code so far:
Shader "Custom/TonyShader2D"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_OffTex ("Other Texture", 2D) = "white" {}
_Strength ("Blend Strength Between Textures", Range(0,1)) = 1
_Opacity ("Opacity", Range(0,1)) = 0.0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _OffTex;
half _Opacity;
half _Strength;
float4 _MainTex_ST;
float4 _OffTex_ST;
struct Input
{
float2 uv_MainTex;
float2 uv_OffTex;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float2 uv2 : TEXCOORD1;
};
v2f vert(appdata_base v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
o.uv2 = TRANSFORM_TEX (v.texcoord, _OffTex);
return o;
}
//void surf (Input IN, inout SurfaceOutputStandard o)
float4 frag(v2f i) : SV_Target
{
fixed4 c = tex2D (_MainTex, i.uv);
//c.a= _Opacity;
fixed4 c2 = tex2D (_OffTex, i.uv2);
//c2.a= _Opacity;
fixed4 c3 = lerp (c, c2, _Strength);
c3.a= _Opacity;
return c3;
}
ENDCG
}
}}
Any Ideas?