Browse Source

Duplicate the Quake palette CLUT with transparency flag set, to use for water surfaces. Doesn't actually work yet but the solution should be something in this direction.

master
Nico de Poel 3 years ago
parent
commit
64d9b16c12
  1. 17
      texture.cpp

17
texture.cpp

@ -48,11 +48,13 @@ static bool generate_clut(const char* paletteFile, tim::PARAM* outTim)
fread(palette, sizeof(unsigned char) * 3, PALETTE_SIZE, fp);
fclose(fp);
tim::PIX_RGB5* clut = (tim::PIX_RGB5*)malloc(PALETTE_SIZE * sizeof(tim::PIX_RGB5));
tim::PIX_RGB5* clut = (tim::PIX_RGB5*)malloc(PALETTE_SIZE * sizeof(tim::PIX_RGB5) * 2);
if (clut == NULL)
return false;
for (int c = 0; c < PALETTE_SIZE; ++c)
memset(clut, 0, PALETTE_SIZE * sizeof(tim::PIX_RGB5) * 2);
for (int c = 0; c < PALETTE_SIZE - 1; ++c) // Final palette entry is for alpha masking
{
unsigned char color[3];
desaturate(&palette[3 * c], color);
@ -60,16 +62,23 @@ static bool generate_clut(const char* paletteFile, tim::PARAM* outTim)
clut[c].r = color[0] >> 3;
clut[c].g = color[1] >> 3;
clut[c].b = color[2] >> 3;
clut[c].i = (c == 255); // Final palette entry is for transparencies
clut[c].i = 0;
// Completely black pixels are regarded as transparent by the PS1, so prevent that from happening by making those palette entries *nearly* black
if (clut[c].r == 0 && clut[c].g == 0 && clut[c].b == 0)
clut[c].r = clut[c].g = clut[c].b = 1;
}
// Create a second palette with the transparency flag set. Used for water surfaces.
for (int c = 0; c < PALETTE_SIZE; ++c)
{
clut[c + PALETTE_SIZE] = clut[c];
clut[c + PALETTE_SIZE].i = 1;
}
outTim->clutData = clut;
outTim->clutWidth = PALETTE_SIZE;
outTim->clutHeight = 1;
outTim->clutHeight = 2;
return true;
}

Loading…
Cancel
Save