void GX_TestInitLightShininess(GXLightObj *lobj, f32 shininess) { shininess = (shininess / 128) * 256; //convert opengl range to gx GX_InitLightAttn(lobj, 1.0, 0.0, 2.0, (shininess)*0.5, 0.0, 1.0F-(shininess)*0.5 ); //Redshade //math behind a and k is [a0 + a1^2 + a2^3], brightness as you go away from the center, [or brightness as you go away from source in k //if you want to see the GL equivalent, look up GL_(CONSTANT|LINEAR|QUADRATIC)_ATTENUATION, since those are k0,k1,k2 respectively //your end equation value should be between 0.0 and 1.0 }
void render(NODE * node, Vector camPos) { Mtx tmp; if(!node->isRenderable()) return;//Skip non-renderable nodes such as empty nodes, regions or lights if(node->flags & F_Visible)//Is it visible? { //Set matrices Mtx aux, inv; GX_ClearVtxDesc(); node->absMtx(modelM); char msg[64]; guMtxConcat(view, modelM, modelview); GX_LoadPosMtxImm(modelview, GX_PNMTX0);//Load model view matrix guMtxInverse(modelview, tmp); guMtxTranspose(tmp,inv); GX_LoadNrmMtxImm(inv, GX_PNMTX0);//Load normal matrix //TODO: Better lighting (multiple lights) std::vector<LIGHT*>::iterator light = mainRoot->getLights().begin(); //if(light == mainRoot->getLights().end()) // REVConsole->write("LIGHT"); GXLightObj lObj[8]; u8 lightMask = 0, tmpLight = GX_LIGHT0; for(u8 i = 0;light != mainRoot->getLights().end(); ++light, ++i) { Vector lpos = (*light)->getPos(); guVecMultiply(view, &lpos, &lpos); GX_InitLightPos(&lObj[i],lpos.x,lpos.y,lpos.z); GX_InitLightAttn(&lObj[i], 1.0f,0.0f,0.0f,1.0f,0.0f,0.0f); GX_InitLightSpot(&lObj[i],0.0f,GX_SP_OFF); GX_InitLightColor(&lObj[i],(*light)->clr); GX_LoadLightObj(&lObj[i],tmpLight); lightMask |= tmpLight; tmpLight *= 2; } //Render the node node->render(lightMask); } }