STR : Semi-Transparency

Code example

https://github.com/ABelliqueux/nolibgs_hello_worlds/tree/main/hello_poly_stp
https://github.com/ABelliqueux/nolibgs_hello_worlds/tree/main/hello_cubetex_stp

Hello_stp

STP : Semi-Transparency usage

This example shows the various way of converting an image with transparency to a TIM and use it in code.
It also shows the effect of activating Semi-Transparency on a primitive textured with those images.

Use the SELECT button to switch primitive semi-transparency on and off.

It also features a few C struct to facilitate access to the TIM file / pixel data.

You can use Lameguy64's img2tim tool to convert most of image formats to the psx TIM format..

TIM transparency

See https://github.com/ABelliqueux/nolibgs_hello_worlds/wiki/TIM#transparency for more details on transparency.

Semi-transparency rates

You can find another example with the various transparency rates demoed here : https://github.com/ABelliqueux/nolibgs_hello_worlds/tree/main/hello_cubetex_stp

Important

By default, the PSX will consider black pixels (0,0,0,0) as transparent.
In order to display those black pixels as black, you have to set the STP on black (1,0,0,0).
Black pixels and non-black pixels with the STP bit will display as semi-transparent when using SetSemiTrans().

STP on black

Use this to display black pixels as black, not transparent. The inverted alpha mask of the TIM corresponds to the position of black (0,0,0) pixels in the image.

img2tim -b -org 640 0 -o stpOnBlack.tim av.png

STP on non-black

Black pixels will be considered as transparent, and non-black pixels will receive semi-transparency with SetSemiTrans().

The alpha mask of the TIM corresponds to the position of non-black (n,n,n) pixels in the image. Additionally, a setting allows you to define the RGB value to be considered transparent ; -tcol . This does not set any STP flag.

img2tim -t -org 320 0 -o stpOnNonBlack.tim av.png

Use alpha channel

The alpha mask of the TIM corresponds to the existing alpha channel of the image (PNG, GIF, TGA, TIFF). Additionally, a setting allows you to define the threshold for the alpha value to be considered transparent ; -alpt . This does not set any STP flag.

img2tim -usealpha -org 640 256 -o stpOnNonBlack.tim av.png

Use color index

When using 8/4bpp palettized images, you can specify the index number of the color to be considered transparent. This does not set any STP flag.

You can set the STP bit by CLUT color with PsyQ's TIMTOOL.EXE. This allows you do do cool stuff like oly having specific colors being rendered as semi-transparent by SetSemiTrans().

img2tim -b -bpp 8 -tindex 0 -org 640 256 -plt 0 481 -o stpOnColIndex.tim av8.png

Black transparency work-around

Using a pseudo-black color with one of the channels value to 10, i.e : 0,0,10 can be done so you dont have to set the STP bit on full black.
This allows you to keep the pseudo-black opaque when using SetSemiTrans().

Bonus links

A case study of TR1/2 transparency usage to create pseudo-reflections on PSX :
part 1 - study : https://wiki.arthus.net/?tr2_not_shaders-follow_up
part 2 - re-creation : https://wiki.arthus.net/?tr2_not_shaders