Passing data from a vertex shader to the next frame to interpolate vertex position

Godot Version



I’m working on a shader that reads an offset encoded into a texture color channel, and then moves each vertex along an axis by that amount. It works as intended, however I would like to interpolate the offset of the vertex such that, instead of snapping to the given offset, it gradually moves from it’s current position (more specifically, the offset evaluated in the previous frame) to the target position.

For instance:
Previous offset: 20, target offset: 50. Vertex moves to 35. Next frame, if the target didn’t change, it would maybe move to 42.5, and so forth.

I really cannot think of a way of achieving this without being able to write data out of the shader somehow, as only the vertex shader is aware of the previous frame’s offset. Maybe I’m missing something, but I haven’t found any way to write data into any kind of buffer to be used in the next frame. I’ve seen mentions of viewports, but I don’t think that would work given that the shader would need to be on the viewport itself create the render texture, losing access to the other model’s vertices.

Any advice would be greatly appreciated!