How to build a complex sprite character by pieces (body and nodes)?

Basically all starts here:

and continues here:

Sry for the DancingMarblesScene missnaming :slight_smile:

1 Like

Or this one, here I am attaching thin instances to the animation:

1 Like

I will take a look. Maybe I can combine bones with textures instead sprites, and get full advantage of bjs materials getting rid of the sprites constrains.

I wasnā€™t using sprites until I did a PR: Unexpected rotation on multi-layered SpriteMap

I came to the same conclusion, that sprite support is quite limited in babylon.js comparing for example to Godot which I tried out to create a small 2d sprite based game. I believe we (the community) can make contributions which will move our beloved 3d framework (just for the record I mean babylon.js) towards what the big players on the scene can already offer.

2 Likes

When you posted your question I was thinking about could we make compound sprite animations make the same way as we do vertex animations? Could we remake the sprite engine to support skeletal animations using the GPU? etc etcā€¦

1 Like

Iā€™m trying to look up what animated textures are. Is it the same as a spritesheet but with animation frames?

In that case, yes, you can use that too.

With a node material, itā€™s just using nodes instead of individual lines of shader code, which makes it quite flexible. So, you can use any approach you would like.

Also, when you create a node material, you are not supposed to have your sprites inside the node material itself. Unless you always want a certain sprite to be used. Instead, you want to leave the texture nodes blank. Then inside your game code, you provide the sprites to the node material.

So, if you want to support up to 8 layers, then you make a node material which supports 8 layers. Then inside your engine, you only assign as many sprites as you need.

This way, you can reuse the same node material for any number of different characters.

A shader is generated from the node material under the hood. Shaders are designed to be as performant as possible, so youā€™re unlikely to run into any performance issues.

1 Like

You convinced me, but Iā€™ll have to change all the 2D layer of the engine :smiley:

Anyway I have to make a deeper learning of how it works to see how to adapt it to the public interface (which is not going to change).

At the end, the user will use it like if the textures are sprites, with a similar interface than what babylon provides. Nodes will be abstract to the user. But I have to think about the shader effects, and how to implement that in a simple layer.

You canā€™t use any number of textures, because you will be limited by the maximum number of samplers that can be used in a fragment shader, which is typically between 10 and 20, depending on the GPU. Itā€™s better to use a spritesheet and change the coordinates inside this texture to change sprite.

You could use regular 3D planes and enable billboard mode instead of sprites. In that case, if the materials you use for these planes are transparent, the sorting will be done by the engine.

Thanks for the info.

Just to ensure Iā€™m going to do the proper thing: so you think I can use textures and node materials instead sprites for a 2D game full of animated textures in the foreground and background?

I donā€™t know, I never tried it :slight_smile:

You should probably do a test with the maximum number of sprites you want to use and do the same test replacing the sprites with a plane + material. The latter may be slower than the former (sprites are optimized for simple quad rendering, after all), but if you want to create characters made of sprites (as ā€œbuild a complex sprite characters by piecesā€ seem to mean), then being able to parent the planes will probably help a lot, something you canā€™t do with sprites.

1 Like

Thanks a lot, I will implement both ways and do performance tests :slight_smile:

Materials can also add FX to the sprites, which seems to be cool, and I donā€™t have to deal with sprites depth, something that can cause problems because their creation order is total arbitrary (users can create sprites at any order any time).