# how are semantics used when declaring a struct?

I don't understand how semantics are used in shaders. While reading Unity's shader tutorials, I come across this

struct v2f {
float worldPos: TEXCOORD0;
half3 worldNormal: TEXCOORD1;
float4 pos : SV_POSITION;
};


and also this

       struct v2f {
float3 worldPos : TEXCOORD0;
half3 tspace0 : TEXCOORD1;
half3 tspace1 : TEXCOORD2;
half3 tspace2 : TEXCOORD3;
float2 uv : TEXCOORD4;
float4 pos : SV_POSITION;
};


Microsoft's documentation says

A semantic is a string attached to a shader input or output that conveys information about the intended use of a parameter.

I know there is some kind of interpolation of data because vertices and pixels aren't one to one, thus I think semantics are used for telling the graphics library what to do about the data. But here it uses TEXCOORDX for things like world position and tangent space vectors. They don't seem to have anything to do with UV coordinates. So how are these semantics actully used?

• "from some answers on Unity's forum they say Unity only supports two UV channels" this does not sound accurate based on my experience. :/ Have you tested this claim? Mar 8, 2019 at 1:39
• I'm editing my question, actually, I don't care about that, yet. I need to rephrase something. Mar 8, 2019 at 1:40

Keep in mind that the struct in HLSL is just a language convenience. It doesn't really mean anything in the hardware. You can use HLSL structs to group parameters to shaders and outputs from shaders. They can be used in constant buffers (either globally in the case of legacy Direct3D 9, or in constant buffers in Direct3D 10+ where there's actually some context to the grouping as a cbuffer).
These particular semantics are associated with the outputs of vertex shaders and the inputs of pixel shaders. You must have a SV_Position (or the older POSITION) as that's used to drive the rasterization and invocation of pixel shaders. The rest are just 'interpolators' that calculate smooth values between each vertex on the triangle when drawing. That includes NORMAL, TEXCOORD0, etc. They are often used by shaders with this convention, but there's nothing special about these values in most cases.