Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Issue with worldspace UV

Discussion in 'Shaders' started by BrianND, Jan 23, 2018.

  1. BrianND

    BrianND

    Joined:
    May 14, 2015
    Posts:
    79
    Hi I have a shader that uses world space xz to uv map an object

    vertex

    Code (CSharp):
    1. float2 worldSpaceUV = mul(unity_ObjectToWorld, v.vertex).xz;
    fragment

    Code (CSharp):
    1. fixed4 col = tex2D(_SomeTex, IN.worldSpaceUV);
    The problem is that the texture gets distorted on some models. The object itself is positioned at x = 1000 so I think it's a precision issue.

    I've tried resolving using these methods but nothing helps. It looks fine on PC but iOS
    - Change all shader precision to float
    - Disable all static batching
    - Disable mesh compression and optimisations

    The only fix I have is to reposition the object to 0, 0, 0. It looks like just by moving the mesh I lose a bunch of precision. I wouldn't expect to have such a huge drop off.