首页 > 解决方案 > 着色器错误:函数返回值缺少语义

问题描述

我在着色器代码中缺少语义错误。我该如何解决?

“文本框/平滑渐变”中的着色器错误:“vert”:函数返回值在第 39 行缺少语义(在 d3d9 上)。

“文本框/平滑渐变”中的着色器错误:“frag”:输入参数“f”在第 48 行缺少语义(在 d3d9 上)。

 // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

 // Copyright 2012, Catlike Coding
 // http://catlikecoding.com/
 // Version 1.0
 // Variant of the "Text Box/Smooth" shader that subtly fades by increasing Edge Maximum.
 Shader "Text Box/Smooth Fade"{
     Properties{
         _MainTex("Distance Map (Alpha)", 2D) = "white" {}
         _EdgeMin("Edge Minimum (Outside)", Float) = 0.45
         _EdgeMax("Edge Maximum (Inside)", Float) = 0.55
         _FadeDistance("Fade Distance (Begin)", Float) = 10
         _FadeStrength("Fade Strength (Increase per Unit)", Float) = 1
     }
     SubShader{
         Tags{ "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
         Blend SrcAlpha OneMinusSrcAlpha
 //        Cull Off // use this to make it visible from behind
         Lighting Off
         ZWrite Off
         Pass{
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag

             #include "CC Text CG.cginc"

             sampler2D _MainTex;
             fixed _EdgeMin, _EdgeMax;
             float _FadeDistance, _FadeStrength;

             struct v2f {
                 float4 pos : SV_POSITION;
                 fixed4 color: COLOR;
                 half2 uv : TEXCOORD0;
                 fixed fade;
             };

             v2f vert (cc_text_u2v v)  { // <========= error1
                 v2f o;
                 o.pos = UnityObjectToClipPos(v.vertex);
                 o.color = v.color;
                 o.uv = v.texcoord;
                 o.fade = lerp(_EdgeMax, 1, saturate(((length(mul(UNITY_MATRIX_MV, v.vertex)) - _FadeDistance)) * _FadeStrength));
                 return o;
             }

             fixed4 frag(v2f f) : COLOR {   // <========= error2
                 f.color.a *= smoothstep(_EdgeMin, f.fade, tex2D(_MainTex, f.uv).a);
                 return f.color;
             }

 //            version that includes texture RGB
 //            fixed4 frag(v2f f) : COLOR {
 //                fixed4 t = tex2D(_MainTex, f.uv);
 //                f.color.rgb *= t;
 //                f.color.a *= smoothstep(_EdgeMin, f.fade, t.a);
 //                return f.color;
 //            }
             ENDCG
         }
     }
     Fallback "Text Box/Smooth"
 }

标签: unity3dshader

解决方案


在您的struct v2f定义中,fixed fade;缺少语义。

例如float4 pos,使用 的用法进行标记SV_POSITION,但不标记淡入淡出。

阅读Semantics


推荐阅读