longtimedevs commited on
Commit
0b07206
·
verified ·
1 Parent(s): 8ffc963

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +147 -0
README.md CHANGED
@@ -1,3 +1,150 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - gamedev
5
+ - normal-map
6
+ - image-to-image
7
+ - computer-vision
8
+ - sprites
9
+ - pixel-art
10
+ - onnx
11
+ - 2d-lighting
12
+ pipeline_tag: image-to-image
13
+ library_name: onnx
14
  ---
15
+
16
+ <div align="center">
17
+
18
+ # 🎮 Sprite2Normal
19
+
20
+ **AI-powered Tangent-Space Normal Map Generator for 2D Sprites & Pixel Art**
21
+
22
+ [ 🇬🇧 English ](#-english) • [ 🇷🇺 Русский ](#-русский)
23
+
24
+ </div>
25
+
26
+ ---
27
+
28
+ <a name="-english"></a>
29
+ ## 🇬🇧 English
30
+
31
+ **Sprite2Normal** is an ultra-lightweight neural network (~7 MB) designed to instantly generate tangent-space **Normal Maps** from flat 2D sprites, textures, and pixel art.
32
+
33
+ Built for indie game developers to easily add dynamic 2D lighting to their games without manually drawing height or normal maps.
34
+
35
+ Trained completely from scratch with a custom lightweight U-Net architecture.
36
+
37
+ ### ✨ Features
38
+ - **Ultra-Compact:** Model file is only **~7 MB** in ONNX format.
39
+ - **CPU & GPU Friendly:** Runs in **3–10 ms** on standard CPUs without requiring a dedicated GPU.
40
+ - **Engine Compatible:** Generates standard OpenGL tangent-space normal maps (X: Red, Y: Green, Z: Blue), ready for **Godot, Unity, GameMaker, Unreal Engine**, and custom shaders.
41
+ - **Dynamic Resolution:** Fully convolutional architecture supporting sprites of any size.
42
+
43
+ ### 🚀 Quick Start (Python)
44
+
45
+ #### 1. Install dependencies
46
+ ```bash
47
+ pip install onnxruntime pillow numpy
48
+ ```
49
+
50
+ #### 2. Inference script
51
+ ```python
52
+ import numpy as np
53
+ from PIL import Image
54
+ import onnxruntime as ort
55
+
56
+ session = ort.InferenceSession("sprite2normal.onnx", providers=["CPUExecutionProvider"])
57
+ input_name = session.get_inputs()[0].name
58
+ output_name = session.get_outputs()[0].name
59
+
60
+ img = Image.open("character.png").convert("RGB")
61
+ orig_w, orig_h = img.size
62
+
63
+ img_resized = img.resize((128, 128), Image.Resampling.BILINEAR)
64
+ arr = np.array(img_resized, dtype=np.float32) / 255.0
65
+ arr = np.transpose(arr, (2, 0, 1))
66
+ input_tensor = np.expand_dims(arr, axis=0)
67
+
68
+ output = session.run([output_name], {input_name: input_tensor})[0][0]
69
+
70
+ pred = (output + 1.0) * 0.5 * 255.0
71
+ pred = np.clip(pred, 0, 255).astype(np.uint8)
72
+ pred = np.transpose(pred, (1, 2, 0))
73
+
74
+ normal_map = Image.fromarray(pred).resize((orig_w, orig_h), Image.Resampling.BILINEAR)
75
+ normal_map.save("character_normal.png")
76
+ print("Saved to character_normal.png!")
77
+ ```
78
+
79
+ ### 🕹️ Game Engine Integration
80
+ - **Godot Engine:** Place `character.png` and `character_normal.png` in your project folder. Assign the normal map to the **Normal Map** slot of your `Sprite2D` node and add a `PointLight2D`.
81
+ - **Unity (URP 2D):** Set texture type of `character_normal.png` to **Normal Map**. Assign it to **Secondary Textures** of your Sprite Renderer.
82
+
83
+ ---
84
+
85
+ <a name="-русский"></a>
86
+ ## 🇷🇺 Русский
87
+
88
+ <details open>
89
+ <summary><b>Нажмите, чтобы свернуть / развернуть русский текст</b></summary>
90
+ <br>
91
+
92
+ **Sprite2Normal** — это сверхлёгкая нейросеть (~7 МБ), предназначенная для мгновенной генерации карт нормалей (**Normal Maps**) из плоских 2D-спрайтов, текстур и пиксель-арта.
93
+
94
+ Создана специально для инди-разработчиков игр, чтобы быстро добавлять динамическое 2D-освещение без необходимости вручную прорисовывать объём каждого кадра анимации.
95
+
96
+ Обучена полностью с нуля на специализированной компактной архитектуре U-Net.
97
+
98
+ ### ✨ Особенности
99
+ - **Минимальный вес:** Модель весит всего **~7 МБ** в формате ONNX.
100
+ - **Работает без мощной видеокарты:** Время инференса всего **3–10 мс** на обычном офисном процессоре (CPU).
101
+ - **Готовность к игровым движкам:** Создаёт стандартные OpenGL-карты нормалей (X: Красный, Y: Зелёный, Z: Синий), совместимые с **Godot, Unity, GameMaker, Unreal Engine** и кастомными шейдерами.
102
+ - **Любое разрешение:** Свёрточная архитектура принимает спрайты произвольного размера.
103
+
104
+ ### 🚀 Быстрый старт (Python)
105
+
106
+ #### 1. Установка библиотек
107
+ ```bash
108
+ pip install onnxruntime pillow numpy
109
+ ```
110
+
111
+ #### 2. Скрипт запуска
112
+ ```python
113
+ import numpy as np
114
+ from PIL import Image
115
+ import onnxruntime as ort
116
+
117
+ session = ort.InferenceSession("sprite2normal.onnx", providers=["CPUExecutionProvider"])
118
+ input_name = session.get_inputs()[0].name
119
+ output_name = session.get_outputs()[0].name
120
+
121
+ img = Image.open("character.png").convert("RGB")
122
+ orig_w, orig_h = img.size
123
+
124
+ img_resized = img.resize((128, 128), Image.Resampling.BILINEAR)
125
+ arr = np.array(img_resized, dtype=np.float32) / 255.0
126
+ arr = np.transpose(arr, (2, 0, 1))
127
+ input_tensor = np.expand_dims(arr, axis=0)
128
+
129
+ output = session.run([output_name], {input_name: input_tensor})[0][0]
130
+
131
+ pred = (output + 1.0) * 0.5 * 255.0
132
+ pred = np.clip(pred, 0, 255).astype(np.uint8)
133
+ pred = np.transpose(pred, (1, 2, 0))
134
+
135
+ normal_map = Image.fromarray(pred).resize((orig_w, orig_h), Image.Resampling.BILINEAR)
136
+ normal_map.save("character_normal.png")
137
+ print("Сохранено в character_normal.png!")
138
+ ```
139
+
140
+ ### 🕹️ Интеграция в движки
141
+ - **Godot Engine:** Поместите спрайт и карту нормалей в проект. В ноде `Sprite2D` в поле **Normal Map** выберите созданный файл и добавьте `PointLight2D`.
142
+ - **Unity (URP 2D):** В настройках текстуры укажите тип **Normal Map** и назначьте её во вкладку **Secondary Textures** компонента Sprite Renderer.
143
+
144
+ </details>
145
+
146
+ ---
147
+
148
+ ## 📄 License / Лицензия
149
+ This project is open-sourced under the **Apache-2.0** License.
150
+ Проект распространяется под открытой лицензией **Apache-2.0**.