Unity3D构建过程中的着色器错误

时间:2018-04-22 01:08:47

标签: unity3d

我的Timer.shader文件有2个错误,但不明白为什么,我是Unity3D的新手

这是错误:

Shader error in 'Timer': 'dot': no matching 0 parameter intrinsic function; Possible intrinsic functions are: dot(floatM|halfM|doubleM|min10floatM|min16floatM|intM|uintM|min12intM|min16intM|min16uintM, floatM|halfM|doubleM|min10floatM|min16floatM|intM|uintM|min12intM|min16intM|min16uintM) at line 51 (on gles3)
Shader error in 'Timer': syntax error: unexpected token 'h' at line 51 (on gles3)

包含错误的文件: Timer.shader

Shader "Timer"
{
   Properties
   {
      _MainTex ("Texture Image", 2D) = "white" {} 
          _SecondTex ("Second Image", 2D) = "white" {} 
          _MaskTime ("Time", Range (0, 1)) = 0
          _MPow ("Pow", Range (5, 50)) = 5
   }
   SubShader
   {
      Pass
          {    
         CGPROGRAM

         #pragma vertex vert  
         #pragma fragment frag 

         sampler2D _MainTex;
                 sampler2D _SecondTex;
                 fixed _MaskTime;
                 fixed _MPow;

         struct vertexInput
                 {
            float4 vertex : POSITION;
            fixed4 texcoord : TEXCOORD0;
         };
         struct vertexOutput
                 {
            fixed4 pos : SV_POSITION;
            fixed2 tex : TEXCOORD0;
         };

         vertexOutput vert (vertexInput input) 
         {
            vertexOutput output;

            output.tex = input.texcoord;
            output.pos = UnityObjectToClipPos (input.vertex);
            return output;
         };

         float4 frag (vertexOutput input) : COLOR
         {
                        fixed3 c0 = tex2D (_MainTex, fixed2 (input.tex));
                        fixed3 c1 = tex2D (_SecondTex, fixed2 (input.tex));

                        fixed dot1 = dot (normalize (input.tex.xy-fixed2 (0.5h, 0.5h)), fixed2 (0h, 1h));

                        half ang = acos (dot1);

                        ang = degrees (ang);
                        ang = (input.tex.x<0.5h)?360h-ang:ang;


                        fixed pos = min ((ang/360h), 360h);
                        pos = pos+0.9h-_MaskTime+(0.2h*(1h-_MaskTime));
                        pos = saturate (pow (pos, _MPow*_MPow));


                        fixed3 c = lerp (c1.rgb, c0, pos);

                        return fixed4 (c, 1h);
                        //return pos;
         }

         ENDCG
      }
   }
   }

如果需要更多信息,请告诉我,因为就像我说我是新手一样,我对此错误并不了解。

我正在尝试构建Android,并且所有内容都崩溃,因为如果我只按播放,一切都会在没有警告的情况下运行。

当然其他平台上的错误触发器,但我假装构建到Android

1 个答案:

答案 0 :(得分:1)

  

后缀指定数字类型。它们指示C#编译器将诸如1000之类的整数文字视为某种类型的数字 - 例如,长(1000L)。我们将研究如何为数字添加数字后缀。

     

https://www.dotnetperls.com/suffix

但是在着色器中你不应该使用后缀。我只是删除任何h在着色器中,例如0.5h0.5并且正常工作

试试这个:

Shader "Timer"
    {
       Properties
       {
          _MainTex ("Texture Image", 2D) = "white" {} 
              _SecondTex ("Second Image", 2D) = "white" {} 
              _MaskTime ("Time", Range (0, 1)) = 0
              _MPow ("Pow", Range (5, 50)) = 5
       }
       SubShader
       {
          Pass
              {    
             CGPROGRAM

             #pragma vertex vert  
             #pragma fragment frag 

             sampler2D _MainTex;
                     sampler2D _SecondTex;
                     fixed _MaskTime;
                     fixed _MPow;

             struct vertexInput
                     {
                float4 vertex : POSITION;
                fixed4 texcoord : TEXCOORD0;
             };
             struct vertexOutput
                     {
                fixed4 pos : SV_POSITION;
                fixed2 tex : TEXCOORD0;
             };

             vertexOutput vert (vertexInput input) 
             {
                vertexOutput output;

                output.tex = input.texcoord;
                output.pos = UnityObjectToClipPos (input.vertex);
                return output;
             };

             float4 frag (vertexOutput input) : COLOR
             {
                            fixed3 c0 = tex2D (_MainTex, fixed2 (input.tex));
                            fixed3 c1 = tex2D (_SecondTex, fixed2 (input.tex));

                            fixed dot1 = dot (normalize (input.tex.xy-fixed2 (0.5, 0.5)), fixed2 (0, 1));

                            half ang = acos (dot1);

                            ang = degrees (ang);
                            ang = (input.tex.x<0.5)?360-ang:ang;


                            fixed pos = min ((ang/360), 360);
                            pos = pos+0.9-_MaskTime+(0.2*(1-_MaskTime));
                            pos = saturate (pow (pos, _MPow*_MPow));


                            fixed3 c = lerp (c1.rgb, c0, pos);

                            return fixed4 (c, 1);
                            //return pos;
             }

             ENDCG
          }
       }
       }