Usage
When niff2gfx -h is executed from the command line, the following is displayed.
In N64, the vertex value is described in the Vtx table as a signed 16-bit integer. So depending on the original model data, rounding off can destroy the original form. In this case, please specify the option. The default is set at 20x.
This is convenient when using numerous conversion files in a single compiler environment.
In order to boost the vertex calculation performance in the RCP at conversion time, niff2gfx makes as much of a consecutive transfer of the vertex buffer as possible. As a result, the same vertex information is output many times to the vertex table. At this time, vertex buffers that have already been output are viewed to evaluate whether a continuous part can be shared.
For example, say 10 vertices are to be output as a vertex table. Normally 10 Vtx are simply output, but when -vtxshare 5 is set if, previously, there was a continuous part of 5 of these 10 vertices, then a past vertex buffer is used to issue the vertex transfer instruction (gsSPVertex). Note that at this time the number of vertex transfer instructions increases to 2.
With gspF3DEX the vertex cache size is 32. But it increases to 64 with gspF3DLX.Rej, and 80 with gspF3DLP. When these other microcodes are used, please use this option to increase the vertex cache size for conversions. The default size is 32.
According to the microcode specifications during flat shading,
only one of the three vertices needs to express the normal, but for automatic creation of ST values for reflection mapping, all three vertices need to be normal.
Thus, it is necessary to set
normal to three vertices only when reflection mapping with flat shading. This option affects these settings.
First, the colors used by the image are reduced to 16-bits (RGBA5551). The colors are then sorted in order from the most-used. either the first 256 colors are set in the palette for an 8-bit CI texture or the first 16 colors are set in the palette for a 4-bit CI texture. Since alpha is effective for only 1 bit, it is transparent when the original data is 0, and opaque when the original data is a value other than 0.
If there is no match for a color in the palette, the sum of the difference of squares is calculated for each RGB component and the smallest is selected.
If -noreduct is specified and there are too many colors, the conversion is aborted.
Specification of CC setting when mat_type is MAT_TYPE_NIFF
Resource Usage Rules
The converter analyzes NIFF data and uses a number of RDP registers.
The RDP register's Primitive Color register is allocated to PrimColor, while the Environment Color register is allocated to TriColor, and color changes are assigned to the registers.
Determining Color Combiner Mode
The color combiner mode is determined based on the MAT_SHADE_LIGHT* of mat_shade_type and the following bits of mat_color_type0:
The following bits are not referenced:
Each bit is assigned separately, so there are a variety of modes. These are determined in the following way:
First, the color combiner expression is evaluated with the following formula:
Wch, Xch, Ych, and Zch are virtual color channels, and they are determined by different bits in mat_color_type0.
Ych is determined by MAT_CC_NIFF_VTX, _TEX0_ALPHA, _PRIM_ALPHA, _TRI_ALPHA, and _VTX_ALPHA.
NIFF to N64 GBI format convertor. version 1.3.6
supported format revisions: NIFF 1.0
usage: niff2gfx [option] infile outfile
infile ... NIFF format file.
outfile ... N64 Displaylist C source file.
option:
-q quiet mode.
-verbose verbose mode.
-header fname, -d fname
set output header filename.
-label str set label string.(label string = str)
-scale fval set convert scale.(scale = (float)fval)
-niffinfo fname NIFF information onto file fname.
-nocomdef common define,typedef block no output.
-regmask val prevent RDP register assignment.
-vtxshare val vertex share on set minimum match length.
-vtxcache val vertex cache size(default 32).
-vtxload val vertex cache load limit(default 32).
-strictflat flat normal output to 3 vertices at all times.
-noalignpad prevent alignment of 8-byte order no padding.
-outobj name output object by name.(default: all objects)
-outmask val prevent output dataclass assignment.
-nogeomclr geometry mode no clear.
-preview val preview type value.(default: 0x1c)
-binary, -b output gfx in binary file.
-rotorder val default rotation order.(default: 0x010203)
-vtxseg val Vtx segment number.(default: 5)
-imgseg val image data segment number.(default: 6)
-tlutseg val TLUT data segment number.(default: 7)
-nomodify disable modify vertex.
-strictcidx CIDX pixel/bits follow 'tex_type'.
-noreduct CIDX no color reduction.
-nullanim output null animation data.
-?, -h help
fname indirect option file.
-header fname set output header filename.
-label str set label string.(label string = str)
-scale fval set convert scale.(svale = (float)fval)
-niffinfo fname NIFF infomation on to file fname.
-nocomdef common define,typedef block no output.
-regmask val prevent RDP register assignment.
bit0 ... Suppresses CycleMode setting
bit1 ... Suppresses RenderMode setting
bit2 ... Suppresses ColorCombinerMode setting
bit3 ... Suppresses settings for Primitive color register
bit4 ... Suppresses settings for Environment color register
bit5 ... Suppresses register settings coming to the object header
-vtxshare val vertex shar on set minimum match length.
-vtxcache val vertex cache size(default 32).
-vtxload val set vertex cache load limit(default 32).
-strictflat flat normal output to 3 vertices at all times.
-noalignpad prevent alignment of 8-byte order no padding.
-outobj name output object by name.(default: all objects)
-outmask val prevent output dataclass assignment.
bit0(0x001) ... Header
When each bit is 1, output of that bit's data class is prohibited. If bit4 is 1, then bit5 and bit6 are also always 1.
bit1(0x002) ... TLUT
bit2(0x004) ... Bitmap pattern
bit3(0x008) ... Data related to deforming
bit4(0x010) ... Shape
bit5(0x020) ... Vertex list (Vtx structure array)
bit6(0x040) ... Display list (Gfx structure array)
bit7(0x080) ... Object structure
bit8(0x100) ... Animation structure
bit9(0x200) ... Scene structure
-nogeomclr geometry mode no clear.
-binary, -b output gfx in binary file.
-preview val preview type value.(default: 0)
-rotorder val default rotation order.(default: 0x010203)
-vtxseg val Vtx segment number.(default: 5)
-imgseg val image data segment number.(default: 6)
-tlutseg val TLUT data segment number.(default: 7)
-nomodify disable modify vertex.
-strictcidx CIDX pixel/bits follow 'tex_type'.
-noreduct CIDX no color reduction.
On conversion, if the image specified as an 8-bit color
index texture is more than 256 colors, and the image specified as a 4-bit color index texture is more than 16 colors, color
reduction is attempted. However, setting this option prohibits color reduction.
-nullanim output null animation data.
fname indirect option file.
-?, -h help
Indirect Filename Specifications
Example 1
command line:
% niff2gfx @ind cube.niff mdl_a.c
"ind" file:
-header a.h -strictflat
converter parsing...:
% niff2gfx -header a.h -strictflat cube.niff mdl_a.c
Example 2
command line:
% niff2gfx ind
"ind" file:
# option
-header model.h
-regmask 0x5 # no CycleMode & CC mode
# input file
cube.niff
# output file
model.c
converter parsing...:
% niff2gfx -header model.h -regmask 0x5 cube.niff model.c
Example 3
command line:
% niff2gfx opt file
"opt" file:
# option
-header model.h
-regmask 0x5 # no CycleMode & CC mode
"file" file:
cube.niff model.c
converter parsing...:
Same as in Example 2
MAT_CC_NIFF_VTX = 0x00000001
MAT_CC_NIFF_TRI = 0x00000002
MAT_CC_NIFF_PRIM = 0x00000004
MAT_CC_NIFF_TEX0 = 0x00000008
MAT_CC_NIFF_TEX1 = 0x00000010
MAT_CC_NIFF_TRI_ALPHA = 0x00020000
MAT_CC_NIFF_PRIM_ALPHA = 0x00040000
MAT_CC_NIFF_TEX0_ALPHA = 0x00080000
MAT_CC_NIFF_VTX_ALPHA = 0x00010000
MAT_CC_NIFF_TEX1_ALPHA = 0x00100000
(Wch - Xch) * Ych + Zch
VTX_A | TRI_A | PRIM_A | TEX0_A | VTX | |
Shade color | |||||
Vertex color | |||||
Texel0 alpha | |||||
Primitive alpha | |||||
Env alpha | |||||
Shade alpha | |||||
Vertex alpha |
In the above table an asterisk (*) refers to an undefined value. In short, _VTX_ALPHA, _TRI_ALPHA, _PRIM_ALPHA, _TEX0_ALPHA, and _VTX are evaluated in order to set one of the above-mentioned modes.
Shade color expresses the color value inferred from calculating SP from the lighting setting and the model's shade.
When G_LIGHTING is set to off in the GeometryMode settings, Vertex color is extracted from the color value used by the normal of the Vtx structure.
When Ych is Shade Color, and when both LOCAL and GLOBAL are 0 (no lighting) in the MAT_SHADE_LIGHT_* settings of mat_shade_type, then the color combiner expression is changed to the following:
(1.0 - Xch) * Wch + Zch
Also note that this special rule does not apply for the second cycle in 2 cycle mode.
Wch, Xch, and Zch are determined from MAT_CC_NIFF_TRI/_PRIM/_TEX0/_TEX1.
Tex0 indicates Texel0 color.
Prim indicates the Primitive Color Register.
Env indicates the Environment Color Register.
T1/Prim is determined from the states of TEXEL1/PRIMITIVE according to the following rule
In 1 cycle mode, the above settings also apply to pipeline 2.
In 2 cycle mode, the above type of evaluation is not performed on mat_color_type1, and the values are substituted and output in the following way:
Determining Alpha Combiner Mode
Alpha combiner mode is determined based on the following mat_alpha_type0 bits:
VTX_ALPHA becomes a control flag for ShadeColor.
T1/Prim is determined from the states of TEXEL1/PRIMITIVE according to the following rule:
In 1 cycle mode, the above settings also apply to pipeline 2.
In 2 cycle mode, the above type of evaluation is not performed on mat_color_type1, and the output value for Shade Alpha is replaced by Combine alpha and output.
3. Known Problems
A 64 x 32 texture that does not fit in TMEM is to be stretched over a square polygon while bilinear interpolation remains effective. Think of it as dividing the texture down the middle and stretching it over two 32 x 32 square polygons.
You can think of a square polygon starting from the left at pixel 0 to pixel 31, and another polygon adjoining it from pixel 32 to 63. But because bilinear interpolation is necessary from the 31st to 32nd pixel, 33 x 33 pixels must be loaded for the texture. The converter can evaluate this, but it cannot evaluate whether the texture tiles fit in 4K of TMEM.
When you prepare on the assumption of an exact fit in TMEM, sometimes the pattern will break down.
TRI
T1/PRIM
TEX0
TEXEL1
PRIM
T1/Prim
Contents
MAT_CC_NIFF_VTX_ALPHA = 0x00010000
MAT_CC_NIFF_TRI_ALPHA = 0x00020000
MAT_CC_NIFF_PRIM_ALPHA = 0x00040000
MAT_CC_NIFF_TEX0_ALPHA = 0x00080000
MAT_CC_NIFF_TEX1_ALPHA = 0x00100000
The following bits are not referenced:
MAT_CC_NIFF_VTX = 0x00000001
MAT_CC_NIFF_TRI = 0x00000002
MAT_CC_NIFF_PRIM = 0x00000004
MAT_CC_NIFF_TEX0 = 0x00000008
MAT_CC_NIFF_TEX1 = 0x00000010
The alpha combiner expression is defined in the same way as the color combiner expression:
(Wch - Xch) * Ych + Zch
The Wch, Xch, Ych, and Zch channels are determined based on the five effective flags described above, and according to the following rule.
TEXEL1_A
PRIM_A
T1/Prim
Contents