1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - GX - demos - UnitTours/DEMOLib
3 File: DEMOUtility.c
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 #include "DEMOUtility.h"
19
20 #define DEMO_INTENSITY_DF 23
21 #define DEMO_INTENSITY_AM 8
22 #define DEMO_INTENSITY_SP 31
23
24 static const GXRgb DEMO_DIFFUSE_COL =
25 GX_RGB(DEMO_INTENSITY_DF, DEMO_INTENSITY_DF, DEMO_INTENSITY_DF);
26 static const GXRgb DEMO_AMBIENT_COL =
27 GX_RGB(DEMO_INTENSITY_AM, DEMO_INTENSITY_AM, DEMO_INTENSITY_AM);
28 static const GXRgb DEMO_SPECULAR_COL =
29 GX_RGB(DEMO_INTENSITY_SP, DEMO_INTENSITY_SP, DEMO_INTENSITY_SP);
30 static const GXRgb DEMO_EMISSION_COL = GX_RGB(0, 0, 0);
31
32 static const u32 LIGHTING_L_DOT_S_SHIFT = 8;
33
34
DEMO_Set3DDefaultMaterial(BOOL bUsediffuseAsVtxCol,BOOL bUseShininessTbl)35 void DEMO_Set3DDefaultMaterial(BOOL bUsediffuseAsVtxCol, BOOL bUseShininessTbl)
36 {
37 G3_MaterialColorDiffAmb(DEMO_DIFFUSE_COL, // diffuse
38 DEMO_AMBIENT_COL, // ambient
39 bUsediffuseAsVtxCol // use diffuse as vtx color if TRUE
40 );
41
42 G3_MaterialColorSpecEmi(DEMO_SPECULAR_COL, // specular
43 DEMO_EMISSION_COL, // emission
44 bUseShininessTbl // use shininess table if TRUE
45 );
46 }
47
48
49 #include <nitro/code32.h> // avoid byte access problems
DEMO_Set3DDefaultShininessTable()50 void DEMO_Set3DDefaultShininessTable()
51 {
52 u8 i;
53 u32 shininess_table[32];
54 u8 *pShininess = (u8 *)&shininess_table[0];
55 const u8 tableLength = 32 * sizeof(u32);
56
57 for (i = 0; i < tableLength - 1; i++)
58 {
59 // ShininessTable is ( 0.8 ) fixed point foramt, so we have to right-shift 8 bit for One multiply.
60 // pShininess = (i*2+1)^4
61 pShininess[i] = (u8)(((s64)(i * 2 + 1) * (i * 2 + 1) * (i * 2 + 1) * (i * 2 + 1)) >> (LIGHTING_L_DOT_S_SHIFT * (4 - 1))); // byte access
62 }
63
64 // set the max value specialy
65 pShininess[tableLength - 1] = 0xFF;
66
67 G3_Shininess(&shininess_table[0]);
68 }
69
70 #include <nitro/codereset.h>
71