Hardware/GX/Transform Unit

From WiiBrew
< Hardware‎ | GX
Jump to navigation Jump to search

The transform unit (XF) is a component of the Wii's GX subsystem. It is responsible for transforming the incoming vertices to screen coordinates.

Writing to XF registers

Writing to XF registers is done by writing values to the FIFO, as shown below:

To write to one XF register:

  • write 0x10 (8-bit)
  • write 0x0000 (16-bit)
  • write the address of the register (16-bit)
  • write the value to write to the register (32-bit)

To write to multiple XF registers:

  • write 0x10 (8-bit)
  • write (n-1) (16-bit)
  • write the address of the first register (16-bit)
  • write the values to write to each register (32-bit each)

Where n is the number of registers to write.

XF registers

XF viewport registers

These registers define the viewport coordinates.

Access R/W
  • 0x101A: This register defines the X0 coordinate of the viewport.

Access R/W
  • 0x101B: This register defines the Y0 coordinate of the viewport.

Access R/W
  • 0x101C: This register defines the depth (far plane - near plane) of the viewport.

Access R/W
  • 0x101D: This register defines the X1 coordinate of the viewport.

Access R/W
  • 0x101E: This register defines the Y1 coordinate of the viewport.

Access R/W
  • 0x101F: This register defines the far plane of the viewport.

The viewport coordinates can be calculated as shown below:

  • GX_XF_VIEWPORT_X0 = viewport_width / 2
  • GX_XF_VIEWPORT_Y0 = (-viewport_height) * 342
  • GX_XF_VIEWPORT_X1 = (viewport_x + (viewport_width / 2)) + 342
  • GX_XF_VIEWPORT_Y1 = (viewport_y + (viewport_height / 2)) + 342
  • GX_XF_VIEWPORT_F = (viewport_farplane * 16777215)
  • GX_XF_VIEWPORT_Z = (viewport_farplane - viewport_nearplane) * 16777215

Note: These formulas are taken from the libogc fucntion GX_SetViewportJitter().