Sign in to follow this  
  • entries
    177
  • comments
    531
  • views
    163639

VAtlas - Texture atlas tool

Sign in to follow this  
Scet

939 views

My work with voxels lead me to try out volume textures(thinking it might be possible to render them, I was wrong). Anyway I ended up making a texture atlas class that would combine single images into one large volume texture. Only after I completed it did I find the nVidia tool, however it had several problems that mine did not. So I built a command-line utility similar to theirs using my code, and the result was VAtlas.

Edit(Nov. 25, 07): There is a newer version of VAtlas with support for colour keying and tile sheets, VAtlas 0.3. Also for anyone looking for help, please PM me, do not e-mail me or comment on this journal entry, I won't see it.

Download VAtlas 0.2
VAtlas 0.1 (incase of problems with 0.2)




results:



For volume textures the output is always in DDS format, but I added the ability to export PNGs for single textures for you non-Direct3D infidels. Only problem is Direct3D will only output 24-bit PNGs, oh well. If you want 32-bit PNGs, you'll have to convert the DDS files yourself.

I would appreciate it(read: giant rate++) if people could give it a try and report any possible errors. Read the readme file first though. Also you'll need .Net 2.0 and Managed DirectX installed.

MDX and volume textures

There seems to be very little information on volume textures out there, especially concerning MDX. So here is how to create a custom vertex format that will use the Tw coordinate in MDX.


public struct CustomVertex
{

public float X;

public float Y;

public float Z;

public float Tu;

public float Tv;

public float Tw;

public static readonly Direct3D.VertexFormats Format;

public static readonly Direct3D.VertexElement[] Declarator = new Direct3D.VertexElement[]
{
new Direct3D.VertexElement( 0, 0, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.Position, 0 ),
new Direct3D.VertexElement( 0, 12, Direct3D.DeclarationType.Float3, Direct3D.DeclarationMethod.Default, Direct3D.DeclarationUsage.TextureCoordinate, 0 ),
Direct3D.VertexElement.VertexDeclarationEnd
};

public static readonly int StrideSize = Direct3D.VertexInformation.GetDeclarationVertexSize( Declarator, 0 );

static CustomVertex()
{
Format = Direct3D.VertexInformation.FormatFromDeclarator( Declarator );
return;
}

public CustomVertex( float X, float Y, float Z, float Tu, float Tv, float Tw )
{
this.X = X;
this.Y = Y;
this.Z = Z;
this.Tu = Tu;
this.Tv = Tv;
this.Tw = Tw;
return;
}

}





Sign in to follow this  


5 Comments


Recommended Comments

VAtlas seems to work really well to me. I did a random dump of all the .bmp files in my main graphics folder:



What algorithm are you using to decide where to put the images? I've written a dynamic atlasing system for my Direct3D sprite wrapper that bungs images onto a Direct3D texture and produces similar results to the above, but the method I use is naive to say the least and I'm curious to know about more intellegent approaches than my sort of brute force method.

Share this comment


Link to comment
Thanks for trying it out. While typing this up I actually thought of a more efficent way. The original class was meant to add and remove textures during a game, but that is unneeded here.

So I'll be back soon with something a bit faster.

Share this comment


Link to comment
Alright give 0.2 a try, it should perform slightly better.

If you're using a software API like SDL and your hardware supports non power of 2 texture(for VAtlas) try adjusting the width and height until you find something with very few empty spots.

The way it works is by seperating each texture into a 2D array of "cells". Each cell is 8x8 pixels and is actually a pointer to an image. This way when looking for empty cells it can skip over a bunch if it finds one that contains an image.

Share this comment


Link to comment
I'll try it out again tonight and see if it is quicker.

I use a similar system although not quite as clever. I just create a temporary 2D map of bools that represent a grid on the texture (you can control the granularity when you create the map) and I just search across and down for a rectangle big enough to put each texture in.

It is a little naive, but I've loaded hundreds of images onto a texture at game startup with this method and have yet to notice any kind of slowdown. I guess if I was trying to load textures during actual game execution I'd need a faster method.

Share this comment


Link to comment
Really nice tool!

But I have a problem; I can't get it to store
the alpha channel of the original images!
I'm exporting to .dss.

Thanks for your help.

Share this comment


Link to comment

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