CC: Color Combiner

The color combiner (CC) combines texels from TX and stepped RGBA pixel values from RS. The CC is the ultimate paint mixer. It can take two color values from many sources and linearly interpolate between them. The CC basically performs this equation:

newcolor = (A - B) x C + D

Here, A, B, C, and D can come from many different sources. Notice that if D=B, then this is a simple linear interpolator.

Figure 12.6.1  Color Combiner State and Input/Output

Most of CC programming involves setting the desired sources for (A,B,C,D) of the equation above. There are also programmable color registers within CC that can be used to source (A,B,C,D) input of the interpolator.

Color and Alpha Combiner Inputs Sources
The following picture describes all possible input selection of a general purpose linear interpolator for RGB and Alpha color combination. The input in the shaded boxes are CC internal state that you can set. Most are programmable color registers.

Figure 12.6.2  RGB Color Combiner Input Selection

Figure 12.6.3  Alpha Combiner Input Selection

CC Internal Color Registers
There are two internal color registers in the CC: primitive and environment color. The primitive color can be used to set a constant polygon face color. The environment color can be used to represent the ambient color of the environment. Both can be used as source for linear interpolation. The names “primitive” and “environment” are purely arbitrary; you can use them for any purpose you wish.

Table 1  gsSetPrimColor(minlevel, frac, r, g, b, a), gsDPSetEnvColor(r, g, b, a)
Parameter Value
minlevel minimum LOD level
frac LOD fraction for blending two texture tiles
r, g, b, a color

One-Cycle Mode
Many of the typical RGB and alpha input selections are predefined in Section 12.7, Table 1, "One-Cycle Mode gsDPSetRenderMode(mode1, mode2)." In 1 cycle mode both mode1 and mode2 should be the same. Please see the man page for gDPSetCombineMode for a description of each mode setting.

Table 2  One-Cycle Mode Using gsDPSetCombineMode(mode1, mode2)
Parameter Value
mode1/2 G_CC_PRIMITIVE
G_CC_SHADE
G_CC_ADDRGB
G_CC_ADDRGBDECALA
G_CC_SHADEDECALA
mode1/2 Decal textures in RGB, RGBA formats
G_CC_DECALRGB
G_CC_DECALRGBA
mode1/2 Modulate texture in I, IA, RGB, RGBA formats
G_CC_MODULATEI
G_CC_MODULATEIA
G_CC_MODULATEIDECALA
G_CC_MODULATERGB
G_CC_MODULATERGBA
G_CC_MODULATERGBDECALA
G_CC_MODULATEI_PRIM
G_CC_MODULATEIA_PRIM
G_CC_MODULATEIDECALA_PRIM
G_CC_MODULATERGB_PRIM
G_CC_MODULATERGBA_PRIM
G_CC_MODULATERGBDECALA_PRIM
mode1/2 Blend texture in I, IA, RGB, RGBA formats
G_CC_BLENDI
G_CC_BLENDIA
G_CC_BLENDIDECALA
G_CC_BLENDRGBA
G_CC_BLENDRGBDECALA
mode1/2 Reflection and specular hilite in RGB, RGBA formats.
G_CC_REFLECTRGB
G_CC_REFLECTRGBDECALA
G_CC_HILITERGB
G_CC_HILITERGBA
G_CC_HILITERGBDECALA

Note: In one-cycle mode, mode1 and mode2 should be the same value.

Two-Cycle Mode
Color Combiner (CC) can perform two linear interpolation arithmetic computations in two-cycle pipeline mode. Typically, the second cycle is used to perform texture and shading color modulation (in other words, all those modes you saw in one-cycle mode). However, the first cycle can be used for another linear interpolation calculation; for example, LOD interpolation between the two bilinear filtered texels from two mipmap tiles.

Table 3  Two-Cycle Mode Using gsDPSetCombineMode(mode1, mode2)
Parameter Value
mode1 G_CC_TRILERP
G_CC_INTERFERENCE
mode2 G_CC_PASS2
Most of the Decal, Modulate, Blend and Reflection/Hilite texture modes mentioned in one cycle mode. However, since they are values for mode2 parameter, the names must all end with 2. e.g. G_CC_MODULATEI2.

Custom Modes
Color Combiner (CC) can be programmed more specifically when you design your own color combine modes. To define a new mode use the format:

#define G_CC_MYNEWMODE a,b,c,d, A,B,C,D

Where the color output will be (a-b)*c+d and the alpha output will be (A-B)*C+D. The values you can use for each of a, b, c, d, A, B, C, and D are:

COMBINEDcombined output from cycle 1 mode
TEXEL0texture map output
TEXEL1texture map output from tile+1
PRIMITIVEPrimColor
SHADEShade color
ENVIRONMENTEnvironment color
CENTERchroma key center value
SCALEkey scale value
COMBINED_ALPHAcombined alpha output from cycle 1
TEXEL0_ALPHAtexture map alpha
TEXEL1_ALPHAtexture map alpha from tile+1
PRIMITIVE_ALPHAPrimColor Alpha
SHADE_ALPHAShade alpha
ENV_ALPHAEnvironment color alpha
LOD_FRACTIONLOD fraction
PRIM_LOD_FRACPrim LOD fraction
NOISEnoise (random)
K4color convert constant K4
K5color convert constant k5
11.0
00.0

Then you can use your new mode just like a regular mode:

gDPSetCombineMode(G_CC_MYNEWMODE, G_CC_MYNEWMODE);

Chroma Key
The color combiner can be used to perform “chroma keying”, which is a process where areas of a certain color are taken out and replaced with a texture. This is a similar effect to “blue screen photography”, or as seen on the television news weather maps.

The theory is quite simple; a key color is provided, and all pixels of this color are replaced by the texel color requested. The key color is actually specified as a center and width, allowing soft-edge chroma keying (for blended colors):

Chroma Key Equations

KeyR = clamp(0, (-abs((R - RCen) * RScl) + RWd), 255)
KeyG = clamp(0, (-abs((G - GCen) * GScl) + GWd), 255)
KeyB = clamp(0, (-abs((B - BCen) * BScl) + BWd), 255)
KeyA = min(KeyR, KeyG, KeyB)

The center, scale, and width parameters have the following meanings:

In two-cycle mode, the keying operation must be specified in the second cycle (key alpha is not available as a combine operand). The combine mode G_CC_CHROMA_KEY2 is defined for this purpose.

The command:

gsDPSetCombineKey(G_CK_KEY);

enables chroma keying.

The commands:

gsDPSetKeyR(cR, sR, wR);	
gsDPSetKeyGB(cG, sG, wG, cB, sB, wB);

allow you to set the parameters for each channel.

Copyright © 1999
Nintendo of America Inc. All Rights Reserved
Nintendo and N64 are registered trademarks of Nintendo
Last Updated January, 1999