However, when I try to declare my Surface shader input struct with a UV declared as a float4:
struct Input {
float4 color : COLOR;
float4 uv_emissionColor;
};
I get an error stating, “cannot implicitly convert from ‘const float2’ to ‘float4’”.
Is it possible to access all four elements of the UV (when passed as Vector4) in the Surface shader, or are the last two elements ( zw / ba) inaccessible?
For context, I am trying to pass a second Color - for emission - on a per vertex basis to a custom shader. I know I could split the Color across two float2 UVs, but I would rather not do this if I can avoid it.
I’ve answered my own question, so I’ll post that here in case someone else might find it useful.
My question was the result of a basic misunderstanding of the UV fields on the Surface shader. Since Surface shaders operate on a per-pixel basis, these field contain the UV value of the pixel as translated between UV values of the relevant vertices. So, my original question was a comparison between apples (UV coordinates of the vertex as set on the Mesh [per vertex]) and oranges (UV fields on the Surface shader input struct [per pixel, translated]).
To achieve what I wanted to - passing an additional per vertex Color value to the Surface shader by setting a Vector4 on the Mesh - I needed to add a Vertex shader to pass the input. The Surface Shader documentation, section Custom data computed per-vertex, provides an explanation of how to do this. I will provide a brief example based on this explanation (which worked for my case):