batch draw!

Started by
19 comments, last by AlanWu 11 years, 4 months ago
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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Advertisement

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.

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!
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 this for texture coordinate mapping in DX9 and this Nvidia sample for more on atlas texturing

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


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 this for texture coordinate mapping in DX9 and this Nvidia sample for more on atlas texturing


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!
Read this article 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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion


Read this article 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.


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?
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?

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?


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.

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

[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?


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.

http://msdn.microsof...0(v=vs.85).aspx
[/quote]

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

[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?


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.

http://msdn.microsof...0(v=vs.85).aspx
[/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.

This topic is closed to new replies.

Advertisement