对于熟悉着色器的人来说,这似乎是非常基本的,但我现在有两个着色器,第一个只是滚动一个纹理两次,它到目前为止应该工作。
第二个着色器是仅使用另一个纹理作为alpha蒙版的那个。
如何组合这两个着色器,以便第一个着色器中两个滚动mainTex的结果将以与第二个着色器相同的方式进行alpha屏蔽?
第一个着色器,带有2个滚动的mainTex
Shader "Custom/TwoScrolling" {
Properties {
_MainTex ("Rays texture", 2D) = "white" {}
_speed ("Speed", Float) = 0.2
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha One
Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
float _speed;
float4 frag(v2f_img i) : COLOR {
i.uv.x += cos(_Time*_speed);
return tex2D(_MainTex, i.uv);
}
ENDCG
}
Pass {
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
float _speed;
float4 frag(v2f_img i) : COLOR {
i.uv.x += sin(_Time*_speed);
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
}
}
具有单独alpha遮罩的第二个着色器
Shader "Separate Alpha Mask" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Alpha ("Alpha (A)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Transparent" "Queue" = "Transparent"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Pass {
SetTexture[_MainTex] {
Combine texture
}
SetTexture[_Alpha] {
Combine previous, texture
}
}
}
}