- Home /
Adding worldspace offset to substance UVs
I've got a model that's being repeated in a small space - doors on kitchen cabinets specifically. I've got a basic system that lets me swap meshes and materials onto standard sized cabinet units, and that's letting me add a lot of variation into repeated buildings in an open world.
However, because the meshes (including UVs) are shared, every door has the same section of the material applied to it:
As you can see, each door looks identical. I'm using X/Y tiling substances for these materials, so my solution was to simply offset the UVs. I want to retain the ability to batch all these together effectively, so I wrote a shader to factor in the object position to the UVs:
float2 WorldOffset(float3 pos, float2 uv)
{
return float2(
(pos.x + pos.y + pos.z * 123) + uv.x,
(pos.x + pos.y + pos.z * 423) + uv.y
);
}
I'm then using unity_ObjectToWorld
to get the world position and applying that method to the UVs before they're used on the samplers.
This works exactly as I wanted, however this is an extremely simple shader. The substances I'm making are designed to work with the standard shader - i.e. packing the inverse roughness into the alpha of the metallic channel and so on. I'd much rather simply apply this minor modification to the standard shader than mimicking all that stuff.
I've downloaded the internal shader pack, but the changes would need to be made down in one of the cgincs, and then it would need to be manually updated each time the Unity version changed.
In short:
Is there a way I can make a tiny modification to the standard shader in a simple, maintainable fashion?