2026 · Shader

  • GLSL
  • Touchdesigner

Lysergiq Fluid v1.0

Real-time Lattice Boltzmann fluid dynamics for TouchDesigner with bidirectional image coupling.

What it does

A 2D GPU-accelerated fluid engine based on the Lattice Boltzmann Method (LBM) using D2Q9 spatial discretization. The simulation extracts spatial luminance gradients from the incoming texture and injects them as physical obstacles and opposing force vectors directly into the vector field. Fluid currents dynamically warp and advect the source media in response to live cursor interactions, while a final optical pass computes dynamic surface normals and Blinn-Phong specular reflections.

Protocol

  1. Feed a 32-bit float TOP into In 1 and assign the interactive UI panel path to sample normalized cursor coordinates.
  2. Modulate Viscosity (BGK relaxation time) and Image Impact to tune fluid turbulence against edge-deflected currents.
  3. Back-sample the velocity field in bufferD using Distortion Speed to generate the advected fluid drag before normal generation.
// Advection displacement (bufferD)
vec2 fluidVelocity = texture(sTD2DInputs[1], vUV.st).xy;
vec2 distortedCoords = vUV.st - (fluidVelocity * uDistortionSpeed);
vec4 finalColor = texture(sTD2DInputs[0], distortedCoords);

Architecture & GLSL Pipeline

The entire simulation and rendering pipeline executes on the GPU via dedicated multi-pass fragment shaders encapsulated inside a modular .tox container.

1. Ingestion & Interaction

  • Normalized (u, v) coordinates and velocities are extracted from the target UI panel via a Panel CHOP and injected as uniforms (uMouse, uForce) into the physical simulation buffers.
  • Kinetic energy is injected within the defined Brush Size based on Euclidean distance to the cursor.

2. Physical Engine (LBM D2Q9)

  • Operates via a GPU feedback loop between bufferA and bufferB utilizing a 9-velocity discrete grid (D2Q9).
  • Solves collision and relaxation states through a Bhatnagar-Gross-Krook (BGK) operator.
  • Bidirectional Coupling (Image Impact): The engine samples the luminance gradient of the incoming texture via partial derivatives and converts it directly into opposing momentum:
// Spatial luminance gradient converted into physical obstacle forces
float lum = dot(texture(sTD2DInputs[1], uv).rgb, vec3(0.299, 0.587, 0.114));
vec2 imageForce = vec2(dFdx(lum), dFdy(lum)) * uImageImpact;

Because the fluid advects the image and the distorted image recalculates the obstacle forces in the subsequent frame, an organic feedback loop is established where turbulence inherently conforms to the subject's contours.

3. Visual Distortion (Advection)

  • Handled in bufferD purely as a displacement stage without physical overhead.
  • Samples the velocity field calculated by the physical buffers to back-sample coordinates, producing realistic liquid shearing and drag.

4. Optical Engine (Shading & Normal Mapping)

  • Derives dynamic surface normals from the spatial derivatives of the fluid density field.
  • Implements a Blinn-Phong illumination model for responsive highlights and depth:
// Surface normal reconstruction & Blinn-Phong specular calculation
vec3 normal = normalize(vec3(deltaDensityX * uBumpiness, deltaDensityY * uBumpiness, 1.0));
vec3 halfDir = normalize(lightDir + vec3(0.0, 0.0, 1.0));
float specAngle = max(dot(normal, halfDir), 0.0);
float specular = pow(specAngle, uShininess) * uSpecularStrength;

Parameters & Controls

Fluid Physics

  • Viscosity: Modulates the BGK relaxation time. Lower values generate sharp, high-frequency turbulence; higher values increase internal dissipation, simulating viscous media such as oils or paints.
  • Friction: Linear damping factor applied to the global velocity field to bring the fluid to rest when interaction ceases.
  • Distortion Speed: Scalar applied to velocity during texture coordinate warping.
  • Diffusion: Rate of kinetic energy dispersion across neighboring lattice nodes.
  • Gravity: Directional constant downward acceleration (negative Y-axis) driving continuous flow.
  • Image Impact: Controls coupling intensity between the source texture and physical vector field.

Screenshot 2026-03-02 201950

User Interaction

  • Brush Size: Normalized radius of the localized force injection area around the cursor.
  • Mouse Force: Multiplier for instantaneous momentum imparted by cursor velocity.
  • Interact Panel: TouchDesigner path reference (e.g., /project1) from which to sample interaction coordinates.

Optical & Shading

  • Light Direction (X, Y, Z): Virtual light vector for the Blinn-Phong shading pass.
  • Ambient: Base ambient illumination level to preserve detail in shadowed regions.
  • Bumpiness: Normal map intensity derived from local density gradients.
  • Shininess: Specular power exponent (higher values yield sharper, wetter reflections).
  • Specular Strength: Linear gain applied to specular highlights.

System Utilities

  • Reset (Pulse): Clears memory buffers and reinitializes momentum to prevent numerical instability or floating-point runaway.
  • Reset Resolution: Reallocates and clears internal resolution caches.

Technical Specifications

Parameter Specification
Platform TouchDesigner
Component Format .tox (Container Component)
Internal Precision 32-bit floating point (RGBA)
Input Requirement 32-bit float TOP (In 1)
Output Processed 2D visual TOP with normal shading (16-bit / 8-bit downcast)
Author Meirks (www.meirks.xyz)

License (EULA)

Copyright © 2026 Meirks (www.meirks.xyz). All rights reserved.

  • Grant of License: Perpetual, non-exclusive, non-transferable license for use in personal, educational, and commercial projects (live visual performances, interactive installations, video production, and rendered art).
  • Restrictions: Resale, sub-licensing, standalone redistribution, or inclusion in commercial asset packages without written authorization is strictly prohibited.
  • Attribution: Attribution is not mandatory for visual output, but referencing @Meirks or linking to www.meirks.xyz is appreciated.

Contact & Feedback