A tool to generate normal maps from any sprite and animated sprite sheet.
The project's README from github.com/Hugo-Dz/spritefusion-sprite-normals. As one markdown file: README.md.
A tool to generate normal maps for pixel art sprites and animations. Written in Rust, available as a CLI and a WebAssembly library.
Normal maps let 2D sprites react to dynamic lighting. Ideal for 2.5D games.
Features:
Requires Rust 1.85 or newer. From this directory:
cargo build --release --locked
The binary is available at target/release/spritefusion-sprite-normals. To install it locally:
cargo install --path . --locked
spritefusion-sprite-normals <INPUT>... [OPTIONS]
<INPUT>: PNG sprites or sheets, GIF, or APNG files.-o <OUTPUT>: Output normal PNG for one input.--output-dir <DIR>: Output directory for a batch.--normal-strength <VALUE>: Overall strength. Defaults to 1.5.--detail-strength <VALUE>: Relief from painted shading. Defaults to 6.--detail-scale <PIXELS>: Shading smoothing. Defaults to 0.6.--shape-strength <VALUE>: Silhouette volume. Defaults to 1.15.--frame-size <WIDTHxHEIGHT>: Isolate uniform PNG sheet cells.--normal-format directx: Reverse the green channel. Defaults to OpenGL.--force: Replace existing outputs. Input files are protected.spritefusion-sprite-normals sprite.png -o sprite_n.png
spritefusion-sprite-normals sprites/*.png --output-dir normals
spritefusion-sprite-normals sprite.png -o sprite_n.png --normal-strength 2
spritefusion-sprite-normals sheet.png --frame-size 32x32 -o sheet_n.png
spritefusion-sprite-normals walk.gif -o walk_n.png
Without an output path, maps are saved beside their inputs as <name>_n.png. Run spritefusion-sprite-normals --help for every option.
GIF and APNG inputs, and PNG sheets with --frame-size, produce three files:
walk_n.png: lossless normal-map atlas.walk_n.color.png: color atlas with the same frame layout.walk_n.frames.json: atlas dimensions, frame dimensions, columns, frame count, and timing.Frames are arranged in row-major order. delays_ms contains [numerator, denominator] pairs in milliseconds. PNG sheets keep their layout and receive a default 100 ms frame delay. Source loop counts are not exported.
Normal PNGs are data textures: disable sRGB sampling in your engine. Use artwork at its native pixel resolution. Generation estimates relief from color and shape; painted highlights can also become surface detail.
Build with the wasm32-unknown-unknown Rust target and wasm-bindgen CLI 0.2.126:
cargo build --release --target wasm32-unknown-unknown --no-default-features --locked
wasm-bindgen target/wasm32-unknown-unknown/release/spritefusion_sprite_normals.wasm --target web --out-dir pkg
Use the generated package in your project:
import init, { generate_normal_map } from "./pkg/spritefusion_sprite_normals.js";
await init();
const result = generate_normal_map(inputBytes, JSON.stringify({ strength: 1.5 }));
try {
const normalPng = result.normal_png;
const colorPng = result.color_png;
const metadata = JSON.parse(result.metadata);
// Use these bytes to save files or create image URLs.
} finally {
result.free();
}
Pass a Uint8Array and "{}" for default settings. Optional keys are strength, detail, smoothing, volume, frame_width, frame_height, and directx. Returned arrays own their bytes and remain valid after free().
The CLI and WASM module use the same generator and animation decoder. Inputs are limited to 64 MiB and 4,194,304 pixels including processing padding; animated inputs additionally allow up to 256 frames and 4,194,304 total decoded pixels.
cargo test --locked
cargo clippy --all-targets --locked -- -D warnings
cargo fmt --check
Sprite Normals is a Sprite Fusion project. Sprite Fusion is a tool to generate pixel art sprites and animations for game development.
MIT License โ Hugo Duprez.
A tool to generate normal maps from any sprite and animated sprite sheet.