How to adjust texture coordinates with a distortion texture? For a turbulent fluid texture I'm working on, I need to distort texture coordinates in a repeated, step-wise fashion, so this seems like a job for OSL. Specifically, I need to offset each point in a texture by a small amount based on the value in a noisy color texture that represents a velocity field (r=vx, g=vy, b=vz=0).

In the illustration below, I've used small arrows to represent the velocity field rather than the RGB texture I'll actually use. Each blue dot represents a starting point to trace the velocity field. Each blue curve represents a path that is consistent with the local velocity field at each point along the way.



However, the examples I have found here and on other sites offset texture coordinates globally (the same offset or scale applied to the entire texture).

I'm looking for a method to distort texture coordinates non-uniformly in small repeated increments to follow the velocity field similar to the blue curves in the illustration above. I will use the resulting coordinate map to warp a simple color texture.

I can imagine this effect could be achieved with a Particle System and a Turbulence Force Field, but (1) I can't imagine how I would fill the entire surface with color without using an enormous number of overlapping particles and (2) I can't figure out how to constrain the particles to the surface of an arbitrary mesh.

I opted for OSL because I hoped to generate a distorted coordinate system for every point in the texture and let the renderer sample the texture appropriately.
No need for OSL, just use a Converter > Vector Math node.



The above node setup uses the image texture on the left to offset the UV (or any other) texture coordinates by adding the distortion map pixel values to the mapping vectors (RGB is automatically converted to XYZ).



If you want a little more control over the distortion strength  and directionn you can add a Separate RGB and Combine XYZ node and use some math nodes in-between.



With the above node setup you can adjust the strength for each direction independantly, if you want the same strength in all directions and don't want to have to play with 3 different values you can plug an Input > Value node into all 3 math nodes.