Unity3d 尝试为Unity项目组合两个着色器-剪切着色器和运动着色器

Unity3d 尝试为Unity项目组合两个着色器-剪切着色器和运动着色器,unity3d,shader,Unity3d,Shader,正在尝试将这两个着色器合成为“unlight/ScreenCutoutShader”。我的尝试没有产生任何积极的结果,因为我在“Unlight/ScreenCutoutShader”中遇到了错误着色器错误:在每一步的第70行(金属上)重新定义“_MainTex” 以下是第一个明暗器,它是一个剪切明暗器: Shader "Unlit/ScreenCutoutShader" { Properties { _MainTex ("Texture", 2D) = "

正在尝试将这两个着色器合成为
“unlight/ScreenCutoutShader”
。我的尝试没有产生任何积极的结果,因为我在“Unlight/ScreenCutoutShader”中遇到了错误
着色器错误:在每一步的第70行(金属上)
重新定义“_MainTex”

以下是第一个明暗器,它是一个剪切明暗器:

    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
       }
     }
   }
第二个着色器是一个简单的波浪旗样式着色器,应用于与上面的着色器相同的四边形:

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"
  }
上面给出了错误:
Custom/FlagWaveCG中的着色器错误:在第70行(金属上)重新定义“\u MainTex”


任何方向正确的帮助都将不胜感激。提前谢谢。

嗨!到目前为止,您的组合着色器代码是什么?(您的错误消息听起来有点像_MainTex声明了两次。)@PhilippLenssen Hi!很抱歉延迟回复。正如我所怀疑的那样,你的_MainTex声明了两次——如果你在第二次编写
sampler2D _MainTex时删除了它会发生什么?嗨!到目前为止,您的组合着色器代码是什么?(您的错误消息听起来有点像_MainTex声明了两次。)@PhilippLenssen Hi!很抱歉延迟回复。正如我所怀疑的那样,你的_MainTex声明了两次——如果你在第二次编写
sampler2D _MainTex时删除了它会发生什么