3
$\begingroup$

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.

enter image description here

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.

$\endgroup$
3
$\begingroup$

No need for OSL, just use a Converter > Vector Math node.

enter image description here

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.

enter image description here

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.

$\endgroup$
  • $\begingroup$ If you want to do this in texture nodes (instead of material nodes) you'll use the Distort/At node type. $\endgroup$ – Mutant Bob May 17 '16 at 15:28
  • $\begingroup$ The important issue is that I need to repeat the distortion in small steps to follow the velocity field. I know of no way to do this with just a set of Nodes. I'll edit my question to make this clearer. $\endgroup$ – astrogeek May 17 '16 at 15:36
  • 1
    $\begingroup$ @MutantBob Texture nodes don't work in Cycles. $\endgroup$ – PGmath May 17 '16 at 18:05
  • $\begingroup$ @astrogeek I guess I don't really know what you mean by "small repeated steps". Could you maybe add a picture or something explaining that a little further? $\endgroup$ – PGmath May 17 '16 at 18:06
  • 1
    $\begingroup$ I wonder if the fundamental problem is that he wants the distortions to ACCUMULATE OVER TIME. $\endgroup$ – Mutant Bob May 18 '16 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.