From 64d9b16c12ca418787439aab7038054cd2c32000 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 31 Jan 2023 10:42:27 +0100 Subject: [PATCH] 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. --- texture.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/texture.cpp b/texture.cpp index 8dfd53d..e20a4db 100644 --- a/texture.cpp +++ b/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; }