Difference between revisions of "Wii Graphics Code"
Line 63: | Line 63: | ||
! 00 !! 01 !! 02 !! 03 !! 04 !! 05 !! 06 !! 07 !! 08 !! 09 !! 0a !! 0b !! 0c !! 0d !! 0e !! 0f | ! 00 !! 01 !! 02 !! 03 !! 04 !! 05 !! 06 !! 07 !! 08 !! 09 !! 0a !! 0b !! 0c !! 0d !! 0e !! 0f | ||
|- | |- | ||
− | | PM || TM0 || TM1 || TM2 || TM3 || TM4 || TM5 || TM6 || TM7 || colspan=2 | Pos || colspan=2 | Norm || colspan=2 | | + | | PM || TM0 || TM1 || TM2 || TM3 || TM4 || TM5 || TM6 || TM7 || colspan=2 | Pos || colspan=2 | Norm || colspan=2 | Col0 || Col1 |
|- | |- | ||
! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17 !! 18 !! 19 !! 1a !! 1b !! 1c !! 1d !! 1e !! 1f | ! 10 !! 11 !! 12 !! 13 !! 14 !! 15 !! 16 !! 17 !! 18 !! 19 !! 1a !! 1b !! 1c !! 1d !! 1e !! 1f | ||
Line 130: | Line 130: | ||
The E value for each item is '''Unknown'''. The format value should match the formats values in the headers of the respective groups in the [[MDL0 (File Format)|MDL0 file]]. The divisors should also match these. | The E value for each item is '''Unknown'''. The format value should match the formats values in the headers of the respective groups in the [[MDL0 (File Format)|MDL0 file]]. The divisors should also match these. | ||
|} | |} | ||
+ | |||
=== [0x10] Load XF (Transform Unit) Register === | === [0x10] Load XF (Transform Unit) Register === | ||
The XF (Transform Unit) register set commands are found in both the vertex declarations, and in some material files. They are used in vertex declarations to indicate how many of each item the transform unit will recieve, and in materials to setup texture matricies and post effect matricies. The format for each command is as follows. Measured in bytes. | The XF (Transform Unit) register set commands are found in both the vertex declarations, and in some material files. They are used in vertex declarations to indicate how many of each item the transform unit will recieve, and in materials to setup texture matricies and post effect matricies. The format for each command is as follows. Measured in bytes. |
Latest revision as of 12:24, 15 November 2019
The Wii graphics card uses a system of command code which is transimitted in several ways by BRRES Files. This page is an instruction set listing of the command code. The instruction set is initially being created to just cover codes found in Mario Kart Wii.
Code
There are several types of command code. Graphics code is sent by first sending a byte to indicate which type of command is being used, and then multiple bytes to indicate the command.
Command | Command Length | Description |
---|---|---|
0x00 | 1 | NOP (No Operation) |
0x08 | 6 | Load CP (Command Processor) Register |
0x10 | Varies | Load XF (Transform Unit) Register |
0x20 | 5 | Load Indexed 3x3 Position Matrix |
0x28 | 5 | Load Indexed 3x3 Normal Matrix |
0x30 | 5 | Load Indexed Texture Matrix |
0x38 | 5 | Load Indexed Light Object |
0x40 | Varies | Call Display List |
0x44 | 1 | Unknown |
0x48 | 1 | Invalidate Vertex Cache |
0x61 | 5 | Load BP (Blitting Processor) Register |
0x80 | Varies | Draw Quads |
0x90 | Varies | Draw Triangles |
0x98 | Varies | Draw Triangle Strip |
0xa0 | Varies | Draw Triangle Fan |
0xa8 | Varies | Draw Lines |
0xb0 | Varies | Draw Line Strip |
0xb8 | Varies | Draw Points |
Command length is the total length including the first command byte.
[0x08] Load CP (Command Processor) Register
The command processor commands are found in the vertex declaration section of polygons in MDL0 files. The command processor command is structured as follows.
0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
0x08 | Sub Command | Parameters |
The values for the sub command and it's parameters are listed below. In the table Pos means position; TexN means texture coordinate N; ColN means color N; Norm means normal; TMN means texture coordinate matrix N; and PM means position matrix. Measured in bits with lsb first.
Sub Command | Parameters | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x50 |
The one bit fields indicate whether or not the 8 bit index is present or not. For the 2 bit fields, 00 indicates not present, 01 indicates direct, 10 indicates 8 bit index, 11 indicates 16 bit index. |
Vertex Declaration Setup. Controls how data is encoded into the draw command streams. Indexed data references the relevant group. Direct data indicates the data is embeded in the command rather than indexed. Values are encoded into draw commands in the order they appear here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x60 |
00 indicates not present, 01 indicates direct, 10 indicates 8 bit index, 11 indicates 16 bit index. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x70 |
The E value for each item is Unknown. The format value should match the formats values in the headers of the respective groups in the MDL0 file. The divisors should also match these. The Dequant and NormI3 values are Unknown. |
Vertex Declaration Setup. Controls how data is encoded into the draw command streams. Indicates how the elements are stored either at the indexed location, or directly in the draw command. This must match the values in the groups of the MDL0 file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x80 |
The E value for each item is Unknown. The format value should match the formats values in the headers of the respective groups in the MDL0 file. The divisors should also match these. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x90 |
The E value for each item is Unknown. The format value should match the formats values in the headers of the respective groups in the MDL0 file. The divisors should also match these. |
[0x10] Load XF (Transform Unit) Register
The XF (Transform Unit) register set commands are found in both the vertex declarations, and in some material files. They are used in vertex declarations to indicate how many of each item the transform unit will recieve, and in materials to setup texture matricies and post effect matricies. The format for each command is as follows. Measured in bytes.
0 | 1 | 2 | 3 | 4 |
---|---|---|---|---|
0x10 | Transfer Size | Address |
The address is the XF register to set. The transfer size is the amount of data being sent. This is always 1 less than the actual amount. The amount is measured in 4 byte units. The values follow directly after the command structure. The meanings of XF register addresses are given below. Measured in bits with lsb first.
Address | Parameters | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x1008 |
The counts refer to the amount of each type of item used in the draw commands. |
Transform unit input size. Must match the rest of the vertex declaration in polygons in MDL0 Files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x104N |
Projection is either ST projection or STQ projection. STQ projection allows for perspective correction. Input form is either AB11 or ABC1 and controls perspective as well, in most cases AB11 is used with ST projection and ABC1 with STQ projection. The texture generation type can have the following values: 0 for regular, 1 for emboss mapping and 2 and 3 for two variants of color-based mapping. Source row determines how the texture coordinates are transformed: possible values are: vertex geometry (0), normals (1), colors (2), binormalT (3), binormalB (4) and UV coordinates 1 to 7 (5-12). |
Sets the Nth texture matrix. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0x105N | Unknown | Sets the Nth post effect matrix. |
[0x61] Load BP (Blitting Processor) Register
Main article: Wii Graphics Code/Blitting Processor
The BP (Blitting Processor) register set commands are used by materials and shaders in MDL0 files. They control the look of the textures, by controlling the operation the graphics card performs on each vertex in order to determine its color. Each command has the following structure. Measured in bytes.
0 | 1 | 2 | 3 | 4 | |
---|---|---|---|---|---|
0x61 | Address | Value |
The address is the BP register to set. The meanings of CP register addresses are given below. Measured in bits with lsb first.
Address | Parameters | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x27 |
All values are indices to either a texture map or a texture coordinate of a material. |
Sets the indirect texture sources | ||||||||||||||||||||||||||||||||||||||||||||||||
0x28-0x2f |
TexN E sets whether reading the Nth texture is enabled. N is the value in the table + the instrction's lowest 3 bits multiplied by 4 (e.g. 0x29 tex0 is the 2nd texture). The ras values use a similar index, and represent which value to use in pixel shader calculations for the ras constant. The values are 000: Col0; 001: Col1; 101: AlphaBump; 110: AlphaBump Corrected; 111: 0. |
Controls whether or not texture reading is enabled, and the value for the RAS constants in pixel shader calculations. | ||||||||||||||||||||||||||||||||||||||||||||||||
0x41 |
The values for blend source and destination control the weighting of the current and new pixels during alpha blending. The values for destination are: 000: 0; 001: 1; 010: Source Color; 011: Inverse Soruce Color; 100: Source Alpha; 101: Inverse Source Alpha; 110: Destination Alpha; 111: Inverse Destination Alpha. The values for blend source are the same except it uses destination values for 010 and 011. |
Controls whether or not alpha blending is enabled, and if so how it occurs. | ||||||||||||||||||||||||||||||||||||||||||||||||
0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce |
The command performed on each layer by the graphics card obeys the format: |
Controls how color is blended in each layer of the coloring operation. The number of the command indicates which layer is being controlled, with 0xce being the last layer. These layers also correspond to which texture is read at each stage. | ||||||||||||||||||||||||||||||||||||||||||||||||
0xc1, 0xc3, 0xc5, 0xc7, 0xc9, 0xcb, 0xcd, 0xcf |
The command performed on each layer by the graphics card obeys the format: |
Controls how alpha is blended in each layer of the coloring operation. The number of the command indicates which layer is being controlled, with 0xcf being the last layer. These layers also correspond to which texture is read at each stage. | ||||||||||||||||||||||||||||||||||||||||||||||||
0xf6-0xfd |
Swaps the color channel defined by the table indices with the channel defined in swap N. Swap N has the following values: 00: red, 01: green, 10: blue,11: alpha. The table index is determined by the least significant 3 bits of the address. |
Controls how the swap mode table is accessed when rendering a texture on a polygon. | ||||||||||||||||||||||||||||||||||||||||||||||||
0xe0-0xe8 |
If the LSB of the address is zero, red and alpha are set, otherwise blue and green. This register range maps to two different variables: the constant flag determines if a regular color (0) or a constant color (1) is set. |
This address range is used by materials to set shader colors and shader constant colors. | ||||||||||||||||||||||||||||||||||||||||||||||||
0xfe | This address can be used to limit to which bits of BP registers is actually written to. This mask is reset after the next BP write. |
Draw Commands
The draw commands (0x80, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8) are found in the vertex data section of MDL0 files. The draw commands all obey the same basic format. They have a 16 bit count of the amount of vertices in the command directly after the command byte. The vertex data then follows. The format of this varies, and is set using the 0x08 Command Processor commands. The order of items is the same as the order in the 0x08:0x50 and 0x08:0x60 commands.