N64® Functions Menu

al - Audio Library Functions
gDP - DP GBI Macros
gdSP - General GBI Macros
gSP - SP GBI Macros
gt - Turbo Microcode RDP
gu - Graphics Utilities
Math - Math Functions
nuSys - NuSystem
os - N64 Operating System
sp - Sprite Library Functions
uh - Host to Target IO
64DD - N64 Disk Drive

Nintendo® Confidential

   

gSPZLight
gSPZLightMaterial

Format
gSPZLight(Gfx *gp, u32 nsrc,
   u32 num, u32 cdest, u32 tdest)
gSPZLightMaterial(Gfx *gp, u32 msrc,
   u32 nsrc, u32 num, u32 cdest,
   u32 tdest)
Arguments
  • gp is the pointer to the graphics display list
  • msrc is the starting address in the user area that holds the material color data (the color of the vertices)
  • nsrc is the starting address in the user area that holds the normal ray vector data
  • num is the number of normal ray vectors to be processed (multiple of 2)
  • cdest is the starting address in the user area that will store the color value of the vertices after the light calculation
  • tdest is the starting address of the user area that will store the texture and coordinate values of the vertices after the environment map calculation
What These Macros Do
These Z-Sort microcode GBI macros regard the data from the nsrc address in the user area as the signed 8-bit normal ray vector value (nx, ny, nz). They calculate the lighting by using the light parameters specified by the gSPZXfmLights macro. This provides the light color that corresponds to the normal ray vectors. The vertex color is obtained by multiplying this light color and the material color, which is the color of the vertex itself, by each r, g, b element. These calculated color values are stored at the cdest address in the user area.

With gSPZLight, the r, g, b, and a values are each equal to 255, and that is used as the material color. As with Fast3D microcode, this indicates vertex coloring using light color.

With gSPZLightMaterial, use data from the msrc address in the user area as the r, g, b, and a values, in order, for the unsigned 8-bit color data.

Note that when the LookAt structure's data is set as the light data, the macros perform the lighting calculation and environment map calculation simultaneously. Texture coordinate values (S, T = 0.00-32.00) are output to the tdest address in the user area as the calculation results. Even when the LookAt structure data is not set, an undefined value is output to tdest, so be careful that the (num * 4) bytes area is not destroyed.

After cdest and tdest are output, 3 is added to nsrc and 4 is added to msrc, cdest, and tdest. Then the process proceeds to the next vertex. Although the num number of normal ray vectors are processed continuously, the num argument must have an even number as its value. If the number value is odd, (num+1) is output to cdest and tdest to make an even number. Then meaningless data is output to the output data position of num+1.

The formats of the data values to be input and output using these GBI macros are defined as follows as the zNorm, zColor, and zTxtr structures in the header file gZ-Sort.h.
 typedef struct  {
   s8  nx, ny, nz;
   }  zNorm;

 typedef struct  {
   u8  r, g, b, a;
   } zColor_t;

 typedef union  {
   zColor_t  n;
   u32  w;
   }  zColor;

 typedef struct  {
   s16 s, t;
   }  zTxtr_t;

 typedef union  {
   zTxtr_t  n;
   u32  w;
   }  zTxtr;
The size of each structure is 3 or 4 bytes, so you need to pay special attention to the 8-byte alignment when transferring DMA using gSPZSetUMem. When the transfer size must be a multiple of 8, the DMA transfer size must be rounded off to a multiple of 8.

The routine of these GBI macros is basically as follows. If you are careful not to overwrite the unprocessed nsrc and msrc with the output of cdest and tdest, it is possible to overlap these areas.
for (i = 0; i < num; i ++) {
  (*cdest, tdest) = CalcLight (*nsrc, *msrc);
  nsrc  += 3;
  msrc  += 4;
  cdest  += 4;
  tdest  += 4;
}
For detailed information on Z-Sort microcode's GBI macros and data structures, please see the "Z-Sort Microcode" area of the N64 Programming Manual.

See Also
Z-Sort Microcode
gSPZRdpCmd
gSPZSetUMem
gSPZGetUMem
gSPZSetMtx
gSPZGetMtx
gSPZMtxCat
gSPZMtxTrnsp3x3
gSPZViewPort
gSPZMultMPMtx
gSPZSetAmbient
gSPZSetDefuse
gSPZSetLookAt
gSPZXfmLights
gSPZLight
gSPZLightMaterial
gSPZMixS16
gSPZMixS8
gSPZMixU8
gSPZSegment
gSPZSetSubDL
gSPZLinkSubDL
gSPZSendMessage
gSPZWaitSignal
gSPZSegment
gSPZPerspNormalize



Nintendo® Confidential

Warning: all information in this document is confidential and covered by a non-disclosure agreement. You are responsible for keeping this information confidential and protected. Nintendo will vigorously enforce this responsibility.


Copyright © 1998
Nintendo of America Inc. All rights reserved
Nintendo and N64 are registered trademarks of Nintendo
Last updated January 1998