gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Alpha-colored 3d particles

#145874 - melw - Sat Nov 24, 2007 12:45 pm

Last night I played around with some alpha-blended particles in MODE_0_3D. Using RGB8_A5 texture format is otherwise ok, but the 8 color palette doesn't give much freedom while I wanted to pick the particle color freely from all the 32k possible values. In the end I came up with one solution (which some of you may consider a dirty hack): Filling the entire VRAM bank E with all the colors, create 8 otherwise identical particle textures, only each of them using different color from the "8 color palette" and set palette pointer manually when drawing to get the right color.

Code:
#define NUM_TEXTURES 8
int textureIds[NUM_TEXTURES];

u8 *textureData[NUM_TEXTURES];

// particle texture loading etc.

for(int i=0;i<NUM_TEXTURES;i++)
{
   glBindTexture(0, textureIds[i]);
   glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_32, TEXTURE_SIZE_32, 0, TEXGEN_TEXCOORD, (u8*)textureData[i]);
}

u16 *palData = (u16*)malloc(32*32*32);
for(r=0;r<32;r++) // generate all 15bit colors into one large palette
{
   for(g=0;g<32;g++)
   {
      for(b=0;b<32;b++)
      {
         palData[r*1024+g*32+b] = RGB15(r,g,b);
      }
   }
}
glTexLoadPal(palData, 32768, 0);

// when drawing a particle - color is integer between 0...32768
glBindTexture(0, textureIds[textureId+(color&7)]);
GFX_PAL_FORMAT = color>>4;
glBegin(GL_QUAD);
// ... rest of the draw code

If you know how to do this better or otherwise, feel free to comment. Wasting half of the VRAM bank E for oversized palette data feels stupid, but at least it works. :)

test src + nds

#145881 - Lick - Sat Nov 24, 2007 4:14 pm

If you want to modulate texture color with vertex color, use glMaterialf(GL_EMISSION, RGB15(31,0,0));. Here, the texture will be modulated with red. Default should be 0x7FFF (white).

This way, you can use greyscale+alpha textures modulated with the particle's color.
_________________
http://licklick.wordpress.com

#145882 - melw - Sat Nov 24, 2007 5:37 pm

Thanks! Reduced palette size from 32kb to 8 bytes and texture count from 8 to 1.