14.4 Multi-Tile Effects

There are eight tile descriptors available in the tile memory of the RDP. These tile descriptors contain information about the type and size of tiles and where these tiles are located in TMEM. In two-cycle mode, texture from two tiles is available for each pixel. Many effects are possible by manipulation of tile descriptors and combining of the textured pixels.

In the g*DPLoadTexture* commands, a simple two-tile system is used for loading and rendering. In this system, the G_TX_LOADTILE is used for loading a tile starting at TMEM address 0 and the tile descriptor G_TX_RENDERTILE is set up for rendering the tile. This is a double-buffering scheme which avoids having to insert tile sync commands in the load macro. Notice that since each tile is loaded at TMEM address 0 and the G_TX_RENDERTILE is always used for rendering, we cannot use these macro for loading multiple tiles into TMEM.

In order to allow the user to manage TMEM for multi-tile effects, the load macros g*DPLoadMultiTile and g*DPLoadMultiBlock were created. These macros allow the user to specify the TMEM address of the tile and the tile descriptor number to use when rendering this tile.

UP


14.4.1 Simple Morph

One simple use of two tiles is to linearly interpolate, using a parameter to indicate the blend amount, between the tiles. A register value in the color combiner, such as primitive alpha, can be used as the "blender" to blend between the two textures as shown in Example 14-22.

Example 14-22 Interpolate Between Two Tiles
#define MY_MORPH TEXEL1,TEXEL0,PRIMITIVE_ALPHA,TEXEL0,
        TEXEL1,TEXEL0,PRIMITIVE,TEXEL0
gsDPSetCycleType(G_CYC_2CYCLE),
gsDPSetTextureLOD(G_TL_TILE),
gsDPSetPrimColor(0,0,0,0,0,128),                /* 0.5 blend */
gsDPSetCombineMode(MY_MORPH,G_CC_PASS2),
gsDPLoadMultiTile(face0,
        0,                          /* TMEM address in 64-bit words */
        G_TX_RENDERTILE,            /* tile */
        G_IM_FMT_RGBA,G_IM_SIZ_16b,
        32,32,
        0,0,31,31,
        0,
        G_TX_NOMIRROR,G_TX_NOMIRROR,
        G_TX_NOMASK,G_TX_NOMASK,
        G_TX_NOLOD,G_TX_NOLOD),
gsDPLoadMultiTile(face1,
        256,                        /* TMEM address in 64-bit words */
        G_TX_RENDERTILE+1,          /* tile */
        G_IM_FMT_RGBA,G_IM_SIZ_16b,
        32,32,
        0,0,31,31,
        0,
        G_TX_NOMIRROR,G_TX_NOMIRROR,
        G_TX_NOMASK,G_TX_NOMASK,
        G_TX_NOLOD,G_TX_NOLOD),
gsSPTextureRectangle(glistp++,
        50<<2,50<<2,82<<2,82<<2,
        G_TX_RENDERTILE,
        0,0,
        1<<10,1<<10);
      

By making the primitive alpha an animation variable, a simple "morphing" effect can be achieved.

UP


14.4.2 Smoothing Flip-Book Animations

Often sprite animations are a sequence of key frames which are selected at the appropriate time by some animation variable. The linear interpolation between two images as described in "Simple Morphing" above can be used to smoothly transit between two key frames. Imagine a series of n images in an animation selected using an animation variable frame. The integer part of frame is called frame_I and the fractional part is called frame_f. An algorithm for smoothing the sequence is described in Example 14-23.

Example 14-23 Smoothing an Animation Sequence
  1. Load tiles frame_I and frame_I+1 into TMEM
  2. Set primitive alpha = 256 * frame_f
  3. Render the rectangle using MY_MORPH combiner mode

The frames do not necessarily have to be related in time. For example, you could interpolate between different flame images that are randomly selected to create a fire effect.

UP


14.4.3 Shrinking Sprites

In the previous discussion of scaling in Section 14.1.2 "Bilinear Filtering", we only discussed scaling a sprite to a larger size since scaling it smaller would result in aliasing effects. It is possible to effectively shrink an image by interpolating between two tiles, one of which is a half the size of the other tile. This is shown in Figure 14.4.1. Prim_lod_frac is a register in the color combiner that can be used to indicate the fractional distance between the two "LOD" of the sprite.

Figure 14-15 Shrinking a Sprite
[Figure 14-15]

One of the tile descriptor parameters is the shift (see Section 13.4.8 "Shift S,T") that describes how many places to bitwise shift the tile coordinates for the primitive. This implies that one tile's size is related to the other's by some integer shift, but the tiles don't necessarily have to be power of two sizes. Example 14-24 shows the code to create a sprite that is 0.75 the size of the larger image. The user must scale the size of the rectangle primitive by the desired amount as well.

Example 14-24 Shrinking a Sprite
#define MY_LOD TEXEL1,TEXEL0,PRIM_LOD_FRAC,TEXEL0,
        TEXEL1,TEXEL0,PRIM_LOD_FRAC,TEXEL0
gsDPSetCycleType(G_CYC_2CYCLE),
gsDPSetTextureLOD(G_TL_TILE),
gsDPSetPrimColor(0,128,0,0,0,0),        /* 0.5 lod_frac */ 
gsDPSetCombineMode(MY_LOD,G_CC_PASS2),
gsDPLoadMultiTile(face0,
        0,                          /* TMEM address in 64-bit words */
        G_TX_RENDERTILE,            /* tile */
        G_IM_FMT_RGBA,G_IM_SIZ_16b,
        32,32,
        0,0,31,31,
        0,
        G_TX_NOMIRROR,G_TX_NOMIRROR,
        G_TX_NOMASK,G_TX_NOMASK,
        G_TX_NOLOD,G_TX_NOLOD),
gsDPLoadMultiTile(face1,
        256,                        /* TMEM address in 64-bit words */
        G_TX_RENDERTILE+1,          /* tile */
        G_IM_FMT_RGBA,G_IM_SIZ_16b,
        16,16,
        0,0,15,15,
        0,
        G_TX_NOMIRROR,G_TX_NOMIRROR,
        G_TX_NOMASK,G_TX_NOMASK,
        G_TX_NOLOD,G_TX_NOLOD),
gsSPTextureRectangle(glistp++,
        50<<2,50<<2,82<<2,82<<2,
        G_TX_RENDERTILE,
        8<<5,8<<5,
        1<<10,1<<10);
      

UP


14.4.4 Texture Decals

We can use the alpha of one tile to select between the texel color of two different tiles to create a texture decal. Figure 14-16 shows an example of a flag created using texture decals. The insignia of the flag has transparency around it's edges. After performing mirror and wrap once, the texture is given a clamp. In the color combiner, the texture alpha is used to interpolate between the flag stripes and the insignia. Where the alpha is zero, the stripes will show, where the alpha is one, the insignia will show.

Figure 14-16 Texture Decals
[Figure 14-16]

UP


14.4.5 Interference Effects

Multiplying two textures together, especially while sliding the textures relative to each other can create interference patterns. For example, a horizontal stripe pattern multiplied by a vertical stripe pattern creates a set of bright spots at the intersection of the points. If the stripes are slid relative to each other, the points will move also. Multiplying can also be used to modulate one image with another. For example, Figure 14-17 shows a complex wave resulting from the modulation of two simple waves.

Figure14-17 Modulation
[Figure 14-17]

UP