# How do I colour a fluid simulation in Cycles based on velocity?

I want to assign a gradient to the water simulations I have. I want to do this by the velocity in the current voxel, so the fastest moving areas will be red and the slowest blue.

How would this be accomplished using blender cycles nodes?

• This feature is not possible using the current fluid-simulation, download a mantaflow-build. You have more chance to access the particle velocity there... Commented Dec 30, 2017 at 16:36
• What kind of simulation do you have: Particle, external import, or Blender Fluid sim? Commented Dec 31, 2017 at 1:10
• @ScottMilner Blenders fluid sim, I was think the attribute node could be used in a way to get the fluids velocity and colour that against a gradient but I cannot see a way of doing it Commented Dec 31, 2017 at 9:27
• I've edited my answer to simplify the setup for particle velocity and particle speed. See the second answer below. Commented Mar 8, 2021 at 13:12

In Blender 2.82 and later, the fluid simulation engine used in previous versions has been replaced with Mantaflow. When Mantaflow simulates the fluid it provides a particle system that can be used to determine the velocity of the fluid in that region of the simulation.

To achieve this, use a Point Density node set to the Liquid Domain object with the Liquid particle system with a material similar to the following :

This takes the Object coordinates and converts into World coordinates - this is required as the particle system is always defined with respect to world coordinates. The Point Density defined the Object (the domain) and the particle system (Liquid) using World Space. Set the Radius to a suitable value such that the influence of each particle is large enough to prevent gaps and select Particle Velocity for the Color Space. The Color output will now represent the velocity of that section of fluid (with RGB representing X,Y,Z velocities.

In my example I used Separate, Absolute, Combine nodes to avoid negative values for use to colour the mesh for demonstration purposes. You can use a Vector Math 'Distance' node to convert the Color directly into a 'speed' instead, if desired.

Note that the Point Density can only be used with Cycles (ie, not Eevee).

The answer by @RichSedman is perfect but you can get the same result with a much easier setup:

First of all, you don't need a Texture Coordinate node and no Vector Transform node unless you want to modify the texture coordinates. And you can get rid of all those Separate, Absolute and Combine nodes as well.

The only thing you need is the Point Density node where you choose your domain as Object and Liquid as the Particle System and Space > World Space. For the Interpolation you can choose whatever you like, while Linear and Cubic result in smooher color transitions than Closest. Then choose Color Source > Particle Velocity. Plug the Color output into a Vector Math node set to Absolute to avoid negative values. The result you can either use as color for Principled, Diffuse, Emission etc.

If you just want to colorize the speed of the particles set the Color Source to Particle Speed instead of Particle Velocity. You'll then get greyscale values where the speed is mapped from 0 to 1 which you can plug directly into a Color Ramp and give them the colors you want, with a color for the slowest speed on the left and the highest speed on the right. Add as many colors inbetween as you like.

If your fluid particles are too slow for your taste, so that the color from most of the mesh stays on the right side, you might consider to increase the speed values with a Math node set to either Multiply or Add between the Point Density and Color Ramp nodes.

1. Particle velocity:

2. Particle speed:

• Could you adapt this answer to get the doppler-effect requested in this question, by taking the dot-product of the velocity with the normalized vector from the particle's position to a defined viewing-point? I'm tempted, but inexperienced with fluids. Commented Mar 8, 2021 at 13:38
• I have no knowledge of the things illustrated there, but the thing I get out of that is red symbolizes upward movement and blue downward movement. In the first answer the color is separated into XYZ values, I guess there it would be possible to get the Z velocity from -1 (down) to 1 (up). Making those values absolute would get rid of negative values resulting in black, and some Greater Than math node could switch between red and blue. Or instead of Absolute you could use a Map Range node mapping -1 to 1 values to 0 to 1. Combining these informations could produce desired results. Commented Mar 8, 2021 at 13:51
• The color-coding is 'Towards Probe', and 'Away From Probe', so it would be the dot-product as described.. fully Away -> -1, fully Towards -> 1, map range ( -1 to 1 ) --> (0 to 1), put through a color-ramp. The vector to the probe is [(fixed) probe position] - [particle position], normalised. The velocity could be normalised, too, so only the direction is coded, not the speed-in-that-direction. Commented Mar 8, 2021 at 14:04
• You have definitely more technical background on what is happening there than me. The Vector Math node has a Dot Product function so it should be no problem to enter to vectors there. But I'm not sure if it functions as expected since the particle velocities are all given in relation to world coordinates. But as I said, I'm lacking the technological background to understand what there is to do. Commented Mar 8, 2021 at 14:17
• @RichSedman Don't worry, it's all fine - as I said in my answer, yours is perfect. Mine is more like "if you want to have an easy way and don't care for perfection" 😆 Commented Jun 8, 2021 at 9:11