bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.24k stars 3.57k forks source link

Normal Maps for 2D Textures #14586

Closed DispairingGoose closed 3 months ago

DispairingGoose commented 3 months ago

What problem does this solve or what need does it fill?

Lighting in 2D games is often very flat.

What solution would you like?

Adding normal maps to 2d sprites

What alternative(s) have you considered?

Additional context

Other Engine Implmentations:

alice-i-cecile commented 3 months ago

My understanding is that MaterialMesh2d is the intended path for these more complex use cases. Sprite should be kept very light and fast for the "just render my pixels" users. What does Bevy's existing 2D lighting ecosystem do?

I do think we should ship 2D lighting, and normal maps for 2D textures are an excellent and standard technique.

zaycev commented 3 months ago

@DispairingGoose there is no built-in support, but as @alice-i-cecile mentioned you can use MaterialMesh2d with few modifications. Essentially all you need to do is add atlas info into the material – texture handle and list of rectangle infos. After that you can pass your current atlas rectangle id into MaterialMesh2d shader and then sample corresponding pixel data inside of your shader. Based on how lighting / shading works in your game you should be able to use normal maps in MaterialMesh2d without any problems. This is what I was experimenting with in BML2D, but I haven't open source that part yet.