Search Unity

Help Wanted Any way to get object's initial position?

Discussion in 'Shader Graph' started by dgoyette, Sep 9, 2019.

  1. dgoyette


    Jul 1, 2016
    I have a WorldUV shader that I use on some static objects, so that they can be scaled to have their texture repeat and tile. I believe the approach I'm using is based on something I saw on this page (, and it depends on accessing the position of each pixel via the Position node:


    This works fine for static objects, but the downside is that I can't use it for dynamic/moving objects. If I do, the texture will move along the surface rather than staying with the mesh. Ideally there would be a way to access the "initial" position of a pixel, and use that to base the World UV on, so that the texture will move with the object. The only approach I can think of is to put a script on every object with this shader, which sets a shader parameter of "Initial Position", and then offsets the pixel position by that initial position. I'm not 100% sure that even works, given the possibility of an object rotating or scaling.

    Anyway, I was wondering if anyone had any ideas on how to set up a World UV shader that allows me to move the object without the texture moving around.

    Edit: I figured I should also explain what I'm trying to accomplish overall, in case there's a better way.

    For most of the large surfaces in my levels, I use a Lit shader with a secondary texture, where the secondary texture is scaled up about 10x to add some variation to the surface, and reduce the repetitive look of tiles. This works fine when all surfaces are static, but I also have some moving walls like this:


    The problem with moving walls is that the UV for the secondary texture generally won't line up with the static wall it's placed next to, which can make the moving piece really stick out. What I want to do was to make the Secondary Texture draw using World UV, so that it will always line up between the static and moving wall pieces. But if I make it World UV, then the texture will scroll on the moving wall when the wall moves.

    So, ultimately I want that secondary texture to use World UV based on the starting position of the object, rather than the current position.
    Last edited: Sep 9, 2019