• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Ochreous · Sep 22, 2014 at 12:57 AM · shadermissing

Shader Missing Semantics?

I'm getting two errors from my shader saying I've got missing semantics on line 103 and 118. What does this error mean? Here's what the error messages say.

 'vert': function return value missing semantics at line 103

 'frag': input parameter 'i' missing semantics at line 118
 

I believe the lines that the error message are pointing to are incorrect. I think I've found the correct lines below marked with // Missing Semantics. What exactly is wrong with the code and how do I fix it?

         v2f vert (a2v v) // Missing Semantics
         {
             v2f o;
             //Create a rotation matrix for tangent space
             TANGENT_SPACE_ROTATION;
             //Store the light's direction in tangent space
             o.lightDirection = mul(rotation, ObjSpaceLightDir(v.vertex));
             //Transform the vertex to projection space
             o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
             //Get the UV coordinates
             o.uv = TRANSFORM_TEX (v.texcoord, _MainTex); 
             o.uv2 = TRANSFORM_TEX (v.texcoord, _Bump);
             return o;
         }
 
         float4 frag(v2f i) : COLOR // Missing Semantics
         {
             //Get the color of the pixel from the texture
             float4 c = tex2D (_MainTex, i.uv); 
             //Merge the colours
             c.rgb = (floor(c.rgb*_ColorMerge)/_ColorMerge);
 
             //Get the normal from the bump map
             float3 n =  UnpackNormal(tex2D (_Bump, i.uv2));
 
             //Based on the ambient light
             float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz;
 
             //Work out this distance of the light
             float lengthSq = dot(i.lightDirection, i.lightDirection);
             //Fix the attenuation based on the distance
             float atten = 1.0 / (1.0 + lengthSq);
             //Angle to the light
             float diff = saturate (dot (n, normalize(i.lightDirection))); 
             //Perform our toon light mapping
             diff = tex2D(_Ramp, float2(diff, 0.5));
             //Update the colour
             lightColor += _LightColor0.rgb * (diff * atten);
             //Product the final color
             c.rgb = lightColor * c.rgb * 2;
             return c;
 
         }
 











Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by MartinCA · Sep 22, 2014 at 05:33 AM

Semantics defines how data fields in the shader code are bound to data channels on the hardware. Additionally, since vertex and fragment programs are run in different steps most hardware and languages will require any data passed between the programs to be bount to specific channels.

You code snippet is missing the v2f structure definition - my guess is you're missing a semantics definition on one of the fields there.

( a semantic definition is the value specified after the field or method definition, in your case in frag() : COLOR you define you're binding the result of your fragment operation to the color channel. Make sure you have such definitions for each field in your v2f struct )

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ochreous · Sep 22, 2014 at 07:07 PM 0
Share

Ok I've added the variable float4 color : COLOR; to each of my v2f structures. However I'm still getting the error for missing semantics. Any ideas if something else might be causing this error? I can't post the entire shader in one post because it's too large. So I will post it in two halfs.

 Shader "Custom/OutlineToonShader" {
     Properties {
         _$$anonymous$$ainTex ("Base (RGB)", 2D) = "white" {}
         _Bump ("Bump", 2D) = "bump" {}
         _Color$$anonymous$$erge ("Color $$anonymous$$erge", Range(0.1,20000)) = 8
         _Ramp ("Ramp Texture", 2D) = "white" {}
         _Outline ("Outline", Range(0, 0.15)) = 0.08
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
  
         Pass {
  
             Cull Front
             Lighting Off
             ZWrite On
             Tags { "Light$$anonymous$$ode"="ForwardBase" }
  
             CGPROGRA$$anonymous$$
             #pragma vertex vert
             #pragma fragment frag
  
             #include "UnityCG.cginc"
             struct a2v
             {
                 float4 vertex : POSITION;
                 float3 normal : NOR$$anonymous$$AL;
                 float3 tangent : TANGENT;
             };
  
             struct v2f
             {
                 float4 pos : POSITION;
                 float4 color : COLOR;
             };
  
             float _Outline;
  
             v2f vert (a2v v)
             {
                 v2f o;
                 float4 pos = mul( UNITY_$$anonymous$$ATRIX_$$anonymous$$V, v.vertex);
                 float3 normal = mul( (float3x3)UNITY_$$anonymous$$ATRIX_IT_$$anonymous$$V, v.normal); 
                 normal.z = -0.4;
                 pos = pos + float4(normalize(normal),0) * _Outline;
                 o.pos = mul(UNITY_$$anonymous$$ATRIX_P, pos);
  
                 return o;
             }
  
             float4 frag (v2f IN) : COLOR
             {
                 return float(0);
             }
  
             ENDCG
  
         }
  
         Pass {
  
             Cull Back
             Lighting On
             Tags { "Light$$anonymous$$ode"="ForwardBase" }
  
             CGPROGRA$$anonymous$$
 // Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members lightDirection)
 #pragma exclude_renderers d3d11 xbox360
             #pragma vertex vert
             #pragma fragment frag
  
             #include "UnityCG.cginc"
             uniform float4 _LightColor0;
  
             sampler2D _$$anonymous$$ainTex;
             sampler2D _Bump;
avatar image Ochreous · Sep 22, 2014 at 07:19 PM 0
Share
             sampler2D _Ramp;
  
             float4 _$$anonymous$$ainTex_ST;
             float4 _Bump_ST;
  
             float _Tooniness;
             float _Color$$anonymous$$erge;
  
             struct a2v
             {
                 float4 vertex : POSITION;
                 float3 normal : NOR$$anonymous$$AL;
                 float4 texcoord : TEXCOORD0;
                 float4 tangent : TANGENT;
  
             };
  
             struct v2f
             {
                 float4 pos : POSITION;
                 float2 uv : TEXCOORD0;
                 float2 uv2 : TEXCOORD1;
                 float3 lightDirection;
                 float4 color : COLOR;
  
             };
  
             v2f vert (a2v v)
             {
                 v2f o;
                 //Create a rotation matrix for tangent space
                 TANGENT_SPACE_ROTATION;
                 //Store the light's direction in tangent space
                 o.lightDirection = mul(rotation, ObjSpaceLightDir(v.vertex));
                 //Transform the vertex to projection space
                 o.pos = mul( UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, v.vertex);
                 //Get the UV coordinates
                 o.uv = TRANSFOR$$anonymous$$_TEX (v.texcoord, _$$anonymous$$ainTex); 
                 o.uv2 = TRANSFOR$$anonymous$$_TEX (v.texcoord, _Bump);
                 return o;
             }
  
             float4 frag(v2f i) : COLOR 
             {
                 //Get the color of the pixel from the texture
                 float4 c = tex2D (_$$anonymous$$ainTex, i.uv); 
                 //$$anonymous$$erge the colours
                 c.rgb = (floor(c.rgb*_Color$$anonymous$$erge)/_Color$$anonymous$$erge);
  
                 //Get the normal from the bump map
                 float3 n =  UnpackNormal(tex2D (_Bump, i.uv2));
  
                 //Based on the ambient light
                 float3 lightColor = UNITY_LIGHT$$anonymous$$O$$anonymous$$_A$$anonymous$$BIENT.xyz;
  
                 //Work out this distance of the light
                 float lengthSq = dot(i.lightDirection, i.lightDirection);
                 //Fix the attenuation based on the distance
                 float atten = 1.0 / (1.0 + lengthSq);
                 //Angle to the light
                 float diff = saturate (dot (n, normalize(i.lightDirection))); 
                 //Perform our toon light mapping
                 diff = tex2D(_Ramp, float2(diff, 0.5));
                 //Update the colour
                 lightColor += _LightColor0.rgb * (diff * atten);
                 //Product the final color
                 c.rgb = lightColor * c.rgb * 2;
                 return c;
  
             }
  
             ENDCG
         }
  
     }
     FallBack "Diffuse"
 }
avatar image MartinCA · Sep 23, 2014 at 10:36 PM 0
Share

Sorry for the late reply, don't get notifications for comments for some reason.

Anyhow, I think this comment pretty much sums up your problem

// Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members lightDirection)

Your second pass declares lightDirection without a semantic. You can change that line to something along these lines float3 lightDirection : TEXCOORD2;

This will bind the data to texcoord channel 3 (count starts at 0), you have 8 texcoord channels available, you can easily exploit some of them for miscellaneous data. As a rule of thumb, TEXCOORD0 is usually uv data, TEXCOORD1 is used by Unity for lightmap UVs, and the rest are usable by you.

avatar image Ochreous · Sep 24, 2014 at 04:43 AM 0
Share

It worked thanks for the help

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Adding Transparency to Custom Unity Shader 1 Answer

Particles/Additive Shader not showing in Android 0 Answers

What is the most common shader model (2.0+,3.0+,4.0+) for unity web player users (or an average) 1 Answer

Hatching shader (Two o.Albedo ?) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges