spritesheet optimize

Discussion and feedback on Construct 2

Post » Mon Jun 15, 2015 12:57 pm

@ashley

if a single object animation is spritesheeted on two sheets, does that mean, it needs to switch constantly between them? with other words
as long as it fits a 2048 texture, would it not be better for it to be on 1 sheet,

like instead of 2x512 = 1*1024 ?
or maybe even a 512 * 1024 ?

or anyone else has a explaination?
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Mon Jun 15, 2015 1:26 pm

Texture atlases and sheets only help with batching, as less textures means more quads can be drawn using the same material without having to issue render commands for individual sprites.

As long as all the required textures for a given scene fit in memory, the actual organisation of the sprites has only a minor impact. It's always possible to fine-tune when hand-crafting everything manually, but in the context of a C2 game whether an animated sprite is using frames from different sprite sheets or not should not be detrimental to performance.

Though it would be interesting to know the logic that decides the size of the atlases :-? I guess some platforms are still limited in terms of hardware when it comes to large textures
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232

Post » Mon Jun 15, 2015 1:36 pm

So why would using different objects have extra drawcalls, while one object with multiframes only one, i think i read its because of textureswitching?

would it be possible to fit a 512*1024 , isn't that also a power of two? this would save memory, i think i have an instance where this should perfectly fit,

also it sometimes a shame to loose great texturespace just because a graphic is a couple pixel to big, while in some cases, the size is not really as important. so a resized version should work ..

edit: it is said, 2048 is maximum for mobile, (for maximum compatibility) but thats fine..
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Mon Jun 15, 2015 1:42 pm

i mean one object , using many instances is the most optimized, but you can set many different frames, is still one call

why would another object that also has been loaded in memory, be an extra call, while using the same object on different frames is not, if the texture sheet is of no importance?

than everything could in theory be called like its one object, just referencing the spritesheet and coordinates
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Mon Jun 15, 2015 7:40 pm

You're absolutely right that additional sheets can and will generate more draw calls ; what I meant by "minimal impact" is that the cost of a few extra draw calls (i.e. a few factors e.g. 2x-10x, as long as there's no order of magnitude e.g. 100+x) is pretty negligible in terms of performance. Though we should think in terms of materials, as objects and/or textures usually don't relate directly to the number or complexity of materials

Basically there are games where each model can require dozens of drawcalls (typically, games with a lot of character customisation, like MMOs, lots of materials, armor pieces, etc. making batching difficult) ; for these, the frame time spent in the graphics drivers start to matter. Assuming a med-size 2D, not so much

I don't have the answer to explain why the atlases don't batch everything in one sheet in your case (and I'd love to know too !), but unless you clearly identified a perf killer or bottleneck through actual profiling, I wouldn't worry and would continue to progress on other fronts while waiting from an answer from Ashley or someone who knows the internal logic of the texture batcher
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232

Post » Mon Jun 15, 2015 8:50 pm

@Refeuh thank you for your answers,

yes i know minimal impact, but still on that low level is pretty important its the best it can, specially because its about possible hundreds of objects,
im not on hold because of this, it just interests me

only thing i can think of is that the textures need square power of two, if thats not the case, there is much to be gained by optimising this, but i suspect there will be something i have not considered

just and idea.. i wonder if would be possible to set the resolution on the texture atlas, the objects would hold its normal dimension, but the textures coordinates would be scaled by that factor, in theory you could then have as small or as high of a texture resolution depending on a setting
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Tue Jun 16, 2015 9:50 am

The spritesheeting strategy is described in some detail in this blog post, although it's a little out of date now (e.g. the maximum spritesheet size is now 2048x2048 instead of 512x512).

The spritesheets have to be square power-of-two to avoid wasting memory on some devices (even if others can do non-power-of-two). Also note that bumping up a 1024x1024 texture to 2048x2048 uses four times as much memory, not twice, so it can be very wasteful to use spritesheets which are unnecessarily large. These days memory use is the main concern, since users tend to develop intensely memory-heavy games and sometimes find it crashes the device if it runs out of memory. So one of the strategies used by the spritesheet builder is if something fits on say 1024x1024, it will also try a 512x512 tile, or two 512x512 tiles, or three, as a way to save wasting memory with empty space on a larger sheet.

More technical concerns are: most third-party plugins aren't written for spritesheeting, and it's tricky to tile images unless they go in their own texture, so tiled background images don't get spritesheeted. Also perhaps surprisingly putting everything on to one giant spritesheet can actually significantly increase the download size of the game. Often individual objects can losslessly compress down to PNG-8 - sometimes around half the file size - because they use less than 256 different unique colors. However if you bundle everything on to one giant sheet, it becomes much more likely that there are more than 256 colors on the sheet and it gets bumped up to PNG-32, which produces larger files.

I don't think the performance is really an issue. In extreme cases with thousands of objects the draw calls can add up, but there are ways of dealing with that. In most real-world games I don't think switching texture poses a significant performance burden.

When I first wrote it I thought it was simple enough, just a matter of dumping lots of images on to one sheet. It turns out there are technical factors and difficult tradeoffs like download size vs. memory use. I don't believe there is one strategy which is universally better.
Scirra Founder
B
399
S
236
G
89
Posts: 24,527
Reputation: 195,386

Post » Tue Jun 16, 2015 11:59 am

@ashley
i'm not good in english i try to translate what you write and just tel me if i'm wrong or not

1- for example i have a sprite with width 80 and height 100 (with no transparanecy spaces)
then to avoid waste memory i have to make it as 100X100 with transparency spaces ?
what about the story about the 1 or 2 pixel around the sprite ?

2-is that same for tiled backgroud ? if the recommanded power of 2 is for example 128 X 128
then we have to put a png with 127x127 or 126 x 126 ?

i'm a little confused
B
46
S
16
G
8
Posts: 794
Reputation: 8,335

Post » Tue Jun 16, 2015 12:13 pm

@matrixreal - don't worry about this when designing your games. It all happens automatically and is taken care for you.
Scirra Founder
B
399
S
236
G
89
Posts: 24,527
Reputation: 195,386

Post » Tue Jun 16, 2015 1:20 pm

@Ashley thank you for explaining this more,

the big problem i see with this solution is that an animation can be just one frame too big and take up an entire sheet, but is for the most part empty, i think there is still room for improvement by using this space, but perhaps thats the entire point why custom atlasses with lots of choice for arrangement is the better solution in the end, > not saying that current solution is bad, its pretty easy :)
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests