Graphics Palette system

posted in A Keyboard and the Truth for project 96 Mill
Published November 08, 2005
Advertisement
Did some design on our underlying graphics storage system.

Unlike the old days (directdraw), you cant just slap any old sized image into your game. In Direct3D, If you do you are likely to waste bunches of space, and even more likely find that there is no texture size large enough .

So I am working on an automated system of storage; what is commonly called a palette (or a texture atlas), is usually created by an artist or designer, but I really don't like this restriction, so instead, the engine will build and maintain it's own palettes.

(An example of a 512x512 palette)


The system will choose the 'best' palette size based on the hardware capabilities; palettes can be as small as 256x256 or technically as large as the graphics hardware will allow (though 1024x1204 is likely to be our largest)

The basic idea of usage is to 'fill the holes' efficantly. The largest texture that can fit into the palette is 256x256 .

Each palette is structured like so:

Palette has n regions (width/256 x height/256)

each 256 region has 4 128 regions
each 128 region has 4 64 regions
each 64 region has 4 32 regions
each 32 region has 4 16 regions

The key to usage is proper decision on how to store incoming images:

Example: I want to load a 256x256 image

find an empty 256 region
found an empty one?
use it
if not
create new palette
repeat

Example: I want to load a 32x32 image

find a 256 region with a 128 region with a 64 region with an empty 32 region

The code will be a little complicated to implement, but overall should be pretty logical.

The resulting storage returns a fully-qualified palette address

palette index,(u,v)

This system can be further extended by cutting up larger images (512x512) into 256x256 sizes
Previous Entry Press Releases
Next Entry Getting Further
0 likes 5 comments

Comments

jollyjeffers
Not sure what API you're using, but have you considered artifacts from texture addressing? Sometimes it's necessary to factor in a gutter in order to stop neighbouring tiles in the palette from being sampled at the borders (e.g. bilinear filtering)...

Also, if you're feeling really adventurous, I was discussing an idea with someone the other day - temporal resource rearrangements.

That is, if you had 5 palettes fully loaded with textures, you'd (over a period of 100 frames or so) monitor what order those textures were required by the hardware. In Direct3D that'd be a SetTexture() call. You'd end up with a list like:

Frame_Begin
SetTexture( 0, Palette_1 );
SetTexture( 0, Palette_2 );
SetTexture( 0, Palette_3 );
SetTexture( 0, Palette_2 );
SetTexture( 0, Palette_4 );
SetTexture( 0, Palette_5 );
SetTexture( 0, Palette_1 );
SetTexture( 0, Palette_2 );
Frame_End

and you could then attempt to optimize the layout of the tiles (probably by moving tiles between palettes) in the palettes so that less state changes occured.

I'll be quiet now [smile]

Jack
November 08, 2005 04:21 PM
EDI
I havent considred that unfortunetly.

Is there no way to insure it doesnt read past?
November 08, 2005 05:08 PM
jollyjeffers
Quote:Is there no way to insure it doesnt read past?

Correct texel addressing should solve most things, but I think there are still cases where you can get the occasional artifact.

Basically, in a bitmap image you store pixel's intensity as an area (usually square!). Whereas when it comes to rasterization, the intensity as defined as a point in the middle of that pixel. If you get the addressing wrong (address the top-left for example) then it knows that part of the colour at that point is an interpolation with the neighbour pixel.

All gets quite confusing unless you write it out on paper with diagrams [smile]

If you've not seen it, have a read of Directly Mapping Texels To Pixels - it covers the basic rules on how to offset things correctly.

hth
Jack
November 08, 2005 05:52 PM
EDI
yup, thankfully i know about proper texture coord adressing (half-texel yada yada), I guess i am just worried about the effects of scaling textures.
November 09, 2005 07:27 AM
Gaheris
I like the idea of optimizing the palettes which Jack proposed but I'd do it a bit differently.

If your game is split into levels or regions you could rank the "importance" of textures once, then store this information in an extra file (or even in the level file) and use it when you load a level or enter a new region. This would make loading time a bit longer, but it would avoid lags which occur when you need a texture which is currently being moved [to another palette].
November 09, 2005 07:31 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement