GLSL shader example

Gray–Scott Reaction-Diffusion Patterns

Two channels store A/B concentrations. Diffusion, reaction, feed and kill terms advance a Gray–Scott model. Parameters change the evolution; mature structures require many frames.

Live example

Edit the code and the preview updates as you type.

What to observe

Gray–Scott Reaction-Diffusion Patterns.

Mechanism

Two channels store A/B concentrations. Diffusion, reaction, feed and kill terms advance a Gray–Scott model. Parameters change the evolution; mature structures require many frames.

The controlling code

vec2 ab=texture2D(u_reaction,uv).rg;c=mix(vec3(.03,.06,.16),vec3(.95,.7,.3),smoothstep(.05,.35,ab.y));

u_reaction keeps A in red and B in green, but Fragment currently colors only B through smoothstep(.05,.35,ab.y). Replace ab.y there with ab.x to view the other concentration without modifying the update equation.

Experiment

Set u_parameter to 0 and then 1 to move kill from .055 to .067 in u_reaction. Let each setting run for many frames from Reset; the balance between growing B-rich regions and their removal changes, so mature patterns can differ.

Debugging and cost

Each update reads the center and eight neighbors, then stores A and B in RGBA8 channels. Lower feed=.035 to .025 to alter replenishment separately from kill; the eight-bit rounding and frame-based updates limit numerical precision and rate consistency.

Built-in functions used

Learn it step by step