FluidLabTutorial 01

Mix Two Fluids in Blender: Water and Oil

Mix water and oil in FluidLab 1.2: two InFlow emitters, Fluid Interactions, an OutFlow collider, a GN mesh and two shaders blended with fl_color.

8 steps13 min

In this tutorial we shoot two jets of liquid, water and oil, into a box so they crash into each other, and then blend their shaders on a single mesh so you can see where each fluid ends up.

You will set up two InFlow emitters from presets, make the two groups interact, remove stray particles with an OutFlow collider, mesh the result with Geometry Nodes and mix the materials using the fl_color attribute provided by FluidLab.

Step by step

  1. Step 1

    Set up the water emitter

    The scene has a box collider (Cube_00) and two spheres: one for water and one for oil. Select the first sphere, click Add New Group, rename it water, choose InFlow and click OK. Then click Add Emitter; the group appears in Fluid Groups as G_Water.

    In Fluid Presets, choose Water and click Set Preset to load the water parameters. Then go to Fluid Settings:

    • Emission: in Count | Size, set 50000 and 0.03 m. Frame Start | End is 1 and 100, so the inflow lasts 100 frames, and Lifetime is 185, the length of the timeline. Under Velocity, set Initial Velocity X to 2.7 m/s.
    • Physics: enable Adaptive, raise Subframes from 4 to 7 for more accurate calculations, and raise Mass slightly to 0.11 kg.
    • Emission → Viewport Display: set Display to Material and pick a water-like blue in the color field.
  2. Step 2

    Set up the oil emitter

    Repeat the process with the second sphere: Add New Group named oil with InFlow, then Add Emitter (it appears as G_Oil). In Fluid Presets, choose Oil and click Set Preset.

    In Fluid Settings → Emission, use the same values as the water: 50000 particles of 0.03 m, frames 1 to 100 and Lifetime 185. The difference is the direction: set Initial Velocity X to -2.7 m/s so the two jets shoot towards each other. In Viewport Display, set Display to Material and choose a yellow.

    In Physics, enable Adaptive and set Subframes to 7 as well, but this time lower Mass slightly to 0.08 kg.

  3. Step 3

    Make the fluids interact and stop the spills

    Hide the collider and play the simulation: both fluids flow, but water and oil don't react to each other. Open Fluid Interactions, click Add Interaction, tick G_Water and G_Oil in the dialog and click OK (Interaction_00 appears in the list). Run the simulation again: now the two fluids push against each other.

    Some particles still spill out through the walls of the box. To fix it, go to Colliders, unhide the collider, duplicate it and scale the copy up a little. With the copy selected, click Add Selection Collider and enable OutFlow (Kill Particles) in its Collider Settings: any particle that touches this outer collider is killed, so nothing leaks out. Hide both colliders and rerun the simulation.

    Groups don't interact by default

    Two fluid groups in the same scene simulate without any interaction until you add one in Fluid Interactions.

  4. Step 4

    Save the cache and mesh the fluids

    Click the disk icon next to Current Cache to save the simulation. In the video a file browser opens at that point and the scene is saved as a .blend file.

    Then open Mesh and click Add Mesh. In the Add GN Meshes To: dialog keep G_Water and G_Oil ticked and click OK: a single Geometry Nodes mesh, M_Water, is created for both fluids. In Mesh Settings:

    • Voxel Resolution: lower it to 0.04 for a bit more detail.
    • Size: raise it to 0.07.
    • Smooth XYZ: raise it from 1 to 10 to smooth the surface.

    Finally, hide the particles in the viewport with the eye icons in Fluid Groups so only the mesh is visible.

  5. Step 5

    Preview the mix with the MixColors material

    Open Shading, make sure Assign is active and browse the Materials previews until you reach MixColors (with Fluid selected). Click Assign Material.

    In Settings you'll see its default colors: Color 0 pink and Color 1 green, with Blur at 100. Play the simulation to watch the two fluids mixing. You can change these colors at any time: in the video Color 0 is switched to blue.

  6. Step 6

    Bring the water and oil shaders into one material

    Save the file first. Back in Shading → Assign, pick Water in the materials gallery and click Assign Material; then pick Oil and click Assign Material again. This creates the Water_00 and Oil_00 materials.

    Switch to Blender's Shading workspace and turn on Material Preview: the mesh shows the oil. Press Ctrl+Space to maximize the Shader Editor, select all of the oil's shader nodes and copy them. Open the Water_00 material and paste them. You now have both node trees in the same material: the water nodes on top and the oil nodes below.

  7. Step 7

    Blend both shaders with the fl_color attribute

    Add a Mix Shader and connect the water shader to its first Shader input and the oil shader to the second. For the Fac, add a Color Attribute node and choose fl_color: this is the attribute you use to mix the two shaders. Put a Color Ramp in between: Color of the attribute → Fac of the ramp, and Color of the ramp → Fac of the Mix Shader. Finally, connect the Mix Shader to the Surface input of the Material Output.

    The mesh's material is set in its Geometry Nodes modifier. Open the Modifier Properties and, in FluidLab_Mesh_GN_00, change Material from Oil_00 to Water_00, the material you are building the mix in.

    Fine-tune the Color Ramp by bringing its two stops close together to sharpen the boundary. Now you can clearly tell the oil side from the water side.

  8. Step 8

    Swap the oil for milk

    The interaction reads better with a more contrasting shader. In Shading → Assign, pick Milk and click Assign Material. In the Shader Editor, copy the milk shader nodes, open Water_00, delete the oil nodes and paste the milk nodes in their place, connected to the Mix Shader.

    Assigning Milk changed the modifier's Material to Milk_00, so set it back to Water_00, the material that holds the mix. Fine-tune the Color Ramp again: water and milk now blend through the same fl_color attribute.

You now have two fluids that interact in the same simulation and a single mesh whose shaders blend along the fl_color attribute. Swap in other materials from the gallery to see the same interaction with a different look.