• Advertisement
Sign in to follow this  

batch draw!

This topic is 1952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

We know put all the vertices together and call drawXXX() can draw all the triangles.
But if each triangles have different textures,what should i do?DX9 doesn't has texture array.
And if we use pixel shader ,i know use pixel shader can sample texture.But pixel shader 2.0 only has 16 sampler.
I think it is use for multiple texture.But how to pass texture into pixel shader?Could anybody give me a example or a idea?
Thank you! Edited by AlanWu

Share this post


Link to post
Share on other sites
Advertisement

We know put all the vertices together and call drawXXX() can draw all the triangles.
But if each triangles have different ,what should i do?DX9 doesn't has texture array.
And if we use pixel shader ,i know use pixel shader can sample texture.But pixel shader 2.0 only has 16 sampler.
I think it is use for multiple texture.But how to pass texture into pixel shader?Could anybody give me a example or a idea?
Thank you!


diffrent...? i'm guessing you mean textures. if so, you could alternatively create a super texture of all the sprites, and adjust the uv's of the object's appropriately. Edited by slicer4ever

Share this post


Link to post
Share on other sites
The basic idea for a texture atlas (or texture array or super texture) for 2-d drawing is to vary the (u,v) values to represent the different tiles.

Imagine you have a 2x2 texture atlas:

ab
cd

If you want to describe a textured quad for each one the u,v coordinates are:

textured quad showing tile a. SetTexture(TextureAtlas), U,V = (0, 0) to (0.5,05)
textured quad showing tile b. No more need to SetTexture. U,V = (0.5,0) to (1.0,0)
textured quad showing tile c. No more need to SetTexture. U,V = (0,0.5) to (0,1.0)
textured quad showing tile d. No more need to SetTexture. U,V = (0.5,0.5) to (1.0,1.0)

Hope this helps with the concept.

There are a few different choices for D3D9 implementation. Use Google and you should be able to find a few.

Share this post


Link to post
Share on other sites

[quote name='AlanWu' timestamp='1355090789' post='5008895']
We know put all the vertices together and call drawXXX() can draw all the triangles.
But if each triangles have different ,what should i do?DX9 doesn't has texture array.
And if we use pixel shader ,i know use pixel shader can sample texture.But pixel shader 2.0 only has 16 sampler.
I think it is use for multiple texture.But how to pass texture into pixel shader?Could anybody give me a example or a idea?
Thank you!


diffrent...? i'm guessing you mean textures. if so, you could alternatively create a super texture of all the sprites, and adjust the uv's of the object's appropriately.
[/quote]
yes,you are right,i have changed it just now.
thank you! Edited by AlanWu

Share this post


Link to post
Share on other sites

The basic idea for a texture atlas (or texture array or super texture) for 2-d drawing is to vary the (u,v) values to represent the different tiles.

Imagine you have a 2x2 texture atlas:

ab
cd

If you want to describe a textured quad for each one the u,v coordinates are:

textured quad showing tile a. SetTexture(TextureAtlas), U,V = (0, 0) to (0.5,05)
textured quad showing tile b. No more need to SetTexture. U,V = (0.5,0) to (1.0,0)
textured quad showing tile c. No more need to SetTexture. U,V = (0,0.5) to (0,1.0)
textured quad showing tile d. No more need to SetTexture. U,V = (0.5,0.5) to (1.0,1.0)

Hope this helps with the concept.

There are a few different choices for D3D9 implementation. Use Google and you should be able to find a few.


i have a idea now,thank you very much!
will the method be slow?if so,do you have any other method?
Thank you for your helping!

Share this post


Link to post
Share on other sites

The basic idea for a texture atlas (or texture array or super texture) for 2-d drawing is to vary the (u,v) values to represent the different tiles.

Imagine you have a 2x2 texture atlas:

ab
cd

If you want to describe a textured quad for each one the u,v coordinates are:

textured quad showing tile a. SetTexture(TextureAtlas), U,V = (0, 0) to (0.5,05)
textured quad showing tile b. No more need to SetTexture. U,V = (0.5,0) to (1.0,0)
textured quad showing tile c. No more need to SetTexture. U,V = (0,0.5) to (0,1.0)
textured quad showing tile d. No more need to SetTexture. U,V = (0.5,0.5) to (1.0,1.0)

Hope this helps with the concept.

There are a few different choices for D3D9 implementation. Use Google and you should be able to find a few.


well,i think i can make a texture atlas by myself,and not let my program make it every times before it use.
But i have some problems here,if every textures have a different size,what should i do?
if i put all the texture together and it is bigger than texture max size which video-card support?what should i do?
some people said i can use pixel shader to draw different textures,how to do that?
thank you! Edited by AlanWu

Share this post


Link to post
Share on other sites
"well,i think i can make a texture atlas by myself,and not let my program make it every times before it use." - You probably should automate this process, else you might get very frustrated when your images change size, or your decide to add a little border around each image, or you change the size of an atlas page, etc.

"But i have some problems here,if every textures have a different size,what should i do?" - Packing different sized textures optimally is a very hard problem, it's a variant of the bin packing problem and is basically unsolvable. There are simple algorithms which produce good results, but you might be best using an existing packing tool rather than write your own.

"if i put all the texture together and it is bigger than texture max size which video-card support?what should i do?" - If you're doing it offline (i.e. you're running your atlas step before you run the game), then you're best off just choosing a max size like 1024x1024 which every reasonable card would support. You will then have to handle the possibility that your textures will end up spread across multiple pages.

"some people said i can use pixel shader to draw different textures,how to do that?" - This doesn't sound like a good idea to me. If your textures are all different sizes, then you'd need to use different samplers and select in your pixel shader, tbh, you'd be better off not batching at all. If your textures are all the same size and all your target hardware support array textures (unlikely), then that might be a reasonable option, your pixel shader would then just be choosing a plane of a single array texture which would be reasonably efficient.

Share this post


Link to post
Share on other sites
If your atlas exceeds the supported texture size you must split it into two atlas textures. You should gather sprites, that are likely to be close to each other in game, in one atlas. If you have different themes (e.g. desert & ice) you should place all desert sprites in one atlas and all ice sprites into the other.

As for shaders, you can draw different textures, but you won't get any performance gain from that as you still need to load both textures to vram. On "how" to do that I suggest getting a book on shader programming since this isn't explained in a few sentences and - depending on what you want do - requires a fair amount of advanced mathematics.

Share this post


Link to post
Share on other sites

"But i have some problems here,if every textures have a different size,what should i do?" - Packing different sized textures optimally is a very hard problem, it's a variant of the bin packing problem and is basically unsolvable. There are simple algorithms which produce good results, but you might be best using an existing packing tool rather than write your own.

Actually it is not that hard to solve if you allow for a few errors in the process. You should always pack square textures on area size, once you have that sorted list fit the biggest one into the texture and split it the original texture on the inserted textures biggest dimension. Now check if the next texture fit into the biggest square that doesn't hold a texture yet. If it doesn't output an error and increase the atlas texture size and start again. If it does sub divide that square again as before and continue with the next square. Here is the source article I used when I had to implement this for a game. Remember ordering on area size is important to get an efficient subdivision of the texture.

This problem gets harder when you have to pack a texture with the atlas for a model and flattened out geometry although the same process should work as well, you might need a different form than a square to sub divide on though. Edited by NightCreature83

Share this post


Link to post
Share on other sites
thanks everybody
now i only have a few problem,could you continue helping me?
i think i have two ways to go:
1.make a texture atlas when i packing game data,divide different themes texture into different texture atlas.So i don't need to do anythings when i run game.But i need to call SetTexture() more than once if it has different themes texture in my game.
2.make a texture atlas which it need to use before run game,it may take some times for loading but it only need to call SetTexture() for once.
And i have another problem,we know texture coordinate is float,but texture is int(pixel),if i want to draw a texture from (100,100) to (200,200),but the size of texture atlas is 1024x1024,and 100/1024 is not a limited decimal ,what should i do?Should i change the size of texture atlas to 1000x1000?And do i have other ways?And do you have some detail articles about texture atlas?i want to learn it.
Thank you guys very much!
Oh,i start some topic here ,i hope you can go to have a look and reply.
vertex rhw and camera in 2D
about Font
thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement