GUIDE // THREE.JS
How to import a fire, smoke or explosion sprite sheet into three.js
Load the PNG with TextureLoader, set texture.repeat to one cell of the grid, such as 1/8 by 1/8, and use it as the map of a SpriteMaterial with transparent set to true. Move texture.offset to a new cell to change frames. Serve the file from your own site or with CORS headers, or the browser refuses to use it.
- Godot 4 Available
- Unity Manual setup
- Unreal Engine Manual setup
- Roblox Studio Manual setup
- three.js Available
A draft compile is from $0.05, and new accounts start with $5 of usage.
01 // WHAT YOU LOAD
One RGBA file, or several in a shader
A Spatial Compiler compile gives you four PNG sprite sheets, each 2048 x 2048 px with 64 frames on an 8 x 8 grid. None is a plain color image. The smoke's look comes from lighting precomputed from six directions, and the flame has its own channels.
SpriteMaterial reads one map, so for a quick start build one RGBA image: for smoke, the green of main_pos.png in RGB and its alpha in alpha. A ShaderMaterial can read the sheets as they are, as in the smoke blending guide.
02 // HOW TO
Load the sheet onto a sprite
- Put the PNG in the folder your site serves, such as
public/fx/. - Load it with
TextureLoaderand setcolorSpacetoTHREE.SRGBColorSpace, since a built-in material shows it as color. - Set
texture.repeatto 1/8 by 1/8 so the sprite shows one cell, andtexture.offsetto (0, 0.875) for frame 0 in the top-left corner. - Make a
THREE.Spritewith aSpriteMaterialusing that map,transparent: trueanddepthWrite: false, and scale it to the effect's size. - Change the offset over time to play the frames, as in the loop guide.
import * as THREE from 'three';
const texture = new THREE.TextureLoader().load('/fx/smoke_rgba.png');
texture.colorSpace = THREE.SRGBColorSpace;
texture.repeat.set(1 / 8, 1 / 8);
texture.offset.set(0, 1 - 1 / 8); // frame 0, top-left cell
const material = new THREE.SpriteMaterial({ map: texture, transparent: true, depthWrite: false });
const sprite = new THREE.Sprite(material);
sprite.scale.set(10, 10, 1);
scene.add(sprite);
03 // REAL OUTPUT
A fire sheet for the same code
The 2 s fire loads the same way. Build its flame image on black from main_colour.png times the squared alpha of main_neg.png, and draw it with additive blending. The image is normalized, so material.color.setScalar(emitMax), with emitMax the scales.emit_max_hdr in layout.json, restores its peak.
04 // FILTERING
Mipmaps and edge bleeding
three.js builds mipmaps (smaller copies for distant objects) for every loaded texture by default. On a sprite sheet they average pixels across cell borders, so a small, distant sprite can show a sliver of the next frame. Leave transparent pixels around each frame, or set texture.generateMipmaps = false with texture.minFilter = THREE.LinearFilter, which trades the bleed for some shimmer at a distance.
Godot 4 gets a ready scene that relights the smoke. three.js uses the documented snippet. A native six-way material is not built yet.
How to import a fire, smoke or explosion sprite sheet into three.js?
Load the PNG with THREE.TextureLoader, set texture.repeat to one grid cell and assign it to a SpriteMaterial map. Update texture.offset to change frames.
Does three.js support sprite sheets?
Yes, through texture.repeat and texture.offset, which crop a texture to one cell. Nothing built in animates it, so your code updates the offset each tick.
How do I prevent texture bleeding between adjacent frames in a three.js sprite sheet?
Leave transparent padding around each frame or disable mipmaps with texture.generateMipmaps = false and texture.minFilter = THREE.LinearFilter so small sprites do not average neighboring cells.
How do I optimize many fire, smoke and explosion flipbooks for WebGL or WebGPU?
Share one texture across sprites, keep sheets at 1024 or 2048 pixels and draw large particle counts with InstancedMesh or THREE.Points instead of separate sprites.
Compile your first effect
You pay per compile and see the price before it runs. New accounts start with $5 of usage.