Materials (Metroid Prime): Difference between revisions

imported>Jackoalan
(Runaway zeros)
>Aruki
Line 102: Line 102:
| long
| long
| 1
| 1
| '''Color channel flag count''' (CC)
| '''Color channel count''' (CC)
|-
|-
| long
| long
| CC
| CC
| '''Color channel flags'''
| '''Color channel flags''' ''(note: only one flag value, but you must advance 4*CC bytes instead of 4 for some reason)''
|-
|-
| long
| long
Line 292: Line 292:
==== Color Channels ====
==== Color Channels ====


There's an odd quirk with how these values work; although there's a count value listed, the game will only actually read the first value listed and then skip the rest. There's no reason to ever have more than one flag value. Aside from that, how this works is unknown and needs research.
The color channels data consists of a count value indicating the number of color channels, and then one set of flags that controls the COLOR0 channel. The flags correspond to arguments passed to [http://libogc.devkitpro.org/gx_8h.html#a87d79cf2375217d06237c887ba027cc2 GX_SetChanCtrl()]. These are the settings:
 
{| class="wikitable"
! Bits
! Hex
! Description
|-
| 0
| 0x1
| '''Enable lighting''' (enable)
|-
| 1
| 0x2
| '''Ambient color source''' (ambsrc)
|-
| 2
| 0x4
| '''Material color source''' (matsrc)
|-
| 3-10
| 0x7F8
| '''Light mask'''; always 0, filled in at runtime ([http://libogc.devkitpro.org/group__lightid.html litmask])
|-
| 11-12
| 0x1800
| '''Diffuse function''' ([http://libogc.devkitpro.org/group__difffn.html diff_fn])
|-
| 13-14
| 0x6000
| '''Attenuation function''' ([http://libogc.devkitpro.org/group__attenfunc.html attn_fn])
|}
 
There's only one set of flags, which operates on COLOR0. COLOR1 is reserved for dynamic shadowmaps, and its settings can't be modified. Here's how the other color channel settings work.
 
If shadowmaps are enabled:
 
* No processing will be done if the count value is 0. Otherwise, the count value is ignored; the game will always set up both color channels.
* COLOR1A1's ambient color is black, and its material color is white.
* COLOR1 will use the diffuse function GX_DF_CLAMP and the attenuation function GX_AF_SPOT. It will have lighting disabled entirely if there are no lights in range.
* COLOR0 will use the flags from the material, with the light mask merged in. It will also have lighting disabled if there are no lights in range.
* If there are no lights in range, COLOR0A0 will have its material color set to white. Otherwise, its material color will be set to match its ambient color.
 
If shadowmaps are disabled:
 
* COLOR1 is disabled if the count value is not 2. If it is 2, then its ambient color will be black and its material color will be white.
* COLOR0 is disabled if the count value is 0. Otherwise, it's set up the same way as with shadowmaps.
 
Finally, an important note is that the formatting of the color channel info is bugged. There is always a count value and a single set of flags; 8 bytes total. However, for some reason the game is expecting one set of flags per color channel. To reach the TEV stages, you need to advance (4 * count) bytes past the count value, rather than 4. A likely explanation is that there was one set of flags per channel earlier in development, and the material loading code wasn't fully updated when this was changed; it's not normally an issue because the count is always 1 in every file the game uses, but beware for experimentation/custom materials.


=== TEV Stages ===
=== TEV Stages ===
Anonymous user