• This repository has been archived on 03/Feb/2023
  • Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    Python
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Make normal maps for 2D art

unflattener

Build Status

Unflattener is a free and open source Python module and a command line tool (unflatten) that helps you make normal maps for 2D sprites and other graphics. You can use the normal maps it generates to implement dynamic lighting in video games.

Example

D-lit images and the resulting normal map

Together the diffuse and normal maps create dynamic lighting

Dynamic lighting in gimp-normalmap in motion

How it works

Unflattener takes as input images of your object lit by a light source pointing directly at that object from four directions: top, bottom, left and right (we'll call those images "directionally lit" or "d-lit" for short β€” like "d-pad"). At least one such image is required; having at least two (one with light coming from the top or the bottom, one with light from the left or the right) is highly recommended.

Unflattener is written in Python and requires the libraries NumPy and Pillow to work. Python programs can access its functionality directly by importing the NormalMap class from the module unflattener.normalmapgen. Right now Unflattener cannot do dynamic lighting previews, so you will need a third-party tool like the gimp-normalmap plugin for GIMP for that.

This project was inspired by Sprite Lamp.

The core algorithm is explained in a rather lengthy comment in the method NormalMap.create_from_images in normalmapgen.py. You will find some tips on how the input artwork should look in the same comment.

The general idea is that in the d-lit images your object should look as if it were

  1. Uniformly matte white with no self-shadowing;
  2. Lit by a very distant light source much larger than itself that creates no highlights.

Installation

Unflattener has been tested to work under Linux (Ubuntu 12.04, Ubuntu 16.04, Fedora 26, Debian 7 and openSUSE Tumbleweed 2017*) and Windows (XP, 7, 8.1 and 10).

You will need Python 2.7 (v2.6 and earlier won't work) or Python 3.2 or later, NumPy and Pillow to run Unflattener. The following instructions are for Python 2.7.

Debian and Ubuntu

You can install the dependencies from the distribution's package repository with

sudo apt install git python-numpy python-imaging python-setuptools

To install gimp-normalmap, run

sudo apt install gimp-normalmap

To install Unflattener, clone this repository, cd into it and run setup.py:

git clone https://github.com/dbohdan/unflattener
cd unflattener
python setup.py install --user

Fedora

You can install the dependencies from the distribution's package repository with

sudo dnf install git numpy python-pillow python-setuptools

To install gimp-normalmap, run

sudo dnf install gimp-normalmap

To install Unflattener, clone this repository, cd into it and run setup.py:

git clone https://github.com/dbohdan/unflattener
cd unflattener
sudo python setup.py install

Windows

On Windows you first need to install Python 2.7 using the official installer from http://python.org/download/. Unflattener has only been tested with the 32-bit versions of Python, NumPy and Pillow (on both 32-bit and 64-bit Windows), so it is recommended that you use those.

Once you have Python installed, download the latest binary packages for NumPy and Pillow from http://www.lfd.uci.edu/~gohlke/pythonlibs/. They will be named, e.g., numpy-1.13.1+mkl-cp27-cp27m-win32.whl and Pillow-4.2.1-cp27-cp27m-win32.whl. Open the Command Prompt in the directory where you downloaded the package files and run

c:\Python27\python.exe -m pip install "numpy-1.13.1+mkl-cp27-cp27m-win32.whl"
c:\Python27\python.exe -m pip install Pillow-4.2.1-cp27-cp27m-win32.whl

To install Unflattener, clone this repository with Git for Windows or download https://github.com/dbohdan/unflattener/archive/master.zip and unzip it, cd into the created directory and do

c:\Python27\python.exe setup.py install

You should then be able to run Unflattener from the Command Prompt with the command unflatten. If you don't have the Python 2.7 scripts directory added to your %PATH%, try

c:\Python27\Scripts\unflatten.exe

Usage

usage: unflatten.py [-h] [--top TOP] [--bottom BOTTOM] [--left LEFT]
                    [--right RIGHT] [--output OUTPUT] [--depth DEPTH]

Generate a normal map for 2D art

optional arguments:
  -h, --help            show this help message and exit
  --top TOP, -t TOP     top image file
  --bottom BOTTOM, -b BOTTOM
                        bottom image file
  --left LEFT, -l LEFT  left image file
  --right RIGHT, -r RIGHT
                        right image file
  --output OUTPUT, -o OUTPUT
                        output file name
  --depth DEPTH, -d DEPTH
                        normal map z_N range

One input file minimum, at least two (one for each axis) highly recommended.
Input files should be 8-bit grayscale PNGs.

Submit your work

If you use Unflattener to create artwork or video game graphics, file an issue to have your work featured here.

License information

Unflattener is distributed under the new (3-clause) BSD license. See the file LICENSE.

Robot sprite originally from the Bits & Bots art pack by MoikMellah. The sprite is licensed under the Creative Commons CC0 license.

More Repositories

1

structured-text-tools

A list of command-line tools for manipulating structured text data
6,948
star
2

automatic-api

A list of software that turns your database into a REST/GraphQL API
Go
1,988
star
3

classless-css

A list of classless CSS themes/frameworks with screenshots
HTML
1,928
star
4

embedded-scripting-languages

A list of embedded scripting languages
1,277
star
5

compilers-targeting-c

A list of compilers that can generate C code
JavaScript
692
star
6

sqawk

Like awk but with SQL and table joins
Tcl
310
star
7

liveviews

Phoenix LiveView workalikes for different languages and frameworks
243
star
8

hicolor

🎨 Convert images to 15/16-bit RGB color with dithering
C
194
star
9

jsonwatch

Track changes in JSON data from the command line
Rust
165
star
10

s2png

Store any data in PNG images
Rust
99
star
11

csv2html

Convert CSV files to HTML tables
Rust
73
star
12

initool

Manipulate INI files from the command line
Standard ML
57
star
13

caddy-markdown-site

Serve Markdown files as HTML pages with CSS using just Caddy
CSS
52
star
14

picol

(Fossil repository mirror) A tiny interpreter
C
32
star
15

jimhttp

A library collection and web microframework
Tcl
28
star
16

tcl-duktape

Tcl bindings for Duktape, an embedded JavaScript interpreter
C
19
star
17

all-caps-basic

(WIP) A compiler written in Awk
Awk
16
star
18

caddy-cgi

An example of how to configure Caddy 1/2 with a FastCGI-to-CGI proxy
Perl
11
star
19

tinyfts

Very small standalone full-text search HTTP/SCGI server
Tcl
10
star
20

messagebox

Display message boxes from Windows batch files and command line programs
Shell
8
star
21

jimsh-static

Jim Tcl static binaries with SQLite 3 for Linux
Dockerfile
7
star
22

tcl-fcgi

FastCGI in pure Tcl
Tcl
6
star
23

2048.tcl

The game of 2048 implemented in Tcl
Tcl
4
star
24

pip-wtenv

Make your script download its dependecies; like pip.wtf but uses venvs
Python
4
star
25

joker-cgi-guestbook

A toy old-school CGI guestbook written in Joker
Clojure
3
star
26

HTMLgen

This is a mirror of the HTMLgen module by Robin Friedrich with the Debian patches
Python
3
star
27

ptjd

A pure Tcl JPEG decoder
Tcl
2
star
28

gpgedit

Edit symmetrically encrypted files
Tcl
2
star
29

fossil-wiki-export

Export a Fossil SCM wiki to Git preserving the revision history
Tcl
2
star
30

circleci-tcl-gcc-autoconf

Docker image for testing Tcl and C code with CircleCI
Dockerfile
2
star
31

klisp

C
2
star
32

empty

(Mirror) An alternative to Expect for *nix shells
C
1
star
33

caddy-deb-opt

Build a deb package to install Caddy in /opt/
Makefile
1
star
34

apache-2.4-webdav

A WebDAV file share/inbox configuration example for Apache 2.4
CSS
1
star
35

tcl86-nsis-installer

Build a Windows installer for Tcl with NSIS
PowerShell
1
star
36

tcl-augeas

Tcl bindings for Augeas
C
1
star