【问题标题】:Shader error on Unity3D building processUnity3D构建过程中的着色器错误
【发布时间】:2018-04-22 11:58:13
【问题描述】:

我的 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

【问题讨论】:

  • 你为什么在你的着色器中使用h?只需删除任何 h 在您的着色器中,例如 0.5h0.5

标签: unity3d


【解决方案1】:

后缀指定数字类型。它们指示 C# 编译器将整数文字(例如 1000)视为某种类型的数字,例如 long (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
          }
       }
       }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多