I'm new to shader, so please pardon my lack of knowledge. I am trying to understand what does UV node do in shader graph. I tried searching on google and in https://docs.unity3d.com/Packages/[email protected]/manual/UV-Node.html it was written:

Provides access to the mesh vertex or fragment's UV coordinates. The coordinate channel of the output value can be selected with the Channel dropdown parameter.

Ok so UV node provide access to mesh vertex UV coordinates, then i google what is UV coordinate and in https://docs.unity3d.com/ScriptReference/Mesh-uv.html it was written

Unity stores UVs in 0-1 space. [0,0] represents the bottom-left corner of the texture, and [1,1] represents the top-right. Values are not clamped; you can use values below 0 and above 1 if needed

Ok so UV coordinate is vector2 which represent the 2D coordinate between [0,0] and [1,1]. But in shader graph UV node output vector4 instead of vector2.

enter image description here enter image description here

Where is the error of my understanding? If UV Node supposedly provide access to mesh vertex UV coordinate, then why did it output Vector4 instead of Vector2? can someone please help me clear this confusion ?


1 Answer 1


Texture coordinates are usually 2-dimensional. But developers can add a third or fourth component to achieve some effects, like sampling from a volume texture, specifying which layer of an array texture to read from, or using projective texturing.

You can author these 3D "UVW" coordinates (or 4D coordinates, though I don't know a common name for the fourth component) in your modelling software, or using the Mesh.SetUVs method, which has overrides for working with Vector3 or Vector4 in addition to the usual Vector2.

The Shader Graph does not know a priori which mesh you will use the shader on, or how many dimensions a given UV channel might have, so it errs on the side of too much and picks the largest option supported by a single vertex attribute. That way if you do something unusual with a third or fourth component, you're not locked out of using that vertex data in the graph.

When Unity compiles this graph down to actual shader code, it may make variants that strip out the unneeded components, since it can follow through the graph to see if they're ever used in an expression. That would be worth experimenting with, as I haven't tested that myself yet.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .