# What is "v.vertex.yyyy" mean

I am new to shader, I found following code when I learn a blur shader:

``````v2f vert(appdata_full v)
{
v2f o;
float4 tmp0;
tmp0 = v.vertex.yyyy * unity_ObjectToWorld._m01_m11_m21_m31;
tmp0 = unity_ObjectToWorld._m02_m12_m22_m32 * v.vertex.zzzz + tmp0;
tmp0 = tmp0 + unity_ObjectToWorld._m03_m13_m23_m33;

...

o.position = unity_MatrixVP._m03_m13_m23_m33 * tmp0.wwww;
o.texcoord.xy = v.texcoord.xy;
return o;
}
``````

There is little information about it on google, I only found something related on Cg_language :

Vector swizzle operator: (.)
a = b.xxyz; // A swizzle operator example

• At least one swizzle character must follow the operator.
• There are three sets of swizzle characters and they may not be mixed: Set one is xyzw = 0123, set two is rgba = 0123, and set three is stpq = 0123.
• The vector swizzle operator may only be applied to vectors or to scalars.
• Applying the vector swizzle operator to a scalar gives the same result as applying the operator to a vector of length one. Thus, myscalar.xxx and float3(myscalar, myscalar, myscalar) yield the same value.
• If only one swizzle character is specified, the result is a scalar not a vector of length one. Therefore, the expression b.y returns a scalar.
• Care is required when swizzling a constant scalar because of ambiguity in the use of the decimal point character. For example, to create a three-vector from a scalar, use one of the following: (1).xxx or 1â€¦xxx or 1.0.xxx or 1.0f.xxx
• The size of the returned vector is determined by the number of swizzle characters. Therefore, the size of the result may be larger or smaller than the size of the original vector. For example, float2(0,1).xxyy and float4(0,0,1,1) yields the same result.

Question:
I am not sure what v.vertex.yyyy or tmp0.wwww is.
If v.vertex equals (1, 2 ,3 ,4), does v.vertex.yyyy equals (2, 2, 2, 2) ?
And is `v.vertex.yyyy * unity_ObjectToWorld._m01_m11_m21_m31;`
equivalent to `mul(unity_ObjectToWorld, float4(y, y, y, y);` which means convert this float4 to world space?

Yes.

No. Itâ€™s equivalent to:
`mul(unity_ObjectToWorld, float4(0,v.vertex.y,0,0));`

Also, a minor word of warning. Regardless of what you may have seen said elsewhere, Unity does not use Cg. Hasnâ€™t for many, many years. Itâ€™s purely HLSL now. That said Cg and DirectX 9 HLSL are very similar, so most of whatâ€™s on that site can still be helpful. Just know sometimes it wonâ€™t be correct because itâ€™s not documentation for HLSL. Also thereâ€™s a lot of stuff in DirectX 11 HLSL that changed significantly and wonâ€™t match Cg at all.

1 Like

Ok, thanks !

Minor correction, but .y would be the second component, so it would be (2,2,2,2) in that case.

1 Like

Oh , yes yes, I will correct that. Thanks for reminding !

whoops, I derped that one