-1
\$\begingroup\$

I render an animation with 100+ frames. (Direct X9,Sprites / Pngs) I load them all in an array and render them.

How i do it: Load all frames in an array of bytes. When i need the frame x, i create the sprite from the specific buffer with "D3DXCreateTextureFromFileInMemoryEx & D3DXCreateSprite". I do that, bec loading them at the start& at device lost etc takes ages.

My question now: What can i do? Creating the sprite takes very long but why? I googled that including all frames into 1 png and rendering regions from it is faster but isnt that like crazy ? I would get files sizes of 100k x 1080px.

The scenario looks the following: - Consumes about 100 mb ram (i am okay with that bec its only displaying 1 animation, so about 100 mb total ram for the program) - Consumes a lot of cpu (not okay, its just rendering 1 sprite at a frame, why does it have way more consume than my 3d rendering)

\$\endgroup\$
1

1 Answer 1

3
\$\begingroup\$

Sprites in Direct3D are just textured triangles (or rather two triangles forming a quadrilateral). As such, the performance hit is because each time you change the source texture it has to flush the sprite batch and submit it as a Draw. The key to Direct3D performance is to get as much work into each Draw as possible. You are basically drawing two triangles per Draw which is always going to perform slowly. If you were drawing the same texture a few thousand times in a row, it would take about the same time as drawing a single sprite.

The general solution to this kind of issue is to use a texture atlas (or specifically for sprites, a 'sprite sheet') where you pack the individual sprites into the same texture. The main challenge is that you are limited to the hardware support for maximum texture sizes. With Direct3D 9 Shader Model 3 hardware, the best you can do is 4096 x 4096. With Direct3D 11, it depends on your target Direct3D hardware feature level but it can range from 4096 x 4096 up to 16384 x 16384. With Direct3D 11 and Feature Level 10.0 or better, you can even get tricky and pack sprites into a 8192 x 8192 textures in an 2D texture array of up to 512.

I have an example Sprite Sheet implementation using DirectX Tool Kit for DirectX 11's SpriteBatch class.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.