Can't get transform position on tilemap?

Hello,

I’m trying to fix a shader that is supposed to apply a noise effect on a tilemap based object. Here is the shader, i’ve simplified it as much as possible for readability:

upload_2023-9-3_14-55-31.png

The issue i’m having is that if my tilemap is moving (which is often the case since i’m working on a 2d platformer), the noise effect doesn’t move with the object, which gives a weird result.

If i remove the position node from the lower left, the noise now moves with the object as expected but is now applied per tile, which is not what i want. I’ve tried feeding it with an “object” node instead, obtaining the same result.

I’ve also tried doing via a script that updates an exposed variable in the shader. This gives the expected result, except for the fact that the performance seems to be poor. The motion was janky and it seemed that the shader update was a few frames behind the game since when the object was moving right the shader was slightly offseted to the left and vice-versa, which makes me think i have to find a way to do it natively in the shader.

public class UpdateTransformPosition : MonoBehaviour
{
    Material _material;
    const string TransformProperty = "_TransformPosition";
    Vector2 _initialPosition;
    Transform _transform;
    static readonly int TransformPosition = Shader.PropertyToID(TransformProperty);
 
    // Fetching components etc
    void Start()  {  }
 
    void Update()
    {
        var newPosition = _initialPosition - (Vector2)_transform.position;
        _material.SetVector( TransformPosition, newPosition );
    }
}