Page 1 of 1

PSX semitransparency to ARGB

Posted: March 21st, 2016, 3:22 am
by Yagotzirck
Hello, i'm trying to convert sprites from a PSX game(Disruptor) to a PC-friendlier ARGB TGA format.
No big issues, except for the way the PSX handles semitransparency.

The library reference describes these 4 methods in GetTPage():
Semitransparency rate
0: 0.5 x Back + 0.5 x Forward
1: 1.0 x Back + 1.0 x Forward
2: 1.0 x Back - 1.0 x Forward
3: 1.0 x Back + 0.25 x Forward
I understand the way each method works, what I can't figure out is how to convert each method to standard png-like ARGB format :?
Thanks in advance to whoever can help

Re: PSX semitransparency to ARGB

Posted: March 21st, 2016, 6:18 pm
by LameGuy64
The way how the PlayStation handles semi-transparency is a bit tricky but it can be figured out. All graphical primitives that use textures have a flag that tells the GPU to do semi-transparent blending or not and another flag that tells which blending method should be used.

Each pixel (in a 16-bit texture) or CLUT color (in a 4-bit/8-bit texture) has a semi-transparency bit which is placed at the very end of a 16-bit color value because the RGB color values only take up the first 15 bits. This bit is used as a special flag for both non-blended and blended drawing of the texture image.


The logic as to how the semi-transparency bit affects the pixel is as follows (full-black means all RGB components are 0):

-- If Semi-Transparent mode is off --
Full-black without STP bit = Transparent (alpha = 0)
Full-black with STP bit = Opaque black (alpha = 255)
Non full-black without STP bit = Solid color (alpha = 255)
Non full-black with STP bit = Solid color (alpha = 255)

-- If Semi-Transparent is on --
Full-black without STP bit = Transparent (alpha = 0)
Full-black with STP bit = Semi-transparent black (alpha = 127)
Non full-black without STP bit = Solid color (alpha = 255)
Non full-black with STP bit = Semi-transparent color (alpha = 127)


I'm not sure how you can convert the colors to other blending modes (blend modes 1-3) as the only way to achieve that is to use a different blending algorithm used when your TGA image is drawn.

Re: PSX semitransparency to ARGB

Posted: March 21st, 2016, 11:52 pm
by Yagotzirck
Yeah, I came to the conclusion the modes 1-3 are just exotic simple arithmetic blending modes and it's impossible to have an exact conversion to ARGB... though I've used an approximation method as follows:

-Convert each 16-bit CLUT pixel to ARGB32, left-shifting each color component by 3 values
if STP bit is set:
-Use the highest color component as alpha value
-Multiply each color component by (255.0 / highestColorComponent).
Otherwise use 255 as alpha value.

Certainly not the most accurate method, but at least that way the sprites appear closer to they way they look like in-game :)
Any suggestions on how to make it even more accurate are welcome, but for now the result seems pretty acceptable to me