GLSL shader example

Dye Advection in a Velocity Field

Backtrace through a prescribed velocity field to sample previous color, then inject dye. This demonstrates advection without pressure projection or a full incompressible fluid solver.

Live example

Edit the code and the preview updates as you type.

What to observe

Dye Advection in a Velocity Field.

Mechanism

Backtrace through a prescribed velocity field to sample previous color, then inject dye. This demonstrates advection without pressure projection or a full incompressible fluid solver.

The controlling code

c=texture2D(u_dye,uv).rgb;

u_dye stores the transported RGB color, while Fragment merely reads that texture. Set c=texture2D(u_dye,uv).rgb to c=vec3(texture2D(u_dye,uv).r) to display only red dye as grayscale without changing its simulated motion.

Experiment

In u_dye, change the flow multiplier 0.002 to 0.004. Each update backtraces twice as far through the previous color, so the dye stretches and moves faster along the prescribed field.

Debugging and cost

u_dye reads one previous-state texel and injects a moving source each update; it does not solve pressure. Change the decay .997 to .98 to make older dye vanish faster, then use Step while paused to compare one update at a time.

Built-in functions used

Learn it step by step