I have a surface shader that needs 3 custom UV sets.
I had this working using uv, uv2, and uv3 but then discovered that uv2 and uv3 are used by the lightmapper because baking lighting breaks my uvs.
I tried just going to higher uv sets but as soon as I try and use uv5 I get errors:
Shader error in 'Custom/TileShader': invalid subscript 'texcoord4' at line 118 (on d3d11)
That error is somewhere internal, my shader doesn’t have 118 lines.
Do surface shaders only have 4 uv sets? I can’t find any documented limit.
I would imagine the cross compilation wasn’t updated to support all 8 texcoords, perhaps for performance reasons.
The workaround here would be to use a custom vertex pass so that you can use a proper input struct instead of this “magic” one that is just interpreted into the proper code. Then you can directly bind a member in the struct to whichever texcoord you want, like float4 tex5 : TEXCOORD4;
Note the vertex:vert in the #pragma to indicate this vert() function should be used for the vertex pass. And addshadow to apply this vertex pass to other shader passes that are generated.
Also, the reason I wrote tex5 in the Input struct instead of say uv5 is because the Surface shader compiler will see the “uv” part and try to automatically convert it, creating the error you mentioned, instead of letting it be a free variable to assign to.
Also, if you add more things to the Input struct that our appadatas struct does not have, you will get an error and have to fix that as well by adding the correct type it wants to the appdatas struct. For example if you added a float4 color; to the Input struct, then you’d need to add float4 color : COLOR; to appdatas.