Runs in any recent browser, phones included. About 11 MB to load (8 MB on a phone).
I first started this hobby project after I was convinced by some test scripts I wrote in PyTorch to optimize geometry for anamorphic sculptures years ago. I’ll post that shortly. So I wondered how texture optimization would look like.
I choose camouflage because it’s partly an evolved biological trait, but also because I served in the Yugoslav military in the eighties and always wondered where the camo patterns come from. I mean it’s obvious they work – but how exactly are they made? By which process? Did the tailors just adopt an iterative process in which they painted some uniforms, made the models wear them, placed them in a suitable biome (like a forest) and kept improving until they were satisfied it camouflages enough? Do there exist scientific criteria? Etc.
So I started some naive optimization projects to optimize a patch against a static backdrop by calculating the loss of many patches placed in various positions simultaneously. It worked, but it was still far from a true 3D optimization – to optimize a patch on a 3D model against a background.
I resumed the project with PyTorch3D and succeeded somewhat, using a variety of techniques, assisted by a coding agent. I stopped short of creating a 3D scene and running the optimization on a 3D model inside the 3D scene, which would be the most faithful reproduction.
I envisioned this workflow:
- a squad has to take some position
- they send a drone to recon said position and take photos
- the remote system optimizes the pattern in a minute
- the pattern is beamed to their electro-chromatic uniforms which paint themselves in the optimized pattern
- they take the position in fully optimized camouflage
I researched electrochromic textiles but they are all in research stage, or prohibitively expensive, so I couldn’t perform the experiment in real world on the cheap.
Below is the technical writeup. Be sure to click on the interactive demo button which opens a ThreeJS viewer.
First attempt: a square on a photograph
The project started much simpler, and flatter. I took one photograph (a forest, a jungle, rubble, a steppe) and a square of 48 by 48 free pixels, filled at first with the photo’s average colour plus a little noise. At every step, the square was compared with 25 random pieces of the photo at once. Three numbers measured the difference: how far apart the pixels were, how far apart the textures were according to a pretrained image network (VGG16), and how far apart the colour averages and spreads were. The optimiser changed the pixels to shrink all three. To see the result, I pasted the square onto ten random spots in the photo.
I found the photos for that first version on the web and don’t know where they came from, so I can’t show them here. The video below is the same code, re-run on four views of the free Poly Haven panoramas that the later experiments use.
The squares pick up the photo’s colour and grain, but they never stop looking like squares. Up close, they show what the method actually optimises: the texture term from the image network is happy with a few bright, saturated specks that no photo contains, because they match its statistics, not the eye.

I tried a few variations. One made the square tile seamlessly, so it could repeat like printed cloth. One moved the square along a path over several frames, to see whether a pattern that has to work while moving looks different. One used a depth estimate (MiDaS) to choose where in the photo to sample, so the square was tested against the ground at a plausible distance rather than against the sky.
Even where the squares came out well, the setup was missing almost everything that makes camouflage hard:
- No shape. A square has no silhouette, no limbs and no folds, so there is no outline to hide. In practice the outline is what gives a figure away first.
- No light. The square was pasted onto the photo, not lit by it. Real cloth is darker on the side facing away from the sky, and a pattern has to survive that.
- No test. The square was judged on the same photo it was fitted to. It could simply learn to copy that photo’s leaves.
- No cloth. Every pixel was free, so the result was a photographic texture with thousands of colours, which nobody would print on a uniform.
Each gap became a part of the second version: a 3D figure instead of a square, the photograph as the light as well as the backdrop, directions held back for testing, and a pattern limited to a few colours and patch sizes.
A figure, a forest and an observer
The setup has three parts. The figure is a 3D human from MakeHuman, 1.66 m tall, in a long-sleeved shirt and trousers that play the role of the uniform. Only the cloth’s colours can change. The shape stays fixed, and the head and hands stay bare. The optimiser sees him in four poses, standing, walking, crouching and kneeling, turned to face any direction, so one pattern has to work on every side of the body.
The forest is a single 360° photograph of a snowy spruce stand: mossy ground, patches of old snow, overcast light. It does two jobs. It is the backdrop, seen through a virtual camera 1.6 m above the ground, and it is the light: the figure is lit by the same photograph, so its colours come out the way they would on that day, in that place. I split the panorama into six sectors of 60°. The optimiser only ever sees three of them. The other three are kept for testing, so every result below comes from directions the optimiser never saw.
The observer is the hard part: a number that says how visible the figure is. Mine adds up four things that differ between the figure and the forest right behind it:
- Outline. How much contrast there is across the silhouette, compared with what the forest’s own edges have. This is what gives a figure away first.
- A consistent rim. A dark or light edge running all the way around the body, which the eye easily joins into a shape.
- Colour. The average colour and its spread, against a ring of background around the figure.
- Texture. Statistics of the pattern, as seen by an image network (VGG16), against those of the background.
Each is measured at four scales, from the image as rendered down to an eighth of its size. Shrinking an image by half is roughly what doubling the distance does, so one number covers a figure seen from close by and from far away. The renderer is differentiable, which means the score can be traced back to every pixel of the cloth’s texture. Gradient descent then nudges the texture, step by step, towards a lower score. A run of 400 steps takes about a minute on a gaming GPU (an RTX 3090).
The data turned out to matter more than the formula. My first attempt used one photograph of a forest, and the pattern learned the photograph: the trousers turned into undergrowth and the chest into sunlit leaves, because that is what was always behind them. Even with the 360° photo, the camera aimed at the person always saw the same band of the panorama behind the chest, and the snow patches there grew a white patch on the shirt. Sliding the background randomly up and down by up to 12° during training fixed it.
Making it look like camouflage
Left free, the optimiser paints soft mottling plus a fine, fingerprint-like noise, far too small to see from more than a metre or two. That noise made the outline more visible up close. Real camouflage is a few flat colours in patches of a bounded size, so I gave the optimiser the same rules. The palette is five colours, picked from the training views of the forest; the optimiser may adjust them. The layout is either patches of 5 to 10 cm with crisp edges, or squares of 1.5 cm, as in digital camouflage. A penalty stops any single colour from forming patches much larger than about 11 cm.

The rules cost almost nothing: the constrained patterns score within a few per cent of the free texture. And they look like real military camouflage without being told what that looks like. One detail kept coming back in every run: the snow white in the palette was always darkened to a beige. Pure white is too conspicuous on a figure, even in a forest with snow on the ground.
Here is how visible the outline is in the held-out directions. A value of 1 means the figure’s outline is as strong as that of a random shape of the same size drawn on the forest, so lower is better. “Close” is the image as rendered, “far” is eight times the distance.
| uniform | outline, close | outline, far |
|---|---|---|
| original clothing (blue shirt, jeans) | 1.42 | 1.04 |
| the forest’s average colour | 1.00 | 0.52 |
| one optimised colour | 0.96 | 0.46 |
| patches, 5 to 10 cm | 0.94 | 0.41 |
| pixels, 1.5 cm | 0.97 | 0.41 |
Up close a good flat colour is hard to beat. Further away the patterned uniforms pull ahead: their outline is weaker than the forest’s own edges, while the flat colour turns into a dark smudge. Patches and pixels end up almost identical.

The same holds when he gets lower. Crouching or kneeling at 5 to 7 m, the patch pattern all but disappears into the moss, the disruptive pattern is easier to pick out, and the original clothing stands out at a glance.

A second observer: a person detector
My measure of visibility is a model of human vision, not a human. So I tested the patterns on a very different observer as well: three off-the-shelf person detectors (Faster R-CNN, RetinaNet and FCOS, trained on the COCO dataset), shown the figure at 5 to 40 m in the held-out directions. None of them reports a person in the empty forest. Up to 15 m they find him every time, whatever he wears. Close up, the shape of a person is enough. From 20 m on, the patterns start to work: at 30 m the patch pattern is found in 48 % of the views, against 74 % for a flat colour and 99 % for the original clothes.

Then I put one of the detectors, Faster R-CNN, into the optimisation as a second observer. Next to the vision model, the loss now included how confident the detector was that the figure is a person, on views at 8 to 30 m. That is the disruptive pattern in the chart. Detection now drops already at 15 m, and averaged over all distances it falls from 75 % to 53 %. The effect carries over: the two detectors that never took part in the training are fooled even more than the one that did. At 30 m, RetinaNet finds the figure in 8 % of the views and FCOS in 14 %.
The interesting part is how the pattern changed. The patches did not get bigger, as I first thought from the renders. They got more different from each other: 37 % more contrast in brightness, 27 % more colour, and colours the forest doesn’t have, a tan-orange, a rust brown and a pale mint. And the vision model doesn’t like it: up close, the disruptive pattern’s outline (1.18) is worse than a plain colour (0.96).

Biologists have names for both strategies. Background matching hides an animal by making it look like a random piece of its surroundings: the same colours, at the same contrast. Disruptive colouration uses bold, contrasting patches that break the body’s outline into pieces that don’t add up to an animal. Abbott Thayer described it in 1909, and Hugh Cott made it a central idea of his 1940 book on animal colouration. In field experiments with paper moths pinned to trees, the birds left disruptive patterns alone more often than background-matching ones (Cuthill et al., 2005), and disruptive patterns still worked when some of their patches did not match the bark, though they worked best when all of them did (Stevens et al., 2006).
The optimiser found both strategies on its own, one for each observer. The vision model finds the figure where its statistics differ from the forest, so its best answer is to copy the forest. The detector has learned what a person looks like, so its best answer is to break the person up, even at the price of colours that don’t belong. Military uniforms went the same way, from single colours like khaki and olive drab to multi-colour patterns with strong internal contrast, from the German Splittertarn of the 1930s to the US Woodland pattern and the German Flecktarn. A good real pattern is a compromise between the two.
One caution. By eye, the difference between the two patterns at 12 to 20 m is smaller than the detector numbers suggest, and up close the disruptive pattern is clearly the easier one to spot. That is what the demo’s Find him mode is for: try it and see which one you find faster.

Where a pattern stops helping
The forest is a friendly place to hide: busy, textured, evenly lit. I ran the same pipeline on harsher sites.
Rubble (a collapsed concrete hall): every pattern, patches or pixels, ended up no better than one well-chosen flat colour. The figure there is actually less visible than in the forest in absolute terms, but the concrete and brick behind it are smooth, and the brightness of the background jumps from view to view, from a light slab to dark brick. No fixed pattern can match both.
Deserts were worse. I trained on three desert sites (red sand with boulders, grey rocky scrub, pale chalk) and tested on a fourth, dark scrub at a low sun. Each site’s own pattern won on that site. A pattern trained on all three won nowhere, and on the unseen fourth site every trained pattern lost to the plain blue shirt and jeans. “Desert” is not one environment. There is also a physical limit: a standing figure is vertical and receives only about 40 % of the light that falls on the flat ground around it, so at the bright sites even white cloth comes out darker than the sand around it.

That raised an obvious question: what if the cloth could change its colours for every viewer, like an e-paper display? I tested the best case, a cloth that knows exactly where the observer is and what lies behind the figure, and re-tunes its five colours for each view while keeping the pattern. In the forest it helps a lot at distance: the far outline score drops from 0.41 to 0.12, and the colour mismatch to a quarter. Under overcast light it also helps up close. In direct desert sun it doesn’t help up close at all, and letting the cloth glow brighter than white adds almost nothing anywhere. What remains in the sun is probably the figure’s own shading, a lit side and a shadow side, which no choice of colours can cancel.
What this is not
- It is a simulation. The figure is rendered onto photographs with soft, diffuse light only: no shadows, no shadow on the ground, and no motion during optimisation.
- The photographs have no depth, so the figure is always drawn in front of everything, even trees that should stand between him and the camera. Real camouflage is used in cover. This is the open-ground worst case.
- The “human observer” is a model built from image statistics. Nobody has tested the patterns on people yet. The three detectors are closely related (all ResNet-50 networks trained on COCO).
- One body, one suit, and for the main results one forest. The head and hands stay bare, and they are the most visible parts in every shot.
- Some of the disruptive pattern’s odd colours may be quirks of the detector rather than disruption. A run with the palette locked to the forest’s colours would tell them apart; I haven’t done it.
Who has done this before
None of the ingredients here are new, and other people have gone further with each of them. Three lines of work come closest.
Hiding objects in photographed scenes. Owens et al. (2014) textured a box so that it disappears into a real scene from many viewpoints, using photographs of the scene, and GANmouflage (Guo et al., 2023) extended the idea to complex shapes with a learned texture model. That is the same multi-view, held-out-viewpoint problem as mine, but done properly: with real scene geometry, so objects can sit behind things, and with tests on real people searching for the objects. Their textures are free, though, not the palette-and-patch patterns of a uniform.
Camouflage research with a learned observer. A group at the University of Bristol has trained networks on people’s detection times and used them to optimise colours (Fennell et al., 2019) and patterns (The Camouflage Machine, 2021), whose best patterns were harder for people to find than a widely used military pattern. CamoGAN (Talas et al., 2020) runs the predator-prey arms race as a GAN, and CamoEvo (Hancock and Troscianko, 2022) evolves patterns against human players. Their observer is built from human data, mine from hand-made image statistics. Theirs works mostly with flat targets on photographs, mine with a lit 3D figure at real distances.
Fooling person detectors. Adversarial patches (Thys et al., 2019), an adversarial T-shirt (Xu et al., 2020) and, closest to my second experiment, camouflage-like clothing textures optimised on 3D bodies, printed and sewn into real clothes (Hu et al., 2023) all hide people from detectors far more effectively than my disruptive pattern, and work in the physical world. Vehicle camouflage against detectors is a field of its own (CAMOU, 2019, and its successors). This work usually optimises against the detector alone and then adds a constraint so the pattern looks natural to people.
What this project adds is small and mostly a matter of putting things together. It works from one 360° photo that is both background and light, with a uniform-like pattern, judged at several distances. And it puts two observers side by side, so you can watch the optimiser trade background matching for disruption, the trade-off biologists describe. The main thing it lacks, compared with all of the above, is a test with people.
How it is built
The figure is built with MPFB, the MakeHuman add-on, in headless Blender, posed and exported as meshes. Rendering and optimisation run in PyTorch with PyTorch3D. Because the geometry never changes, the figure is rasterised once per view and only re-shaded at each step, which is what makes a run take a minute. The 360° photographs come from Poly Haven. The detectors are the pretrained models from torchvision.
The demo is a three.js page that reproduces the optimiser’s lighting. Its Evolve mode doesn’t play back saved images. It stores the raw parameters of 79 steps of each run and rebuilds the pattern on the graphics card, blending smoothly between steps. The result matches the PyTorch textures to within a fraction of one colour level.
GitHub repo: https://github.com/virostatiq/camouflage-optimizationhttps://github.com/virostatiq/camouflage-optimization
Credits and references
- Forest: Snowy Forest by Adrian Kubasa, Poly Haven (CC0). Rubble and desert sites, and the four views in the first experiment: Reinforced Concrete 02 and Birchwood by Sergej Majboroda, Goegap by Greg Zaal, and other Poly Haven panoramas (CC0).
- Figure: MakeHuman and MPFB assets (CC0).
- G. H. Thayer and A. H. Thayer, Concealing-Coloration in the Animal Kingdom, 1909.
- H. B. Cott, Adaptive Coloration in Animals, 1940.
- I. C. Cuthill et al., Disruptive coloration and background pattern matching, Nature 434, 2005.
- M. Stevens, I. C. Cuthill, A. M. M. Windsor and H. J. Walker, Disruptive contrast in animal camouflage, Proceedings of the Royal Society B 273, 2006.
- L. Talas, R. J. Baddeley and I. C. Cuthill, Cultural evolution of military camouflage, Philosophical Transactions of the Royal Society B 372, 2017.
