How can I remap texture coordinate inputs in shader lab?

In a typical shader lab example, I see a “uv_MainTex”. I would like to not only give it a different name, but bind it to a different set of texture coordinates. Using a custom vertex shader (with the vertex:func modifier) and modifying texcoord (or texcoord1) does not change anything.

Firstly, I would like to know how unity is determining that “uv_MainTex” should be bound to an otherwise logically unrelated set of texture coordinates of a particular mesh.

As mentioned, I would like to change the name and binding. For example: I want to call “uv_MainTex” just plain “uv0” and stream a different set of texture coordinates (like uv1 from a mesh).

I should add that the stream specifiers (like “float4 yarp : TEXCOORD1”) are either completely ignored, or something is just copying the texture coordinates. Whenever I use them, I end up with the same sets of texture coordinates regardless of their presence, except that if a mesh has two sets thereof, specifying something like:

struct yep
{
    float4 v : POSITION;
    float4 uv0 : TEXCOORD0;
    float4 uv1 : TEXCOORD1;
};

the texture coordinates in “uv0” will be streamed into “uv1” regardless. Examining the contents of the “uv1” member of the mesh used reveals the original second set of texture coordinates is intact.

Good question :slight_smile: I started to wonder about that myself :slight_smile:

This explains it: Unity - Manual: Writing Surface Shaders

It looks like you want to use uv2 with one of the textures, then you have to use this naming convention: uv2_MainTex