---
id: "neural-cellular-automata-textures"
title: "Neural Cellular Automata for Textures"
aliases: [Self-organising textures, NCA textures]
domain: "genai"
stage: "generation"
realtime: "realtime"
platforms: [webgl2, python]
year_introduced: 2021
inputs: [ldr-image]
outputs: [texture]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Mordvintsev et al., 2021"
url: "https://texelatlas.vercel.app/t/neural-cellular-automata-textures/"
sources_verified_at: "2026-11-29"
---
# Neural Cellular Automata for Textures (Mordvintsev et al., 2021)

> A pixel-grid automaton whose update rule is a tiny CNN, trained so the grid self-organises into a target texture; it runs in real time on a GPU shader and heals when damaged.

## Reach for it when

- generate tileable textures from a small learned model
- texture that grows and regenerates itself
- synthesize textures with tiny network and low memory
- animated organic patterns from local rules

## How it works

Each pixel is a cell with a small state vector. The update step is: apply fixed filters (identity, Sobel gradients, Laplacian) to build a perception vector, pass it through a small MLP to produce an increment, and add it to the cell state with a random fire rate so updates stay asynchronous. The rule is trained by unrolling many steps and minimising a style loss (Gram matrices of pretrained-network features) against an exemplar, so the pattern is not copied but has the same statistics. Since the rule is local and tiny, it can be turned into a fragment shader, runs on any resolution, and the pattern regrows after you erase part of it.

## When to use it

Choose it for animated, procedural-looking tiling textures with a small weights budget and interactive behaviour. Prefer [Mesh Neural Cellular Automata (MeshNCA)](https://texelatlas.vercel.app/t/mesh-neural-cellular-automata.md) to run on mesh vertices, and a classic noise or [SyncMVD](https://texelatlas.vercel.app/t/syncmvd.md)-style generation when you need a single prompt-specific texture rather than a reusable rule.

## Cost

cheap — Rule is a few thousand weights; qualitative GPU cost is low per step.
Measured GPU Weight: 112.74× baseline (extreme) — 3.7093 ms median / 4.0252 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 103.3× baseline (extreme) — 1.6425 ms median (2.26× faster on L4).
Ampere A100 scaling: 81.46× baseline (extreme) — 2.346 ms median (1.58× faster on A100).

## Failure modes

- Struggles with long-range structure and semantic layouts
- Training per texture and sensitivity to hyperparameters
- Patterns can drift or diverge when stepped far beyond the trained horizon
- Style loss gives statistically similar rather than pixel-exact results

## Dataflow

- Inputs: ldr-image
- Outputs: texture
- Platforms: webgl2, python

## Presets

### Neural Cellular Automata — noisy perception seed (left) vs self-organized living texture (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_GROWTH_T": 0.78,
  "P_KERNEL_FREQ": 6.5,
  "P_MORPH_MIX": 0.55,
  "P_SPLIT": 0.44
}
```

```glsl
const float P_GROWTH_T = 0.78; // P Growth Steps [0.1, 1.0, 0.02]
const float P_KERNEL_FREQ = 6.5; // P Perception Scale [3.0, 12.0, 0.25]
const float P_MORPH_MIX = 0.55; // P Morphogen Mix [0.0, 1.0, 0.02]
const float P_SPLIT = 0.44; // P Seed / NCA Split [0.0, 1.0, 0.02]

float hash21(vec2 p) {
  p = fract(p * vec2(127.1, 311.7));
  p += dot(p, p + 34.5);
  return fract(p.x * p.y);
}

float vnoise(vec2 p) {
  vec2 i = floor(p);
  vec2 f = fract(p);
  vec2 u = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),
    u.y
  );
}

// Multi-channel latent state s(x) perturbed by learned Sobel + Laplacian perception updates
vec4 evalNCAState(vec2 p, float t, float freq, float morph) {
  vec2 q = p * freq;
  // Iterative local-neighborhood perception (approximates 4 CNN update steps via curl & Laplacian feedback)
  for (int i = 0; i < 4; i++) {
    float fi = float(i) + 1.0;
    float e = 0.14 / fi;
    float c0 = vnoise(q + vec2(t * 0.12, -t * 0.09));
    float cx = vnoise(q + vec2(e, 0.0) + vec2(t * 0.12, -t * 0.09)) - vnoise(q - vec2(e, 0.0) + vec2(t * 0.12, -t * 0.09));
    float cy = vnoise(q + vec2(0.0, e) + vec2(t * 0.12, -t * 0.09)) - vnoise(q - vec2(0.0, e) + vec2(t * 0.12, -t * 0.09));
    float lap = vnoise(q + vec2(e, 0.0)) + vnoise(q - vec2(e, 0.0)) + vnoise(q + vec2(0.0, e)) + vnoise(q - vec2(0.0, e)) - 4.0 * c0;
    // Anisotropic Sobel curl + reaction-diffusion update
    vec2 grad = vec2(cx, cy) * (1.8 + morph * 1.4);
    q += vec2(-grad.y, grad.x) * 0.38 + vec2(lap * 0.45, -lap * 0.35);
  }
  float ridgeA = sin(q.x * 2.4 + cos(q.y * 2.1 + t * 0.45));
  float ridgeB = cos(q.y * 2.7 - sin(q.x * 2.3 - t * 0.35));
  float activator = smoothstep(-0.35, 0.65, ridgeA * 0.55 + ridgeB * 0.45);
  float inhibitor = smoothstep(-0.2, 0.8, sin(length(q - floor(q + 0.5)) * 6.2831853));
  float vein = exp(-abs(ridgeA + ridgeB * 0.65) * 4.2);
  float hidden = vnoise(q * 1.6);
  return vec4(activator, inhibitor, vein, hidden);
}

vec3 aces(vec3 x) {
  x = max(x, 0.0);
  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  float screenX = fragCoord.x / max(iResolution.x, 1.0);
  float split = clamp(P_SPLIT, 0.0, 1.0);
  float growth = clamp(P_GROWTH_T, 0.05, 1.0);
  float freq = clamp(P_KERNEL_FREQ, 2.5, 14.0);
  float morph = clamp(P_MORPH_MIX, 0.0, 1.0);

  // Regeneration wave pulsing outward from two living seeds
  float rSeed1 = length(uv - vec2(-0.18, 0.08));
  float rSeed2 = length(uv - vec2(0.24, -0.14));
  float rMin = min(rSeed1, rSeed2);
  float front = fract(iTime * 0.14) * 1.15 + growth * 0.65;
  float alive = smoothstep(front + 0.14, front - 0.06, rMin);

  vec4 st = evalNCAState(uv, iTime * 0.55, freq, morph);
  // Compute surface normal from finite difference of activator channel for tactile depth
  float eps = 0.008;
  float hC = st.x * 0.65 + st.z * 0.45;
  float hX = evalNCAState(uv + vec2(eps, 0.0), iTime * 0.55, freq, morph).x * 0.65;
  float hY = evalNCAState(uv + vec2(0.0, eps), iTime * 0.55, freq, morph).x * 0.65;
  vec3 n = normalize(vec3((hC - hX) * 14.0, (hC - hY) * 14.0, 1.0));

  vec3 lDir = normalize(vec3(0.55, 0.68, 0.72));
  float diff = max(dot(n, lDir), 0.0);
  float spec = pow(max(dot(n, normalize(lDir + vec3(0.0, 0.0, 1.0))), 0.0), 36.0);

  // Organic living coral/malachite palette driven by 4 hidden NCA channels
  vec3 deep = vec3(0.03, 0.10, 0.14);
  vec3 teal = vec3(0.08, 0.58, 0.54);
  vec3 amber = vec3(0.95, 0.58, 0.16);
  vec3 ivory = vec3(0.96, 0.91, 0.78);
  vec3 ncaCol = mix(deep, teal, st.x);
  ncaCol = mix(ncaCol, amber, st.z * (0.45 + 0.55 * morph));
  ncaCol = mix(ncaCol, ivory, smoothstep(0.62, 0.95, st.z * st.y) * 0.65);
  ncaCol = ncaCol * (0.38 + 0.78 * diff) + vec3(0.85, 0.94, 0.98) * spec * 0.35;

  // Highlight active self-organization wave front
  float waveRing = exp(-abs(rMin - front) * 28.0) * 0.45;
  ncaCol += vec3(0.25, 0.95, 0.85) * waveRing;
  ncaCol = mix(vec3(0.04, 0.06, 0.09) + vec3(0.05) * hash21(floor(fragCoord * 0.25)), ncaCol, clamp(alive + 0.28, 0.0, 1.0));

  // Left side: raw quantized seed grid & Sobel perception kernel overlay
  vec2 cell = floor(uv * 28.0);
  vec2 cf = fract(uv * 28.0);
  float seedVal = hash21(cell + floor(iTime * 0.8) * 0.07);
  float gridLine = smoothstep(0.08, 0.02, min(cf.x, cf.y));
  vec3 seedCol = mix(vec3(0.04, 0.06, 0.10), vec3(0.18, 0.46, 0.62), seedVal * 0.8);
  seedCol += vec3(0.12, 0.22, 0.30) * gridLine;
  // Visualize 3x3 Sobel perception rings around the two seeds
  float kernelVis = exp(-abs(rMin - 0.16) * 45.0) + exp(-abs(rMin - 0.08) * 65.0) * 0.6;
  seedCol += vec3(0.98, 0.66, 0.20) * kernelVis;
  seedCol = mix(seedCol, ncaCol, smoothstep(0.22, 0.03, rMin) * 0.9);

  vec3 col = (screenX < split) ? seedCol : ncaCol;
  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
  col = mix(col, vec3(0.95, 0.97, 1.0), sep);

  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}
```

Attribution: MIT — written for this index.

## Sources

1. [primary] Alexander Mordvintsev, Eyvind Niklasson, Ettore Randazzo (2021) Texture Generation with Neural Cellular Automata. arXiv preprint (cs.AI). https://arxiv.org/abs/2105.07299 (verified via arxiv on 2026-11-29)
2. [implementation] google-research (2020) google-research/self-organising-systems. https://github.com/google-research/self-organising-systems License: Apache-2.0. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Neural Cellular Automata for Textures." https://texelatlas.vercel.app/t/neural-cellular-automata-textures/ (accessed 2026-12-01).
