I’ll preface this by saying I have a basic understanding of OSL and a solid understanding of vector math.
I am attempting to create a turbulent fluid texture that I will use for gas giant planet atmospheres (such as Jupiter’s cloud belts and zones) and other fluid-y uses. I found a method implemented as part of a game. Here are some example images: http://imgur.com/a/9LipP
The author of the images, Steve Cameron, has his code posted on GitHub and he includes a slideshow where he describes a method by Bridson for generating a realistic, but fake, turbulent fluid velocity field: http://smcameron.github.io/space-nerds-in-space/gaseous-giganticus-slides/slideshow.html#1
Cameron’s texture is some combination of OpenGL and/or C++. I’m not familiar with either of those languages, but I understand the math concepts behind Bridson’s method.
I’m trying to implement this technique in OSL for use in Blender. I have created a procedural velocity vector field based on Bridson’s method and a function to generate a distribution of particles to move in the texture space according to the velocity field. I currently visualize these particles as white dots with user-defined radii.
I am looking for some guidance in OSL programming at this point in my project.
In a test script I’ve written, I am able to modify the positions of the particles according to a simple function like sin(x) which introduces a regular wave pattern in the particles’ positions. However, when I use the same function to sample my procedural velocity field (vx,vy) the particles are distorted in shape and do not seem to trace the local velocity at each particle position. Instead, I am getting a disconnected sequence of irregular spots.
I’ve read Michel Anders’ excellent book on OSL and the OSL documentation. I find no reference to sampling a point-like variable at a specific x,y. I need a function call something like VelocityField(particle_x, particle_y).
I fear this type of call isn’t possible in OSL, but I hope there is some creative way to accomplish the same thing. As I understand it, the sampling of the texture is left up to the renderer, so the specific coordinates within the texture aren’t known until the renderer executes the shader. But, as I said, I’m still learning the “OSL” way of programming.
I’m attaching a zip file that contains my blend file, my osl file, a copy of Anders’ “haltonsequence.h” file, and an image that illustrates the velocity-tracing effect I’m currently trying to achieve (as a step along the way to distorted texture coordinates).
Perhaps I’m approaching the idea of warping the texture coordinates naively. I’m certainly open to other methods that mimic Cameron’s gas giants’ appearance or any other method for achieving the look of our Solar System’s gas giants.
Thanks in advance!
fluid-trace.zip (463 KB)