• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AlanWu

batch draw!

20 posts in this topic

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
0

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!
[/quote]

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
0

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.
2

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1355091835' post='5008900']
[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!
[/quote]

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
0

Share this post


Link to post
Share on other sites
[quote name='Steve_Segreto' timestamp='1355092866' post='5008906']
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.
[/quote]

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!
0

Share this post


Link to post
Share on other sites
[quote name='Steve_Segreto' timestamp='1355092866' post='5008906']
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.
[/quote]

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
0

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.
0

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.
0

Share this post


Link to post
Share on other sites
[quote name='C0lumbo' timestamp='1355126507' post='5009010']
"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.
[/quote]
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. [url="http://www.blackpawn.com/texts/lightmaps/"]Here[/url] 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
1

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.
[url="http://www.gamedev.net/topic/635547-vertex-rhw-and-camera-in-2d/"]vertex rhw and camera in 2D[/url]
[url="http://www.gamedev.net/topic/635550-about-font/"]about Font[/url]
thanks again!
0

Share this post


Link to post
Share on other sites
Texture coordinates don't have to be 1,2,3..100 they can be any floating point value, 0.0025 is a valid texture coordinate. The GPU takes care of transforming your texture coordinate into the correct pixels in the actual texture image. The normal range is 0...1 if you want to show the whole texture, but if you go over one it will repeat on itself if the wrap state is setup that way.

When using atlas textures the texture coordinates of your objects need to be scaled to the range the texture takes in the atlas texture, and you don't store this as pixels but as actual coordinates to make it easier on yourself during drawing.
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1355146472' post='5009068']
Texture coordinates don't have to be 1,2,3..100 they can be any floating point value, 0.0025 is a valid texture coordinate. The GPU takes care of transforming your texture coordinate into the correct pixels in the actual texture image. The normal range is 0...1 if you want to show the whole texture, but if you go over one it will repeat on itself if the wrap state is setup that way.

When using atlas textures the texture coordinates of your objects need to be scaled to the range the texture takes in the atlas texture, and you don't store this as pixels but as actual coordinates to make it easier on yourself during drawing.
[/quote]
Well,i got a good idea for two ways,finally idea:
When i make texture atlas put same theme's texture as much as possible together,just don't call SetTexture() as much as possible.But if really need other theme's texture,make a texture atlas before drawing,i think it will be very quick and i only need to call SetTexture() for twice.

yes,i know that, i know we usually use from 0 to 1,i mean..well,for a example
i have a texture ,size is 369x153,i called it A.
i have another texture ,size is 694x237,i called it B.
Well,if i make a texture atlas,size is 1024x1024 and i want to put these two texture like that:
??(0,1024),(0,0)????(1024,1024),(1,0)
???????????A B ?
??????????????
????(0,0),(0,1)????(1024,0),(1,1)
first coordinate is pixel coordinate,second is texture coordinate
well,that is the layout,but what is the texture coordinate for A?
should it like that?
left-top:(0,0)
right-top:(369/1024,0) //369 divide by 1024,because the width of A is 369,and the width of texture atlas is 1024
left-bottom:(0,153/1024) //153 divide by 1024,because the height of A is 153,and the height of texture atlas is 1024
right-bottom:(369/1024,153/1024) //same
i think it may be like that,but it has a problem,369 divide by 1024 is a recurring decimal ,so i think the GPU can't get a right pixel value for the width of A,and other is same.
So,should i change the size of texture atlas to 1000,then is won't be a recurring decimal 0.369(369/1000),should i do that?Please tell me.
And i have another question,how many decimal places could pass to GPU,if i pass 0.0025 to GPU,will it make it to 2 decimal places?Does it decide by float?
Thank you very much! Edited by AlanWu
0

Share this post


Link to post
Share on other sites
Right I get your question now. Each pixel in a texture basically corresponds to 1/width for the horizontal axis and 1/height for the vertical axis. So if you know the top left and size of a texture you can easily calculate where the next free space is. If you read the source article I posted you see they encode the position and size of the texture in the tree structure they create.

You mapped your texture wrong though in windows pixel and coordinates all start from the left top so (0,0) = (0px,0px), (1, 1) = (1024px, 1024px). Also in DX9 you need to take in to account that you need to squeeze the texture by half a texel coordinate so you won't sample into the neighbouring texture. You shouldn't worry about recurring decimals because as I said your going to have to subtract half a texel from the original coordinates anyway (basically subtract 0.5/width from u and 0.5/height from v). See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx"]this[/url] for texture coordinate mapping in DX9 and [url="https://developer.nvidia.com/search/google_cse_adv/atlas%20texturing"]this Nvidia sample[/url] for more on atlas texturing
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1355216014' post='5009367']
Right I get your question now. Each pixel in a texture basically corresponds to 1/width for the horizontal axis and 1/height for the vertical axis. So if you know the top left and size of a texture you can easily calculate where the next free space is. If you read the source article I posted you see they encode the position and size of the texture in the tree structure they create.

You mapped your texture wrong though in windows pixel and coordinates all start from the left top so (0,0) = (0px,0px), (1, 1) = (1024px, 1024px). Also in DX9 you need to take in to account that you need to squeeze the texture by half a texel coordinate so you won't sample into the neighbouring texture. You shouldn't worry about recurring decimals because as I said your going to have to subtract half a texel from the original coordinates anyway (basically subtract 0.5/width from u and 0.5/height from v). See [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx"]this[/url] for texture coordinate mapping in DX9 and [url="https://developer.nvidia.com/search/google_cse_adv/atlas%20texturing"]this Nvidia sample[/url] for more on atlas texturing
[/quote]

sorry,i don't exactly understand,my english is not very good
For this sentence ,your going to have to subtract half a texel from the original coordinates anyway (basically subtract 0.5/width from u and 0.5/height from v).
do you mean subtract-0.5 for each x and each y?the article said we just need to subtract -0.5 for each x and each y.
could you give me a example?that will help me understand,thank you!
And ,for this sentence:you need to squeeze the texture by half a texel coordinate.
how to do that?
thank you!
0

Share this post


Link to post
Share on other sites
Read this [url="https://developer.nvidia.com/sites/default/files/akamai/tools/files/Texture_Atlas_Whitepaper.pdf"]article[/url] it's been a long time since I implemented this and don't remember all of the details anymore. The DX sample is adjusting the vertex coordinates instead of thet texture coordinates, it's better to fix the texture coordinates so they are in the range [0.5/width, 1 - 0.5 / width] for u and [0.5 / height, 1 - 0.5 / height] for v.
0

Share this post


Link to post
Share on other sites
[quote name='NightCreature83' timestamp='1355303178' post='5009755']
Read this [url="https://developer.nvidia.com/sites/default/files/akamai/tools/files/Texture_Atlas_Whitepaper.pdf"]article[/url] it's been a long time since I implemented this and don't remember all of the details anymore. The DX sample is adjusting the vertex coordinates instead of thet texture coordinates, it's better to fix the texture coordinates so they are in the range [0.5/width, 1 - 0.5 / width] for u and [0.5 / height, 1 - 0.5 / height] for v.
[/quote]

ok..thank you
I am sorry,but i can't understand it at all,my English is not good enough, i can't read this article.But i still don't understand and it said"Most applications, however, use texture coordinates ranging from zero to one,inclusive, nonetheless.".
The things which i don't understand is 'models need to use u-coordinates in the range [.5/width, 1-.5/width] and v-coordinates in the range [.5/height, 1-.5/height].'why do we need to do that?
0

Share this post


Link to post
Share on other sites
left-top:(0,0)
right-top:(369.0f/1000,0) //369 divide by 1000,because the width of A is 369,and the width of texture atlas is 1000
left-bottom:(0,153.0f/1000) //153 divide by 1000,because the height of A is 153,and the height of texture atlas is 1000
right-bottom:(369.0f/1000,153.0f/1000) //same

i do this,it works,does it wrong?
0

Share this post


Link to post
Share on other sites
[quote name='AlanWu' timestamp='1355356094' post='5010013']
The things which i don't understand is 'models need to use u-coordinates in the range [.5/width, 1-.5/width] and v-coordinates in the range [.5/height, 1-.5/height].'why do we need to do that?
[/quote]

I think that might just be for displaying a fullscreen quad and is a way of taking into account the texel-to-pixel offset in DX9 and below.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx[/url]
0

Share this post


Link to post
Share on other sites
[quote name='Steve_Segreto' timestamp='1355382716' post='5010093']
[quote name='AlanWu' timestamp='1355356094' post='5010013']
The things which i don't understand is 'models need to use u-coordinates in the range [.5/width, 1-.5/width] and v-coordinates in the range [.5/height, 1-.5/height].'why do we need to do that?
[/quote]

I think that might just be for displaying a fullscreen quad and is a way of taking into account the texel-to-pixel offset in DX9 and below.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx"]http://msdn.microsof...0(v=vs.85).aspx[/url]
[/quote]

ok,thank you!
Thanks everyone!
i think it is no problem now.
And i am writing texture atlas editor.
0

Share this post


Link to post
Share on other sites
[quote name='Steve_Segreto' timestamp='1355382716' post='5010093']
[quote name='AlanWu' timestamp='1355356094' post='5010013']
The things which i don't understand is 'models need to use u-coordinates in the range [.5/width, 1-.5/width] and v-coordinates in the range [.5/height, 1-.5/height].'why do we need to do that?
[/quote]

I think that might just be for displaying a fullscreen quad and is a way of taking into account the texel-to-pixel offset in DX9 and below.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx"]http://msdn.microsof...0(v=vs.85).aspx[/url]
[/quote]

Let me amend this and say that anytime you programmatically generate u,v coordinates you have to take into account the texel-to-pixel offset when using DX9 and below, not just for full-screen quads.
0

Share this post


Link to post
Share on other sites
[quote name='AlanWu' timestamp='1355356094' post='5010013']
[quote name='NightCreature83' timestamp='1355303178' post='5009755']
Read this [url="https://developer.nvidia.com/sites/default/files/akamai/tools/files/Texture_Atlas_Whitepaper.pdf"]article[/url] it's been a long time since I implemented this and don't remember all of the details anymore. The DX sample is adjusting the vertex coordinates instead of thet texture coordinates, it's better to fix the texture coordinates so they are in the range [0.5/width, 1 - 0.5 / width] for u and [0.5 / height, 1 - 0.5 / height] for v.
[/quote]

ok..thank you
I am sorry,but i can't understand it at all,my English is not good enough, i can't read this article.But i still don't understand and it said"Most applications, however, use texture coordinates ranging from zero to one,inclusive, nonetheless.".
The things which i don't understand is 'models need to use u-coordinates in the range [.5/width, 1-.5/width] and v-coordinates in the range [.5/height, 1-.5/height].'why do we need to do that?
[/quote]
sorry,I don't understand, why can't I use 0 to 1for u, v coordinate?Could you give me a example please? Thank you!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0