Normal map lighting for 2D Pixel Art sprites

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?

Yes, could you please create a ticket in github.com/defold/defold and link to this discussion?

Done, thanks @britzl

2 Likes

Thanks. Jhonny has a PR with a fix here: Engine crashes when producing secondary uv sets by Jhonnyg · Pull Request #8893 · defold/defold · GitHub

1 Like

So after a bit of experimentation with this concept, I’ve come up with a simple project that’s able to support normal and spectral lighting and can handle multiple different lights. It uses a lua module to help create/track lights and their values as they are pushed to the renderscript.

It supports directional, point, and spotlights as per this LearnOpenGL tutorial. The lights exist in 3d space and their effects on the sprites reflect (haha) that, and the lighting is attenuated. I’ll post code or the entire project (after cleaning and documenting) if anyone is interested. Here’s a sloppy example:

10 Likes

Yes please share!

2 Likes

I’ll see if I can get it put later today (it’s 2 am for me lol)

1 Like

That would be great for reference. Let us know if you finally share the code. Thanks!

I’ve shared it already, here it is

3 Likes