Color Combiner
In one and two cycle mode, the color combiner takes input from the texturing unit. The color combiner is fed various inputs, and combines them via user set inputs. Pixel output from the color combiner is fed into the chroma key & alpha fix up unit and then into the alpha compare unit.
Inputs
The color combiner has inputs a, b, c, d for color and alpha separately.
Combined Color - 0
Texel 0 Color - 1
Texel 1 Color - 2
Primitive Color - 3
Shade Color - 4
Environment Color - 5
1.0 - 6
Noise - 7
0.0 - 8-15
Combined Color - 0
Texel 0 Color - 1
Texel 1 Color - 2
Primitive Color - 3
Shade Color - 4
Environment Color - 5
Key Center - 6
Convert K4 - 7
0.0 - 8-15
Combined Color - 0
Texel 0 Color - 1
Texel 1 Color - 2
Primitive Color - 3
Shade Color - 4
Environment Color - 5
Key Scale - 6
Combined Alpha - 7
Texel 0 Alpha - 8
Texel 1 Alpha - 9
Primitive Alpha - 10
Shade Alpha - 11
Environment Alpha - 12
LOD Fraction - 13
Primitive LOD Fraction - 14
Convert K5 - 15
0.0 - 16-31
Combined Color - 0
Texel 0 Color - 1
Texel 1 Color - 2
Primitive Color - 3
Shade Color - 4
Environment Color - 5
1.0 - 6
0.0 - 7
Combined Alpha - 0
Texel 0 Alpha - 1
Texel 1 Alpha - 2
Primitive Alpha - 3
Shade Alpha - 4
Environment Alpha - 5
1.0 - 6
0.0 - 7
Combined Alpha - 0
Texel 0 Alpha - 1
Texel 1 Alpha - 2
Primitive Alpha - 3
Shade Alpha - 4
Environment Alpha - 5
1.0 - 6
0.0 - 7
Texel 0 Alpha - 1
Texel 1 Alpha - 2
Primitive Alpha - 3
Shade Alpha - 4
Environment Alpha - 5
1.0 - 6
0.0 - 7
Combined Alpha - 0
Texel 0 Alpha - 1
Texel 1 Alpha - 2
Primitive Alpha - 3
Shade Alpha - 4
Environment Alpha - 5
1.0 - 6
0.0 - 7
Inputs values are q1.8 \([0-511]\) where \(256 == 1.0\).
Input variables A, B, and D use a special sign extension \([-0.5 - 1.5)\), while C uses uses two’s compliment \([-1.0 - 1.0)\).
Note
1.0 is the only value set to 256 specifically, while others are set to a max of 255. This can allow for overflow via combined input on C if passing 1.0.
There are pipeline bugs when using Texel 0 and Texel 1 in the combiner. The pixel accessed for source colors changes depending on which cycle you are in, and which pipeline mode you are in. Texel 0 becomes Texel 1 while in the second cycle. If you are in one cycle mode, Texel 1 is undefined behavior, but generally it will be equal to the next pixel value of Texel 0.
Outputs
The combiner equation \(Color = (A-B)*C + D\) is performed on each cycle. The output of the first cycle is fed to the 2nd cycle under the combined_X input, where X is color or alpha. The final combined output is subject to the special sign extension \([-0.5 - 1.5)\). Output of the color combiner value goes to Alpha Fix Up & Chroma Key Units.
Chroma Key
Chroma key applies alpha based on the distance from the pixel color from the key value. Chroma key will decrease alpha from a max of key_width based on the distance of key_center from a chosen source color. The scale of that alpha change is based on key_scale where \((key\_scale == 1.0/edge\_size)\). Higher scales result in faster changes in alpha. A scale of 255 is the equivalent of hard edge keying.
The color combiner expects the last used cycle to have a setup of (1). After which, the chroma key unit will perform (2), with the min being taken over the r, g, b channels, to get the key_alpha. Chroma key calculations are done before special sign extension and downshifting on combined_color, which means combined_color will be a s1.16 - [0-0x1ffff] value.
key_center, and key_scale are q0.7 \([0-255]\) values, while key_width is a s7.4 \([0-4096]\) value. A width over 1.0 disables chroma key calculations, upon which key_alpha is set to 0.
When key_en is enabled, the combined color is replaced with the A_Color combiner input.
If alpha_cvg_sel is disabled, the combined alpha is replaced with key_alpha.
Alpha Fix Up
The alpha fix up applies changes to coverage and combined alpha based on rdp flag selection:
Shade alpha is clamped to 0xff (since it is blender input).
cvg_x_alpha - multiplies combined alpha and cvg and uses as cvg (not key alpha), alpha values of 0xff are set to 0x100 for this calc (not that important tbh)
alpha_cvg_sel - uses cvg value for alpha out (overwrites key alpha)
Alpha Compare
Alpha compare is performed after alpha fix up unit. The alpha compare unit takes the cycle 1 combined alpha and compares it to a test value. Alpha compare can be enabled in either threshold or dither modes.
Threshold will disable writing if combined_alpha < threshold
Dither will disable writing if combined_alpha < random value
Note
In 2 cycle mode, alpha compare uses the combined alpha from cycle 1. It will also use the next pixel coverage if alpha_cvg_sel is enabled.