4.3 Combine Mode

Up until now, we have been using combine mode without giving a very detailed explanation. All we have actually been doing is specifying the source color and source alpha for the coefficients a, b, c, d.

There is a macro defined in <gbi.h> called gDPSetCombineLERP. The contents of this macro are shown below:

  #define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0,      \
                a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1)                       \
  {                                                                       \
          Gfx *_g = (Gfx *)(pkt);                                         \
                                                                          \
          _g->words.w0 =  _SHIFTL(G_SETCOMBINE, 24, 8) |                  \
                          _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0,     \
                                          G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \
                                  GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1),    \
                                  0, 24);                                 \
          _g->words.w1 =  (unsigned int)(GCCc0w1(G_CCMUX_##b0,            \
                                                 G_CCMUX_##d0,            \
                                                 G_ACMUX_##Ab0,           \
                                                 G_ACMUX_##Ad0) |         \
                                         GCCc1w1(G_CCMUX_##b1,            \
                                                 G_ACMUX_##Aa1,           \
                                                 G_ACMUX_##Ac1,           \
                                                 G_CCMUX_##d1,            \
                                                 G_ACMUX_##Ab1,           \
                                                 G_ACMUX_##Ad1));         \
  }

The gDPSetCombineLERP macro has many arguments, but all of the arguments besides pkt (the argument for the display list pointer) are there to specify source color and source alpha for the coefficients.

a0, b0, c0 and d0 are the cycle-1 source color & alpha, and they are used to perform the following calculation:

Output color = (a0 - b0) * c0 + d0

In the same way, Aa0, Ab0, Ac0 and Ad0 are the cycle-1 source alpha, and they are used to calculate the alpha value with the following equation:

Output alpha = (Aa0 - Ab0) * Ac0 + Ad0

a1, b1, c1, d1, Aa1, Ab1, Ac1and Ad1 are the cycle-2 source color & alpha. In one-cycle mode, the same combine mode must be set in both cycles.