10.4 Transparency Effects in Copy Mode

As we explained previously, rendering in Copy mode is fast, but you skip over all the processing that goes on in the Combiner and Blender. Thus, you cannot make use of functions like Z buffering, which is processed with the Blender. There is one exception, however, and that is the alpha compare function, which can be used even in Copy mode.

Next we will change the gfx10.c sample program to render in copy mode, and then use the alpha compare function to get a transparency effect. When you change line 40 from undef to define, the small texture rectangle is rendered in Copy mode.

List 10-6

  /* Set the cycle type to Copy mode  */
  gDPSetCycleType(glistp++, G_CYC_COPY);
  /* Specify 0 for the combine mode coefficients  */
  gDPSetCombineLERP(glistp++, 0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0);
  /* Set rendering mode to G_RM_NOOP, G_RM_NOOP2 (Blender does nothing)  */
  gDPSetRenderMode(glistp++, G_RM_NOOP, G_RM_NOOP2);
  /*
   *  Set the blend color alpha to 1 in order to perform an
   *  alpha compare and remove the background.  When this is done,
   *  places with an alpha of 0 become transparent pixels.  This also
   *  works in G_RM_NOOP mode where Blender processes are skipped.
   */
  gDPSetBlendColor(glistp++, 0, 0, 0, 1);
  gDPSetAlphaCompare(glistp++, G_AC_THRESHOLD);

  /* (Parts have been omitted) */

  /* Draw the texture rectangle  */
  gSPTextureRectangle(glistp++,
                      posx << 2, posy << 2,
                     (posx + RECT_WD - 1) << 2, (posy + RECT_HT - 1) << 2,
                      G_TX_RENDERTILE,
                      0 << 5, 0 << 5,
                      4 << 10, 1 << 10);
  gDPPipeSync(glistp++);
  /* Set alpha compare back to OFF  */
  gDPSetAlphaCompare(glistp++, G_AC_NONE);

By looking at the above source you should be able to deduce what is happening, but a simple explanation of the steps in order follows.