Page 1 of 1

[Question] Can i create TIM with multiple CLUT's?

Posted: January 8th, 2019, 12:23 am
by NITROYUASH
Hi guys. I want to create a TIM with multiple palettes (CLUT's). Is it possible?
Never seen any utilities to add more CLUT's to TIM from TIM Tool v3 or anything else.

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 8th, 2019, 10:55 am
by LameGuy64
So far there aren't any tools that support placing multiple CLUTs inside a single TIM. You could however create a 16-bit TIM containing multiple CLUT rows as a workaround.

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 8th, 2019, 2:45 pm
by NITROYUASH
Do i need to add 16b CLUT's as a regular image then swap palette using something like setClut, right?
It's working only for 16-bit TIM's?

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 8th, 2019, 3:25 pm
by LameGuy64
You store the CLUTs as a regular 16-bit TIM file (ie. a TIM containing 8 CLUTs would be 256x8 for 8-bit CLUTs or 16x8 for 4-bit CLUTs) and then use its image coordinates on setClut. To select the other CLUTs simply increment the y coordinate from the coordinates where your TIM of CLUTs is positioned to.

Remember that CLUTs are always strips of 16-bit color pixels.

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 10th, 2019, 9:23 am
by gwald
I thought 16bit tims don't have CLUT's?
I did 4bit clut generation and clut swapping.. via brute forcing it..
Saving a single image (different colours in a clut) and timtool that image (move it to the display buffer.. not needed) and clut (keep it safe), then in code you just swap between cluts.
I'm starting to forget the details :'(

Okay I remember now, so i have sprite animation (doom trooper), each animation cell has it's own set of colours, ie green, red, purple, yellow etc etc.
In code you store the soldier's colour (Clut index to a clut array) and when rendering it, you use that.. not the TIM's clut (or it'll flash different colours).
Because I don't need each CLUT to be the same (duplicate data) I change each CLUT to be unique colours.
If that makes sense??
It was the easiest way, i'm sure there's better ways.

https://www.youtube.com/watch?v=L8nat6ZMOuc

https://www.youtube.com/watch?v=L8nat6ZMOuc

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 10th, 2019, 7:49 pm
by LameGuy64
I was meaning to say having a TIM containing a bunch of CLUTs as a 16-bit texture image. A CLUT is really just a 1 pixel high 16-bit texture that is no different to a 16-bit texture image.

Technically a 16-bit TIM can contain a CLUT but its not really necessary to have a CLUT in one. Multiple CLUTs can be stored inside a single TIM as the file format treats the CLUT data like a texture image as well but all currently available TIM tools don't support it.

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 10th, 2019, 9:25 pm
by NITROYUASH
Interesting.
But i have an idea too. What if we create CLUT inside the game code and then write result to VRAM? Can we? :)

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 11th, 2019, 9:24 am
by gwald
Yes, 16bit TIM's are very easy to create!

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: January 11th, 2019, 11:49 am
by LameGuy64
Should be doable with this kind of struct:

Code: Select all

typedef struct {
    unsigned short r:5;
    unsigned short g:5;
    unsigned short b:5;
    unsigned short i:1;    // Mask bit used for transparencies
} PIX16;
Make an array out of it with 16 elements for a 16 color CLUT or 256 for a 256 color CLUT and then upload them to VRAM like this:

Code: Select all

RECT crect;
crect.x = < desired x position of clut >;
crect.y = < desired y position of clut >;
crect.w = 256; // 16 for 16 color CLUTs
crect.h = 1;
LoadImage( &crect, clutdata );

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: March 21st, 2019, 6:37 pm
by NITROYUASH
Sorry to not tested your code so long, but yesterday i wrote the code based on your example. And yes, looks like it's working. Thanks. :>

Code: Select all

// Custom Palette (CLUT) structs
typedef struct {
	u_short r:5;
	u_short g:5;
	u_short b:5;
	u_short i:1;    // Mask bit used for transparencies
} CPAL;

CPAL		FNT1_pal_red[256] = {
	0,0,0,1, 15,0,0,0, 30,0,0,0, 45,0,0,0,
	60,0,0,0, 75,0,0,0, 90,0,0,0, 105,0,0,0,
	120,0,0,0, 135,0,0,0, 150,0,0,0, 165,0,0,0,
	180,0,0,0, 195,0,0,0, 210,0,0,0, 225,0,0,0,
	240,0,0,0, 255,0,0,0,
};

/*	Record custom CLUT-Palette to VRAM.

	input: Insert CLUT here
	clr_list: List of colors in CLUT
	X/Y: VRAM Coordinates, where the new palette will be saved			  */

void SetCustomCLUT(CPAL *input, short clr_list, int X, int Y) {
	int i,type;
	RECT rect;			// Init rectangular area
	
	if (clr_list <= 16)	type = 16;
	else				type = 256;

	// Erase junk fron unused part of output-CLUT
	for (i = clr_list; i < type; i++) {
		input[i].r = 0; input[i].g = 0;
		input[i].b = 0; input[i].i = 0;
	}

	rect.x = X;
	rect.y = Y;
	
	rect.h = 1;		// Always 1
	rect.w = type;	// CLUT size

	LoadImage(&rect, (u_long*)input);
}

Code: Select all

int main(void) {
	// Graphics initializer
	startup_init();

	SetCustomCLUT(FNT1_pal_red, 18, 700, 14);
	while(1) {
		PrepDisp();
		FntPrint("Do something!");
		Display();
	}
}

Re: [Question] Can i create TIM with multiple CLUT's?

Posted: March 22nd, 2019, 5:32 am
by NITROYUASH
U P D:
Something else is needed here. The initialized CLUT cannot be used for any images because final colors from SetCustomCLUT() are distorted.
► Show Spoiler