Search Unity

How to get the distance of sceneUVs from the "center" UV, when using an atlas texture?

Discussion in 'Shaders' started by Deleted User, Aug 22, 2016.

  1. Deleted User

    Deleted User

    Guest

    1) I'm using at atlas texture, with multiple textures arranged in various placing in the atlas.
    2) Each of these textures within the atlas are entirely for, and used entirely by a single mesh.
    3) Each mesh has just one material, and uses just one of the textures in the atlas, and just one shader.

    THEN, in the shader, I want to know the distance of each UV from the "center" of the texture.

    The problem is: the texture is an atlas, and so I can't compare the UV against a "center" vector of (0.5, 0.5), because that would compare the UV to the center of the entire atlas. But I need to know the distance from the center of just the part of the atlas that this mesh is using.

    AND I want the material to be batch-able, so I can't pass any mesh-specific data to the shader through the shader parameters, because that would be different for each mesh, which would prevent the meshes from being batched, and that ruins the whole point of having the atlas.

    So... can this be done? Thanks :)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    Use an additional UV set that has the UVs as if it wasn't an atlas.
     
    CSCAPromo and Deleted User like this.
  3. Deleted User

    Deleted User

    Guest

    You sir deserve a raise. Thanks again :)