Alpha Blending

Let's start with the BLDCNT register. This register controls the special effects that will be applied to the video.

BLDCNT modes

There are 4 modes you can select from (bits 6..7).

Mode 0: Disabled

This mode is the disabled mode. No effects will be applied to the output.

Mode 1: Alpha Blending

In this mode, the elements that are selected in the targets are alpha blended with each other. There are a few limitations that must be followed. First of all, only 2 elements for each pixel can actually be blended together. The top-most pixel will be blended with the second top-most pixel. The top-most element(s) must be selected in the first target. While the elements below it must be selected in the second target.

To blend the pixels, the hardware multiplies the RGB components by a value specified through the BLDALPHA register. Each target has a coefficient to be multiplied by.

The coefficient values are 5 bits, but the value ranges from 0->16. Values 17..31 are read as 16.

The first target is multiplied by coefficient A and the second by coefficient B. The forumla is something like this: Pixel = MAX( 31, (1st * A + 2nd * B) / 16 ).

We will use this mode to blend the gradient against the backdrop.

Modes 2 & 3: Fade Image

These modes only use the first elements selected in the first target. Mode 2 will increase the brightness of the image, and mode 3 will decrease the brightness of the image. The brightness/darkness coefficient is specified in the BLDY register. The BLDY coefficient ranges from 0->16. The output formula may look like this (mode 2): Pixel = A + ((31-A) * Y) / 16, and mode 3: Pixel = A - (A * Y) / 16.

Blending the Image

Okay, now lets try to blend BG1 against the backdrop. Select BG1 in the bits of the first target, and the backdrop in the bits of the second target. Also set the alpha blending mode.

    REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG1 | BLEND_DST_BACKDROP;
    REG_BLDALPHA = (16) + (16<<8);

Source/SRC and Dest/DST are alternate names for the first and second targets. BLDALPHA was set to 100% (16/16) for both coefficients, so this will fully add both elements together. Compile the code and view the output:

Oops, that's a little bright, lets try 50% for the first target.

    REG_BLDALPHA = (8) + (16<<8);

New output:

Heh, that's still a bit bright. You should tweak the coefficient until it looks okay. I settled with 25%:

    REG_BLDALPHA = (4) + (16<<8);

And.. that should look like this:

It still looks a bot wierd, but it'll have to do. :)

Previous: BackgroundsContentsNext: Loading sprites