Difference between revisions of "Wii Graphics Code/Blitting Processor"

From Custom Mario Kart
Jump to navigation Jump to search
(WIP)
 
(WIP)
Line 52: Line 52:
  
 
The address of the command determines which column of which matrix is set. Addresses 0x06, 0x07 and 0x08 are used for columns one, two and three respectively of matrix 0, addresses 0x09, 0x0A and 0x0B are used for matrix 1 and 0x0C, 0x0D and 0x0E for matrix 2.
 
The address of the command determines which column of which matrix is set. Addresses 0x06, 0x07 and 0x08 are used for columns one, two and three respectively of matrix 0, addresses 0x09, 0x0A and 0x0B are used for matrix 1 and 0x0C, 0x0D and 0x0E for matrix 2.
 +
 +
=== Indirect texture matrix ===
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x14 || 4 || S Scale stage 0
 +
|-
 +
| 0x10 || 4 || T Scale stage 0
 +
|-
 +
| 0x0C || 4 || S Scale stage 1
 +
|-
 +
| 0x08 || 4 || T Scale stage 1
 +
|}
 +
 +
Sets the scale of the indirect texture map for each stage. Address 0x25 sets the scale for stages 0 and 1, 0x26 sets the scale for stages 2 and 3. The coordinates are bitwise shifted right by the scale value, which means that actual scale factor is a negative power of two.
 +
 +
=== Z mode ===
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x17 || 1 || Enable depth test
 +
|-
 +
| 0x14 || 3 || Compare operation
 +
{| class="wikitable"
 +
! Value !! Description
 +
|-
 +
| 0 || Never
 +
|-
 +
| 1 || Less than
 +
|-
 +
| 2 || Equal to
 +
|-
 +
| 3 || Less or equal
 +
|-
 +
| 4 || Greater than
 +
|-
 +
| 5 || Not equal to
 +
|-
 +
| 6 || Greater or equal
 +
|-
 +
| 7 || Always
 +
|}
 +
|-
 +
| 0x13 || 1 || Enable depth update
 +
|}
 +
 +
Z-buffering settings. Determines which object should be drawn in front.
 +
 +
== Shader operations ==
  
 
=== Indirect texture stage ===
 
=== Indirect texture stage ===
Line 123: Line 172:
 
|}
 
|}
  
Each address in range 0x10 - 0x1F contains an indirect texture TEV stage. Indirect textures are used to generate a new texture mapping grid that is altered by the provided texture and its mapping. This technique is mostly used to generate bump or normal maps on materials, which makes faces seem to have more detail than they really have. The provided matrix is multiplied with the green and blue color values of the indirect texture to shift the texture mapping.
+
Each address in range 0x10 - 0x1F contains an indirect texture TEV stage. Indirect textures are used to generate a new texture mapping grid that is altered by the provided texture and its mapping. This technique is mostly used to generate bump or normal maps on materials, which makes faces seem to have more detail than they really have. The provided matrix is multiplied with the green and blue color values of the indirect texture to shift the texture mapping. An indirect texture stage only affects the current TEV stage, no other TEV stages are affected directly.
 +
 
 +
=== Indirect texture references ===
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x15 || 3 || Stage 0 texture
 +
|-
 +
| 0x12 || 3 || Stage 0 texture coords
 +
|-
 +
| 0x0F || 3 || Stage 1 texture
 +
|-
 +
| 0x0C || 3 || Stage 1 texture coords
 +
|-
 +
| 0x09 || 3 || Stage 2 texture
 +
|-
 +
| 0x06 || 3 || Stage 2 texture coords
 +
|-
 +
| 0x03 || 3 || Stage 3 texture
 +
|-
 +
| 0x00 || 3 || Stage 3 texture coords
 +
|}
 +
All texture maps and coordiates for the four indirect texture stages are set at this address. The texture ID is a [[MDL0_(File_Format)#Layers|material layer]] index which references a texture by name. So if the provided material has layers for TexA, TexB and TexC, a value of 2 will load TexB. The texture coords value references one of the coordinates set in the [[MDL0_(File_Format)#Section_10_-_Objects_.28polygons.29|object section]]. All references at this address are then used by one or more indirect texture stages for further calculations, the stage ID value is used as index in this table.
 +
 
 +
=== Texture references ===
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x0E || 10 || Stage 0 data
 +
|-
 +
| 0x02 || 10 || Stage 1 data
 +
|}
 +
 
 +
The 10-bit data blocks have the following layout:
 +
 
 +
{| class="wikitable"
 +
! Offset !! Size !! Description
 +
|-
 +
| 0x08 || 3 || Stage texture map
 +
|-
 +
| 0x04 || 3 || Stage texture coords
 +
|-
 +
| 0x03 || 1 || Stage texture enabled
 +
|-
 +
| 0x00 || 3 || Stage color channel
 +
{| class="wikitable"
 +
! Value !! Description
 +
|-
 +
| 0 || Light channel 0
 +
|-
 +
| 1 || Light channel 1
 +
|-
 +
| 5 || Bump alpha
 +
|-
 +
| 6 || Normalized bump alpha
 +
|}
 +
Other values disable the color channel for this stage.
 +
|-
 +
|}
 +
 
 +
Sets the texture map, texture coordinate and color channel for each TEV stage. At each address the texture references for two stages are set: 0x28 sets stage 0 and stage 1, 0x29 sets stage 2 and stage 3, etc. In total there can be eight stages. Similarly to the indirect texture stage, the texture map is a material layer index and the texture coords are a reference to one of the uv maps set in the object section. Offset 0x03 of the texture data block is used to enable or disable the texture drawing. The stage color channel sets the channel that will be used as raster color. Light channel 0 is often used as vertex color. The bump alpha is the value set by offset 0x0F at the indirect texture stage address, this value can be used to add shadow detail to faces whereas indirect texture maps on their own can only affect texture coordinates.

Revision as of 11:37, 13 September 2019

The blitting processor of the Wii's Hollywood GPU is responsible for applying materials to polygons that will be drawn. In the case of MDL0 files, this processor is mostly used for shader operations. Those operations control the texture map and coordinates to use, the color channel to use and how they are all blended together. MDL0 files access this processor directly by using Wii Graphics Code, whereas many other operations are hardcoded in the game code.

Register overview

The blitting processor has 82 known variables that are used for a large variety of tasks. The variables that are accessed by materials and shaders inside MDL0 files are as listed below:

Address Name
0x06 - 0x0E Three 2x3 indirect texture matrices
0x10 - 0x1F Indirect texture stages
0x25, 0x26 Indirect texture scale
0x27 Indirect texture references
0x28 - 0x2F Texture references
0x40 Z mode
0x41 Alpha blend mode
0x42 Constant alpha
0xC0 - 0xCE Color blending per TEV stage
0xC1 - 0xCF Alpha blending per TEV stage
0xE0 - 0xE7 Shader colors
0xF6 - 0xFD Color table selection per stage
0xFE Mask for next load operation

Material operations

Each material has a number of load calls to set variables used during blending. Variables in the blitting processor are used to control indirect texture matrices, scale and references, texture references, z mode, alpha blend mode and constant alpha. Each material also sets 3 hardcoded colors and 4 constant colors that may be used by the TEV stages. What each variable is used for is explained in the following sections. All tables are ordered from LSB to MSB.

Indirect texture matrix

Offset Size Description
0x0D 11 First row value
0x02 11 Second row value
0x00 2 Scale bits

At address 0x06 in the memory three 2x3 indirect texture matrices are stored together with a scale factor for each of them. To set a matrix three load operations are peformed, one for each column. Each load operation also sets two bits of the six bit scale factor is set; the first column sets the least significant bits, the third column sets the most significant bits. This matrix may be used to transform the texture coordinates of an indirect texture in an indirect texture stage.

The address of the command determines which column of which matrix is set. Addresses 0x06, 0x07 and 0x08 are used for columns one, two and three respectively of matrix 0, addresses 0x09, 0x0A and 0x0B are used for matrix 1 and 0x0C, 0x0D and 0x0E for matrix 2.

Indirect texture matrix

Offset Size Description
0x14 4 S Scale stage 0
0x10 4 T Scale stage 0
0x0C 4 S Scale stage 1
0x08 4 T Scale stage 1

Sets the scale of the indirect texture map for each stage. Address 0x25 sets the scale for stages 0 and 1, 0x26 sets the scale for stages 2 and 3. The coordinates are bitwise shifted right by the scale value, which means that actual scale factor is a negative power of two.

Z mode

Offset Size Description
0x17 1 Enable depth test
0x14 3 Compare operation
Value Description
0 Never
1 Less than
2 Equal to
3 Less or equal
4 Greater than
5 Not equal to
6 Greater or equal
7 Always
0x13 1 Enable depth update

Z-buffering settings. Determines which object should be drawn in front.

Shader operations

Indirect texture stage

Offset Size Description
0x16 2 Indirect tex stage ID
0x14 2 Indirect texture coordinate format
Value Description
0 8-bit coordinates
1 5-bit coordinates
2 4-bit coordinates
3 3-bit coordinates
0x11 3 S (LSB), T and U (MSB) bias
0x0F 2 Bump alpha axis
Value Description
0 Disabled
1 S
2 T
3 U
0x0D 2 Matrix multiplication method
Value Description
0 Normal multiplication
1 Multiply with S value
2 Multiply with T value
3 Multiply with U value
0x0B 2 Indirect texture matrix
Value Description
0 No matrix
1 Matrix 0
2 Matrix 1
3 Matrix 2
0x08 3 S wrapping factor
0x05 3 T wrapping factor
0x04 1 Use unmodified LOD
0x03 1 Add previous TEV stage tex coordinates

Each address in range 0x10 - 0x1F contains an indirect texture TEV stage. Indirect textures are used to generate a new texture mapping grid that is altered by the provided texture and its mapping. This technique is mostly used to generate bump or normal maps on materials, which makes faces seem to have more detail than they really have. The provided matrix is multiplied with the green and blue color values of the indirect texture to shift the texture mapping. An indirect texture stage only affects the current TEV stage, no other TEV stages are affected directly.

Indirect texture references

Offset Size Description
0x15 3 Stage 0 texture
0x12 3 Stage 0 texture coords
0x0F 3 Stage 1 texture
0x0C 3 Stage 1 texture coords
0x09 3 Stage 2 texture
0x06 3 Stage 2 texture coords
0x03 3 Stage 3 texture
0x00 3 Stage 3 texture coords

All texture maps and coordiates for the four indirect texture stages are set at this address. The texture ID is a material layer index which references a texture by name. So if the provided material has layers for TexA, TexB and TexC, a value of 2 will load TexB. The texture coords value references one of the coordinates set in the object section. All references at this address are then used by one or more indirect texture stages for further calculations, the stage ID value is used as index in this table.

Texture references

Offset Size Description
0x0E 10 Stage 0 data
0x02 10 Stage 1 data

The 10-bit data blocks have the following layout:

Offset Size Description
0x08 3 Stage texture map
0x04 3 Stage texture coords
0x03 1 Stage texture enabled
0x00 3 Stage color channel
Value Description
0 Light channel 0
1 Light channel 1
5 Bump alpha
6 Normalized bump alpha

Other values disable the color channel for this stage.

Sets the texture map, texture coordinate and color channel for each TEV stage. At each address the texture references for two stages are set: 0x28 sets stage 0 and stage 1, 0x29 sets stage 2 and stage 3, etc. In total there can be eight stages. Similarly to the indirect texture stage, the texture map is a material layer index and the texture coords are a reference to one of the uv maps set in the object section. Offset 0x03 of the texture data block is used to enable or disable the texture drawing. The stage color channel sets the channel that will be used as raster color. Light channel 0 is often used as vertex color. The bump alpha is the value set by offset 0x0F at the indirect texture stage address, this value can be used to add shadow detail to faces whereas indirect texture maps on their own can only affect texture coordinates.