Попытка объединить оба этих шейдера в "Unlit/ScreenCutoutShader"
. Мои попытки не дали положительных результатов, так как на каждом шаге меня встречала ошибка Shader error in 'Unlit/ScreenCutoutShader': redefinition of '_MainTex' at line 70 (on metal)
.
Вот первый шейдер, который является вырезанным шейдером:
Shader "Unlit/ScreenCutoutShader"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Lighting Off
Cull Back
ZWrite On
ZTest Less
Fog{ Mode Off }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
//float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD1;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
i.screenPos /= i.screenPos.w;
fixed4 col = tex2D(_MainTex, float2(i.screenPos.x, i.screenPos.y));
return col;
}
ENDCG
}
}
}
И второй шейдер, просто шейдер в стиле Wavy Flag, примененный к тому же Quad, что и шейдер выше:
Shader "Custom/FlagWaveCG"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" { }
_WaveSpeed ("Wave Speed", Range(0.0, 150.0)) = 50.0
}
SubShader
{
Pass
{
CULL Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "AutoLight.cginc"
float4 _Color;
sampler2D _MainTex;
float _WaveSpeed;
// vertex input: position, normal
struct appdata {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : POSITION;
float2 uv: TEXCOORD0;
};
v2f vert (appdata v) {
v2f o;
float sinOff=v.vertex.x+v.vertex.y+v.vertex.z;
float t=-_Time*_WaveSpeed;
float fx=v.texcoord.x;
float fy=v.texcoord.x*v.texcoord.y;
v.vertex.x+=sin(t*1.45+sinOff)*fx*0.5;
v.vertex.y=sin(t*3.12+sinOff)*fx*0.5-fy*0.9;
v.vertex.z-=sin(t*2.2+sinOff)*fx*0.2;
o.pos = UnityObjectToClipPos( v.vertex );
o.uv = v.texcoord;
return o;
}
float4 frag (v2f i) : COLOR
{
half4 color = tex2D(_MainTex, i.uv);
return color;
}
ENDCG
SetTexture [_MainTex] {combine texture}
}
}
Fallback "VertexLit"
}
И вот как я сейчас пытаюсь скомбинировать:
Shader "Custom/FlagWaveCG"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Texture", 2D) = "white" { }
_WaveSpeed ("Wave Speed", Range(0.0, 150.0)) = 50.0
}
SubShader
{
Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Lighting Off
Cull Back
ZWrite On
ZTest Less
Fog{ Mode Off }
Pass
{
CULL Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "AutoLight.cginc"
float4 _Color;
sampler2D _MainTex;
float _WaveSpeed;
// vertex input: position, normal
struct appdata {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
float2 uv : TEXCOORD1;
};
struct v2f {
float4 pos : POSITION;
float2 uv: TEXCOORD0;
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD2;
};
v2f vert (appdata v) {
v2f o;
float sinOff=v.vertex.x+v.vertex.y+v.vertex.z;
float t=-_Time*_WaveSpeed;
float fx=v.texcoord.x;
float fy=v.texcoord.x*v.texcoord.y;
v.vertex.x+=sin(t*1.45+sinOff)*fx*0.5;
v.vertex.y=sin(t*3.12+sinOff)*fx*0.5-fy*0.9;
v.vertex.z-=sin(t*2.2+sinOff)*fx*0.2;
o.pos = UnityObjectToClipPos( v.vertex );
o.uv = v.texcoord;
o.vertex = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
i.screenPos /= i.screenPos.w;
fixed4 col = tex2D(_MainTex, float2(i.screenPos.x, i.screenPos.y));
return col;
}
float4 frag (v2f i) : COLOR
{
half4 color = tex2D(_MainTex, i.uv);
return color;
}
ENDCG
SetTexture [_MainTex] {combine texture}
}
}
Fallback "VertexLit"
}
вышеизложенное дает мне ошибку: Shader error in 'Custom/FlagWaveCG': redefinition of '_MainTex' at line 70 (on metal)
Любая помощь в правильном направлении будет принята с благодарностью. Заранее спасибо.