Jump to content
  • Advertisement
Sign in to follow this  
Canglong

Using Texture Atlas (tai) files with Direct3D

This topic is 2512 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

I'm making a 2D- game in Direct3D 9 using quads with ortographic projection. I want to make a large texture atlas containing several smaller textures for drawing large background objects. That would reduce draw calls and calls to setTexture. I downloaded nvidias atlas creation tool, it creates texture atlases as .tai files. But how do use these files in Direct3D? I can't find any information in the nvidia documentation. Can I create a texture from the .tai file? Do I have to convert them to an image format such as PNG?

Share this post


Link to post
Share on other sites
Advertisement

I'm making a 2D- game in Direct3D 9 using quads with ortographic projection. I want to make a large texture atlas containing several smaller textures for drawing large background objects. That would reduce draw calls and calls to setTexture. I downloaded nvidias atlas creation tool, it creates texture atlases as .tai files. But how do use these files in Direct3D? I can't find any information in the nvidia documentation. Can I create a texture from the .tai file? Do I have to convert them to an image format such as PNG?

If I remeber correctly the TAI file only contains the definition of the texture coordinates for each particular texture in the texture file, does it output a DDS file as well?
That particular tool isn't very great and tends to generate highly inefficient atlas textures, when you look at the texture generation code there is a comment in there that they can't explain why it generates horizontal textures.

If it spits out a DDS file as well as a TAI file, you create a texture from the DDS file and then scale the texture coordinates in the shader according to the area the TAI info contains.

Having had a quick look at the tools again it spits out a DDS and a tai file, the tai file contains the texture name you want to set and the texture coordinates the texture maps to in the DDS file.
When using the texture you just assign 0..1 to the UV coordinates and pass the coordinates from the tai file to the shader as a constant. In the shader you then use the coorindate the tai file specifies. If it specifies a location and a size as a vector4 you will have to scale the texture cooridnates by the size and start from the first two elements of the vector4

Share this post


Link to post
Share on other sites
Thanks for the reply.
I'm not that experienced with Direct3D and graphics programming yet, so perhaps this topic is a bit too advanced for me. I'm afraid i don't know what a vector4 is, I've only been using vector3s. I haven't started working with shaders yet. I only know of setting the vertex uv coordinates before creating the vertex buffer, is that what you mean, when you say shader?
Anyway, I tried texturing with the dds file and it seemed to work fine, but you mentioned these atlases were inefficient, do have any tips for a better atlas creation tool or some guide on how to write your own?

Share this post


Link to post
Share on other sites
No when I say shader, I mean shader, it's a piece of code that completely or partly replaces the fixed function pipeline(FF), this is what you are currently using I suspect. It's all the setRenderState and similar calls you are making. Most of that is far easier to achieve in shaders then through the FF.
A vector4 is similar to a vector3 except it has one more element so 4 instead of 3.
You will have to write your own atlasing tools mostly, it all comes down to the packing algorithm how efficient the resulting atlas texture will be. I based the one I implemented on an area packer and so it sorts all the textures it needs to pack by area size and than applies a greedy subdivision algorithm to pack it all into the area of the atlas texture. The benefit of area packing is that when you sub divid the texture you know that if the texture isn't full yet the next one in the list should fit in the rest of the area of the texture that you just divided. Another way to do it is to map the gemeotry uv's to the texture space.
I used this one http://www.blackpawn.com/texts/lightmaps/ but a simple google search on atlas textures gives you a million other ways to do it.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!