"Write a GLSL Material" article is unclear about what texture coordinate layers are

In Working with Geometry Attributes section it is written that vertex shader attributes such as uv[8] (texture coordinate layers) will always be declared for you. I cannot find information on what these layers are exactly or where they are defined. What’s the difference between writing uv[0].xy or uv[2].xy in a vertex shader?

If you middle mouse click on a sop, you’ll “usually” see that uv0 is defined. when I say uv0 I mean the first set of 3 uv coordinates (u,v, and w). See the screenshot below of a standard box SOP:
image

It’s possible to lay out multiple versions of a SOP’s uv’s and assign them to different uv “layers”. If you drop a texture SOP down, you can set the Texture Layer parameter at the top, and any changes you make will write those uv’s to that texture layer. If you set texture layer to 1, you’ll see that middle mouse clicking on the sop shows uv[6] instead indicating there are 2 sets of uvs:

You can then access this in the vertex shader slightly differently. uv[0] is your uvw coordinates from layer 0, and uv[1] will give you your uvw coordinates from layer 1, and so forth.


One point to be clear on, if in the above example you create a new uv set on texture layer 2, but nothing on texture layer 1, middle mouse clicking will show you uv[9] because of how the reporting works. technically though what’s in uv[1] will just be a bunch of zero’s since you never explicitly wrote anything to them, and skipped over them to uv[2].

So just be sure you’re not fooled by what the sop info tells you, and be wary of setting and retrieving from consistent uv layers and you’ll be good :slight_smile:

2 Likes

Thanks, Lucas! Super clear explanation :slight_smile:

1 Like