I was asked today to create a shader that tiles a texture based on world space coordinates rather than in UV space, essentially creating a top-down planar projection. For example, this would allow you to use a much smaller plane to create the illusion of it extending infinitely into world space.

It turned out to be a rather simple and inexpensive trick (1 extra ALU call over mesh uvs), so i decided to share. Here is the implementation in Unity via the Strumpy Shader Editor:

It turned out to be a rather simple and inexpensive trick (1 extra ALU call over mesh uvs), so i decided to share. Here is the implementation in Unity via the Strumpy Shader Editor:

First, we simply take the world position of the pixel being rendered and assemble a Vector2 from it. Since this was done in Unity, we ignore Y as that is world-up. In the case of UDK, we would use Y in place of Z. After we have assembled our Vector2, we multiply it by the global scale of the projection (0.1 in this example), and then add another Vector2 of 0.5,0.5 to recenter the projection. This is then used in place of MeshUVs wherever appropriate in the shader.

You will probably want the global scale as a parameter, so that you can find a projection that works for you.

You will probably want the global scale as a parameter, so that you can find a projection that works for you.