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

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 88
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

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

Post by NITROYUASH » January 8th, 2019, 12:23 am

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.

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 343
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

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

Post by LameGuy64 » January 8th, 2019, 10:55 am

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.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 88
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

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

Post by NITROYUASH » January 8th, 2019, 2:45 pm

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?

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 343
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

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

Post by LameGuy64 » January 8th, 2019, 3:25 pm

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.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
gwald
1997 Yaroze Enthusiast
1997 Yaroze Enthusiast
Posts: 256
Joined: September 18th, 2013, 8:44 am
I am a: programmer/DBA
PlayStation Model: Net Yaroze
Location: Australia
Contact:

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

Post by gwald » January 10th, 2019, 9:23 am

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

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 343
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

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

Post by LameGuy64 » January 10th, 2019, 7:49 pm

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.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 88
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

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

Post by NITROYUASH » January 10th, 2019, 9:25 pm

Interesting.
But i have an idea too. What if we create CLUT inside the game code and then write result to VRAM? Can we? :)

User avatar
gwald
1997 Yaroze Enthusiast
1997 Yaroze Enthusiast
Posts: 256
Joined: September 18th, 2013, 8:44 am
I am a: programmer/DBA
PlayStation Model: Net Yaroze
Location: Australia
Contact:

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

Post by gwald » January 11th, 2019, 9:24 am

Yes, 16bit TIM's are very easy to create!

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 343
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Skype: lameguy64
Location: Philippines

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

Post by LameGuy64 » January 11th, 2019, 11:49 am

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 );
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 88
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

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

Post by NITROYUASH » March 21st, 2019, 6:37 pm

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();
	}
}

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 88
Joined: January 7th, 2018, 12:03 am
PlayStation Model: PSone
Steam: NITROYUASH
Location: Russian Federation
Contact:

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

Post by NITROYUASH » March 22nd, 2019, 5:32 am

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest