How to mix textures with multipass shader on Unity ?
I want to mix textures with multipass shader on Unity as alpha-blending.
But I don’t know how to get the first pass’s result with shader on Unity.
I’ve tried the variable “previous” and “primary”, but they couldn’t be used.
This is my shader.
Shader "Unlit/MixTextures" {
Properties {
_MainTex ("Main Base(RGB) Alpha(A)", 2D) = "white" {}
_MainTex2 ("Main2 Base(RGB) Alpha(A)", 2D) = "white" {}
}
SubShader {
Tags{"Queue"="Transparent"}
Pass{
// Base
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
struct v2f{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
float4 frag( v2f i ) : COLOR {
return tex2D(_MainTex, i.uv);
}
ENDCG
}
// pass 2
Pass{
// Add parts
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex2;
float4 _TextureOffsetAndSize2;
struct v2f{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
float4 _MainTex2_ST;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex2);
return o;
}
float4 frag( v2f i ) : COLOR {
// * I want to use 1st pass result here * //
float4 tex = tex2D(_MainTex2, i.uv);
tex.x *= tex.w;
tex.y *= tex.w;
tex.z *= tex.w;
return tex;
}
ENDCG
}
}
Fallback "Diffuse"
}