Normal map lighting for 2D Pixel Art sprites

The 2d lighting writeups and shares have been awesome to follow. There are very talented people here. I’m brand new to Defold. Normal mapping / 2d lighting advancements would be amazing. Anyone here suggest additional resources / learning material? Happy 2024 to you all.

2 Likes

I can share that we are working on multi-texture support for sprites. The runtime part is done and @vlaaad is working on the editor:

Once this is done you’ll be able to use multiple textures on the same sprite to achieve effects with normal maps etc

3 Likes

This is wonderful. Thank you for posting! I’m very interested in making the most out of 2d lighting in my project. I was looking for this under PRs on Github. Thanks again for sharing.

Here’s the PR for the runtime part which has already been merged:

https://github.com/defold/defold/pull/8183

2 Likes

Thank you!

In the Defold 1.6.4 beta we’ve added support for multiple textures for the sprites as well.

It allows you to set e.g. a diffuse atlas and a normal map atlas to your sprites.
Use naming conventions to keep the image names easy to use in your atlas.
E.g. for the first frame of an animation, you have a diffuse and normal image:

hero_diffuse_1.png
hero_normal_1.png
hero_diffuse_2.png
hero_normal_3.png

Then it’s easy to rename these frames in the atlas using the “Rename patterns”.
Use “rename_patterns: _diffuse_=” and “rename_patterns: _normal_=” to make the names the same in the atlases.
It is important for the image names to be the same, as lookup is being done between atlases using the key “myanim/imagename” into the other atlases.

I hope this helps, and let me know if you have any questions!
(More documentation is coming)

6 Likes

By the way, does someone here have such a set of images that can be used as an example?
E.g. a few frames of a character or object, with diffuse and normal maps?

Or do you happen to know a good place to find such content?

1 Like

Sure I can create something tonight or possibly tomorrow.

1 Like

Heres my recent character “Bopz” walking animation. I applied the naming example you gave so hopefully they are ready to use. If you need flipped green channel or anything let me know.

sample:
bopz_test_previe

TestBopz.zip (1.4 MB)

4 Likes

yoooo let’s gooo

Thank you for sharing this! It does however look like the diffuse and normals aren’t matching:

bopz_walk_normal_001:
bopz_walk_normal_001

bopz_walk_diffuse_001:
bopz_walk_diffuse_001

Look at how the feet are not aligned.

1 Like

Are specular maps also a thing here? I know nothing, I just did a very quick search:-)

The textures are generic, they are what you decide them to be. You just need to have a shader that interprets them the way you want.

2 Likes

You’re right, I was off by one frame. Updated names and checked frames. Should match up correctly now. Let me know if you have any issues.

ps: some of the feet may seem a little different in shape, that is because a platform was masking the feet at some frames and not in the normal frames should be fine for an example and its something I can mask and fix later if needed to be exact. cheers

TestBopz_updated.zip (1.4 MB)

2 Likes

Thanks. They line up properly now. I put this into a sample project and uploaded here:

https://defold.com/sample-normal-maps-2d/

I guess my main concern with the Bopz character is that there’s all those specular highlights baked into the diffuse texture. I’m not an expert on these things but I supposed you’d want a specular map as well.

Sample project source: GitHub - defold/sample-normal-maps-2d

5 Likes

No problem. I went ahead and limited the baked lighting down to a very basic diffuse no harsh light reflections and shadows so that the lighting in this example can have more effect.

I will add the updated diffuse animation to the project and create a pull request on github.

3 Likes

Thanks. I think it is better for the purpose of this example. Next would be to build an example which also includes specular highlights. But what we have now is a good first example of what can be done.

1 Like

Hey guys, I just tested it using the latest version (1.8.0) and I get a crash everytime on Windows 11.
On mac, it runs, but it doesn’t look the same as in the web sample. Looks like it’s ignoring the normal map, right?

Any ideas why it could be happening?

Edit: windows stack

ERROR:CRASH: CALL STACK:

ERROR:CRASH: 0 0x7FF7416EAC70 memcpy D:\a_work\1\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm:199
ERROR:CRASH: 1 0x7FF74168C9B0 dmGraphics::WriteAttribute D:\a\defold\defold\engine\graphics\src\graphics.cpp:469
ERROR:CRASH: 2 0x7FF74139E3A0 dmGameSystem::CreateVertexData D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_sprite.cpp:1221
ERROR:CRASH: 3 0x7FF7413A1AF0 dmGameSystem::RenderBatch D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_sprite.cpp:1300
ERROR:CRASH: 4 0x7FF7413A21A0 dmGameSystem::RenderListDispatch D:\a\defold\defold\engine\gamesys\src\gamesys\components\comp_sprite.cpp:1733
ERROR:CRASH: 5 0x7FF74147A5C0 dmRender::DrawRenderList D:\a\defold\defold\engine\render\src\render\render.cpp:894
ERROR:CRASH: 6 0x7FF741498CB0 dmRender::ParseCommands D:\a\defold\defold\engine\render\src\render\render_command.cpp:183
ERROR:CRASH: 7 0x7FF741487090 dmRender::UpdateRenderScriptInstance D:\a\defold\defold\engine\render\src\render\render_script.cpp:3607
ERROR:CRASH: 8 0x7FF7412BFB30 dmEngine::StepFrame D:\a\defold\defold\engine\engine\src\engine.cpp:1687
ERROR:CRASH: 9 0x7FF7412C0890 dmEngineUpdate D:\a\defold\defold\engine\engine\src\engine.cpp:2189
ERROR:CRASH: 10 0x7FF7412C0AC0 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:83
ERROR:CRASH: 11 0x7FF7412B8CA0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:152
ERROR:CRASH: 12 0x7FF7416E1BA4 __scrt_common_main_seh D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
ERROR:CRASH: 13 0x7FF8E1DD2560 BaseThreadInitThunk :0
ERROR:CRASH: 14 0x7FF8E376AA20 RtlUserThreadStart :0
ERROR:CRASH:

_crash.zip (20.1 KB)

Thanks!

1 Like

It crashes on macOS as well. :sob:

Is there anything I can do to help fixing it? It looks like a bug, right?