Access shared mesh vertex data?

Is there a way to access the local vertex positions of a mesh before it is deformed from within a shader? e.g a skinned mesh renderer of an animated character. I am trying to write a shader that applies different colours to the left and right halves of a character, but if for instance, the right hand crosses over to the left side of the body, it gets assigned the left half colour and I don’t want that. I know I could achieve what I want by assigning vertex colours to one half, but I don’t want to take that approach because I would have to do that for every single mesh that uses the shader.

For skinned meshes specifically, because of the way Unity handles these, encoding the data you need into the vertex color or an extra UV is the only option you have. By the time a skinned mesh is seen by your shader the vertex positions have already been transformed and there’s no way to access the unmodified positions and normals otherwise.

If this is something you’ll need on most of your meshes you can write an asset import script that runs when Unity imports an asset and add the data you need (ie: copy the default mesh positions into UV2). Alternately you can look at using additional vertex streams to add data to meshes at runtime. Also note the UV sets are all Vector4 / float4 even though by default Unity only uses the first two components for UVs, so you could write an asset importer that copies the mesh UVs from the first UV set and just adds the mesh’s local x coordinate to the z component.