Exemplo n.º 1
0
void ConfigureButtonsFrame::drawChildren(menu::Graphics &gfx)
{
	if(isVisible())
	{
		int base_x = 204;
		int base_y = 188;
		int lines[NUM_LINES][4] = {{164, 265, 221, 244}, //D-pad (17,56)
								   {476, 265, 419, 244}, //Tri,Squ,Cir,Cro btns (215,56)
								   {275, 160, 302, 240}, //SELECT (98,52)
								   {365, 160, 338, 242}, //START (134,54)
								   {220, 170, 242, 192}, //L1 (38,4)
								   {420, 170, 398, 192}, //R1 (194,4)
								   {220, 200, 232, 204}, //L2 (28,16)
								   {420, 200, 408, 204}, //R2 (204,16)
								   {260, 345, 278, 294}, //AnalogL (74,106)
								   {380, 345, 362, 294}};//AnalogR (158,106)

		GXColor controllerColors[6] = {	{  1,  29, 169, 255}, //blue
										{254,  32,  21, 255}, //orange/red
										{  8, 147,  48, 255}, //green
										{255, 192,   1, 255}, //yellow/gold
										{150, 150, 255, 255}, //light blue lines
										{255, 255, 255, 255}};//white

		//Draw PSX Controller
		menu::Image* controllerIcon = NULL;
//		gfx.setColor(controllerColors[activePad]);
		gfx.setColor(controllerColors[5]);
		controllerIcon = menu::Resources::getInstance().getImage(menu::Resources::IMAGE_PSX_CONTROLLER);
		controllerIcon->activateImage(GX_TEXMAP0);
//		GX_SetTevColorIn(GX_TEVSTAGE0,GX_CC_ZERO,GX_CC_ZERO,GX_CC_ZERO,GX_CC_RASC);
		GX_SetTevColorIn(GX_TEVSTAGE0,GX_CC_ZERO,GX_CC_TEXC,GX_CC_RASC,GX_CC_ZERO);
		GX_SetTevColorOp(GX_TEVSTAGE0,GX_TEV_ADD,GX_TB_ZERO,GX_CS_SCALE_1,GX_TRUE,GX_TEVPREV);
		GX_SetTevAlphaIn(GX_TEVSTAGE0,GX_CA_ZERO,GX_CA_RASA,GX_CA_TEXA,GX_CA_ZERO);
		GX_SetTevAlphaOp(GX_TEVSTAGE0,GX_TEV_ADD,GX_TB_ZERO,GX_CS_SCALE_1,GX_TRUE,GX_TEVPREV);
		gfx.enableBlending(true);
		gfx.drawImage(0, base_x, base_y, 232, 152, 0, 1, 0, 1);
		gfx.setTEV(GX_PASSCLR);

		//Draw lines and circles
		gfx.setColor(controllerColors[5]);
		gfx.setLineWidth(1);
		gfx.drawCircle(115, 300, 60, 33);
		gfx.drawCircle(525, 300, 60, 33);

		for (int i=0; i<NUM_LINES; i++)
			gfx.drawLine(lines[i][0], lines[i][1], lines[i][2], lines[i][3]);

		//Draw buttons
		menu::ComponentList::const_iterator iteration;
		for (iteration = componentList.begin(); iteration != componentList.end(); iteration++)
		{
			(*iteration)->draw(gfx);
		}
	}
}
Exemplo n.º 2
0
void ConfigureButtonsFrame::drawChildren(menu::Graphics &gfx)
{
	if(isVisible())
	{
		int base_x = 216;
		int base_y = 182;
		int lines[NUM_LINES][4] = {{320, 160, 320, 237}, //START
								   {174, 235, 240, 235}, //D-pad
								   {466, 235, 404, 235}, //C-pad
								   {264, 197, 220, 170}, //L
								   {376, 197, 420, 170}, //R
								   {295, 313, 250, 365}, //Z
								   {320, 299, 320, 415}, //Analog
								   {320, 415, 125, 415}, //Invert Y
								   {373, 268, 373, 325}, //B
								   {373, 325, 435, 405}};//A

		GXColor controllerColors[5] = {	{  1,  29, 169, 255}, //blue
										{254,  32,  21, 255}, //orange/red
										{  8, 147,  48, 255}, //green
										{255, 192,   1, 255}, //yellow/gold
										{150, 150, 255, 255}};

		//Draw N64 Controller
		menu::Image* controllerIcon = NULL;
		gfx.setColor(controllerColors[activePad]);
		controllerIcon = menu::Resources::getInstance().getImage(menu::Resources::IMAGE_N64_CONTROLLER);
		controllerIcon->activateImage(GX_TEXMAP0);
		GX_SetTevColorIn(GX_TEVSTAGE0,GX_CC_ZERO,GX_CC_ZERO,GX_CC_ZERO,GX_CC_RASC);
		GX_SetTevColorOp(GX_TEVSTAGE0,GX_TEV_ADD,GX_TB_ZERO,GX_CS_SCALE_1,GX_TRUE,GX_TEVPREV);
		GX_SetTevAlphaIn(GX_TEVSTAGE0,GX_CA_ZERO,GX_CA_RASA,GX_CA_TEXA,GX_CA_ZERO);
		GX_SetTevAlphaOp(GX_TEVSTAGE0,GX_TEV_ADD,GX_TB_ZERO,GX_CS_SCALE_1,GX_TRUE,GX_TEVPREV);
		gfx.enableBlending(true);
		gfx.drawImage(0, base_x, base_y, 208, 200, 0, 1, 0, 1);
		gfx.setTEV(GX_PASSCLR);

		//Draw lines and circles
		gfx.setColor(controllerColors[4]);
		gfx.setLineWidth(2);
		gfx.drawCircle(125, 270, 60, 33);
		gfx.drawCircle(515, 270, 60, 33);

		for (int i=0; i<NUM_LINES; i++)
			gfx.drawLine(lines[i][0], lines[i][1], lines[i][2], lines[i][3]);

		//Draw buttons
		menu::ComponentList::const_iterator iteration;
		for (iteration = componentList.begin(); iteration != componentList.end(); ++iteration)
		{
			(*iteration)->draw(gfx);
		}
	}
}
Exemplo n.º 3
0
void Gui::drawBackground()
{
	//Draw Menu Backdrop
	Resources::getInstance().getImage(Resources::IMAGE_MENU_BACKGROUND)->activateImage(GX_TEXMAP0);
//	gfx->setTEV(GX_REPLACE);
	GXColor muxCol = (GXColor){0,17,85,255};
	GX_SetTevColor(GX_TEVREG0,muxCol);
	GX_SetTevColorIn(GX_TEVSTAGE0,GX_CC_C0,GX_CC_ZERO,GX_CC_TEXC,GX_CC_TEXC);
	GX_SetTevColorOp(GX_TEVSTAGE0,GX_TEV_ADD,GX_TB_ZERO,GX_CS_SCALE_1,GX_TRUE,GX_TEVPREV);
	gfx->enableBlending(false);
	if(screenMode)	gfx->drawImage(0, -104, 0, 848, 480, 0, 1, 0, 1);
	else			gfx->drawImage(0, 0, 0, 640, 480, (848.0-640.0)/2/848.0, 1.0 - (848.0-640.0)/2/848.0, 0, 1);
	gfx->setTEV(GX_PASSCLR);
}
Exemplo n.º 4
0
void glEnable(GLenum type){

	u8 gxlightmask = 0x00000000;
	u8 gxlightmaskspec = 0x00000000;
	int lightcounter = 0;
	int countlights =0;

		switch(type)
		{
			case GL_DEPTH_TEST: depthtestenabled = GX_TRUE; break;
			case GL_LIGHTING:

				//getting opengl lights to work on gx
				//
				//xg has only one light color (a diffuse one)
				//opengl lights have the following colors: diffuse, ambient and specular
				//also opengl has a global ambient color independend of a individual light
				//gx has 2 material colors: diffuse (mat) and ambient (can also be considered part of light?) 
				//opengl material have the followning colors: diffuse, ambient, specular and emission
				//so we (may) have problem (or call it a challenge)

				//now how does opengl calculate light with all these colors
				//vertex color	= material emission 
				//				+ global ambient scaled by material ambient
				//				+ ambient, diffuse, specular contributions from light(s), properly attinuated
				//
				//let us take these apart.
				//
				//material emission is like a constant color. So we can just add this in a tev stage. The only problem is how to add a color to a specific stage?)
				//
				//global ambient scaled by material ambient
				//this is global ambient * material ambient so we can feed that result to an tev stage.
				//
				//Now comes the hard part as each color is used in the light calulation. And we only have once color in gx.
				//Maybe we are lucky as each colors term is added to each other and only then used in light calculation
				//So we might get away with just adding the 3 colors upfront and feed that as color to the light source
				//But first let see how these terms are calculated.
				//
				//Ambient Term = light ambient * material ambient					= GXChanAmbColor ?							
				//Diffuse Term = surface * (light diffuse * material diffuse)		light diffues = light color	| material diffuse = GXChanMatColor	(let gx handle this)	
				//Specular Term = normal.shininess * (light specular * material specular)	(let gx handle this, but add lspec*mspec to GXChanMatColor)
				//
				//now we could use 3 light to emulate 1 opengl light but that would not be helpfull
				//so maybe there is an other way also gx material misses color components
				//
				//gx has max to channels
				//each can be setup differently so we can have on chanel for normal diffuse
				//and the other for specular. But we only have on light color so unless the specular color equals light color this it not usefull)
				//maybe some experiments with GXChanMatColor help with that? So light color to none and all color CHANMatColor?
				//
				//also we have multiple tev stages.
				//as we have used 2 channels we have to use 3 stages
				//stage 1 = emissive + global ambient scaled by material as constant color (maybe 2 stages?)
				//stage 2 = ambient + diffuse
				//stage 3 = specular
				//
				//So this might do the trick in theory. Now on to practice...

				//<h0lyRS> did you try setting specular to channel GX_COLOR1A1, and diffuse to GX_COLOR0A0, so you can blend them anyway you want?
				//this could add an extra color?
				//one way is adding the specular light, other way is multiplying


				//Setup lightmask with enabled lights (thanks h0lyRS)
				for (lightcounter =0; lightcounter < 4; lightcounter++){
					if(gxlightenabled[lightcounter]){ //when light is enabled
						gxlightmask |= (GX_LIGHT0 << lightcounter);
						gxlightmaskspec |= (GX_LIGHT0 << (lightcounter+4) );
						//countlights++;
					}
				};

//                gxlightmask |= (GX_LIGHT0 << 0);
//                gxlightmaskspec |= (GX_LIGHT0 << 1);


                //Setup light system/channels
				GX_SetNumChans(2); //dependend on if there is a specular color/effect needed

				//channel 1 (ambient + diffuse)                          
				GX_SetChanCtrl(GX_COLOR0A0,GX_TRUE,GX_SRC_REG,GX_SRC_REG,gxlightmask,GX_DF_CLAMP,GX_AF_SPOT);
				
				//channel 2 (specular)
				GX_SetChanCtrl(GX_COLOR1A1,GX_ENABLE,GX_SRC_REG,GX_SRC_REG,gxlightmaskspec,GX_DF_CLAMP,GX_AF_SPEC);
				
				
				//Setup TEV-shader
				
				//Setup the number of tev stages needed
				int numtevstages = 0;
				if (tex2denabled){ 
                  numtevstages = 5;
                } else {
                  numtevstages = 4;
                }
				GX_SetNumTevStages(numtevstages); //each extra color takes another stage?
				
				
				//stage 1 (global ambient light)
				
				//color
				GX_SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0); //shagkur method
				GX_SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0); //shagkur method
				GX_SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color

				//end stage 1


				//stage 2 (global ambient light)
				
				//color
				GX_SetTevColorIn(GX_TEVSTAGE1, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C1); //shagkur method
				GX_SetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A1); //shagkur method
				GX_SetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color

				//end stage 2
				
				
				//stage 3 (ambient and diffuse light from material and lights)

				//color
				GX_SetTevColorIn(GX_TEVSTAGE2, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC);
				GX_SetTevColorOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//alpha
				GX_SetTevAlphaIn(GX_TEVSTAGE2, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CC_RASA); 
				GX_SetTevAlphaOp(GX_TEVSTAGE2, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
				
				//tevorder
				GX_SetTevOrder(GX_TEVSTAGE2, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR0A0); //only use color
				
				// end stage 3
				
				//stage 4 (specular light)
				

		// color - blend
		


		GX_SetTevColorOp(GX_TEVSTAGE3, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
		//GX_SetTevColorIn(GX_TEVSTAGE3, GX_CC_CPREV, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC);
       // GX_SetTevColorIn(GX_TEVSTAGE3,GX_CC_ZERO,GX_CC_RASC,GX_CC_CPREV,GX_CC_ZERO);
GX_SetTevColorIn(GX_TEVSTAGE3,GX_CC_ZERO,GX_CC_RASC,GX_CC_ONE,GX_CC_CPREV);

		
		// alpha - nop
		GX_SetTevAlphaOp(GX_TEVSTAGE3, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_ENABLE, GX_TEVPREV);
		//GX_SetTevAlphaIn(GX_TEVSTAGE3, GX_CA_APREV, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA); //shagkur method
        GX_SetTevAlphaIn(GX_TEVSTAGE3,GX_CA_ZERO,GX_CA_RASA,GX_CA_APREV,GX_CA_ZERO);

		GX_SetTevOrder(GX_TEVSTAGE3, GX_TEXCOORDNULL, GX_TEXMAP_NULL, GX_COLOR1A1);
		
			
				// end stage 4
				
				if (tex2denabled){ 
                                   
                    // stage 5 (textures)
				
				    GX_SetTevOrder(GX_TEVSTAGE4, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); //use texture
				    GX_SetTevOp(GX_TEVSTAGE4, GX_MODULATE); //blend with previous stage

                    // end stage 5

                }   

				break;
			case GL_TEXTURE_2D:
				tex2denabled = true;
				GX_SetNumTexGens(1); //multitexturing so set to 1 for now
				GX_SetTevOp(GX_TEVSTAGE0,GX_REPLACE);
				GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
				break;
			case GL_LIGHT0: gxlightenabled[0]=true; break;
			case GL_LIGHT1: gxlightenabled[1]=true; break;
			case GL_LIGHT2: gxlightenabled[2]=true; break;
			case GL_LIGHT3: gxlightenabled[3]=true; break;
			case GL_LIGHT4: gxlightenabled[4]=true; break;
			case GL_LIGHT5: gxlightenabled[5]=true; break;
			case GL_LIGHT6: gxlightenabled[6]=true; break;
			case GL_LIGHT7: gxlightenabled[7]=true; break;
			case GL_CULL_FACE: gxcullfaceanabled=true; break;
		};
}
Exemplo n.º 5
0
void Textbox::SetupGX(const BannerResources& resources) const
{
	GX_ClearVtxDesc();
	GX_InvVtxCache();

	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

	// channel control
	GX_SetNumChans(1);
	GX_SetChanCtrl(GX_COLOR0A0,GX_DISABLE,GX_SRC_REG,GX_SRC_VTX,GX_LIGHTNULL,GX_DF_NONE,GX_AF_NONE);

	// texture gen.
	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
	// texture environment
	GX_SetNumTevStages(1);
	GX_SetNumIndStages(0);
	GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);
	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
	GX_SetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0);
	GX_SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_1_4);
	GX_SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_1);
	GX_SetTevDirect(GX_TEVSTAGE0);
	// swap table
	GX_SetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP1, GX_CH_RED, GX_CH_RED, GX_CH_RED, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP2, GX_CH_GREEN, GX_CH_GREEN, GX_CH_GREEN, GX_CH_ALPHA);
	GX_SetTevSwapModeTable(GX_TEV_SWAP3, GX_CH_BLUE, GX_CH_BLUE, GX_CH_BLUE, GX_CH_ALPHA);
	// alpha compare and blend mode
	GX_SetAlphaCompare(GX_ALWAYS, 0, GX_AOP_AND, GX_ALWAYS, 0);
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET);

	if(header->material_index < resources.materials.size())
	{
		const Material::Header *matHead = resources.materials[header->material_index]->GetHeader();
		if(!matHead)
			return;

		//GX_SetFog(0, 0.0f, 0.0f, 0.0f, 0.0f, (GXColor){0xff, 0xff, 0xff, 0xff});
		GX_SetTevSwapModeTable(0, 0, 1, 2, 3);
		//GX_SetZTexture(0, 0x11, 0);
		GX_SetNumChans(1 );
		GX_SetChanCtrl(4, 0, 0, 1, 0, 0, 2);
		GX_SetChanCtrl(5, 0, 0, 0, 0, 0, 2);
		GX_SetNumTexGens(1);
		GX_SetTexCoordGen2(0, 1, 4, 0x3c, 0, 0x7D);
		GX_SetNumIndStages(0);
		GX_SetBlendMode(1, 4, 5, 0xf);
		GX_SetNumTevStages(2);
		GX_SetTevDirect(0);
		GX_SetTevDirect(1);
		GX_SetTevSwapMode(0, 0, 0);
		GX_SetTevSwapMode(1, 0, 0);
		GX_SetTevOrder(0, 0, 0, 0xff);

		for( int i = 0; i < 2; i++ )
		{
			// Devkitppc_r27 internal compiler error
			//GX_SetTevColor(i + 1, (GXColor){ LIMIT(matHead->color_regs[i].r, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].g, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].b, 0, 0xFF),
			//								 LIMIT(matHead->color_regs[i].a, 0, 0xFF) });
											 
			u8 r = (u8) LIMIT(matHead->color_regs[i].r, 0, 0xFF);
			u8 g = (u8) LIMIT(matHead->color_regs[i].g, 0, 0xFF);
			u8 b = (u8) LIMIT(matHead->color_regs[i].b, 0, 0xFF);
			u8 a = (u8) LIMIT(matHead->color_regs[i].a, 0, 0xFF);
			GX_SetTevColor((u8) (i + 1), (GXColor){r,g,b,a});
		}

		GX_SetTevColorIn(0, 2, 4, 8, 0xf);
		GX_SetTevAlphaIn(0, 1, 2, 4, 7);
		GX_SetTevColorOp(0, 0, 0, 0, 1, 0);
		GX_SetTevAlphaOp(0, 0, 0, 0, 1, 0);
		GX_SetTevOrder(1, 0xff, 0xff, 4);
		GX_SetTevColorIn(1, 0xf, 0, 0xa, 0xf);
		GX_SetTevAlphaIn(1, 7, 0,  5, 7);
		GX_SetTevColorOp(1, 0, 0, 0, 1, 0);
		GX_SetTevAlphaOp(1, 0, 0, 0, 1, 0);
	}
}
Exemplo n.º 6
0
void Particle_Render(Mtx M_view, ParticleSystem* psystem, Camera* camera) {
	// setup TEV
	GX_ClearVtxDesc();
	
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

	// load model-view matrix
	Mtx M_modelView;
	guMtxIdentity(M_modelView);
	GX_LoadPosMtxImm(M_modelView, GX_PNMTX0);

	// setup tev
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetAlphaUpdate(GX_TRUE);

	GX_SetNumChans(1);

	GX_SetTevColorIn( 
		GX_TEVSTAGE0, 
		GX_CC_TEXC,  // a
		GX_CC_RASC,  // b
		GX_CC_TEXA,  // c 
		GX_CC_ZERO); // d

	GX_SetTevColorOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_2,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg


	GX_SetTevAlphaIn(
		GX_TEVSTAGE0, 
		GX_CA_ZERO,  // a
		GX_CA_TEXA,  // b
		GX_CA_RASA,  // c 
		GX_CA_ZERO); // d

	GX_SetTevAlphaOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_1,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg



	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

	GX_LoadTexObj(&psystem->texture, GX_TEXMAP0);

	int n = psystem->n_particles;

	f32 texCoords[] = {
		0, 0,
		0, 1,
		1, 1,
		1, 0
	};

	GX_InvVtxCache();
	Vec3 camPos = camera->position();

	Mtx axisMtx;
	
	System::LogClear();
	
	Particle_Sort(M_view, psystem);

	GX_Begin(GX_QUADS, GX_VTXFMT6, n*4);
		for (int k = 0; k < n; k++) {
			int i = psystem->binsAllocations[k].particleIdx;
			//System::Log(L"p%d", i);
			Vec3& p  = psystem->positions[i];
			f32 lifetime = psystem->lifetimes[i];
			f32 age = psystem->ages[i];

			f32 ratio = age/lifetime;

			Vec3 forward = Math3D::normalized(camPos - p);

			Vec3 worldUp = Vec3(0, 1, 0);
			Vec3 right = Math3D::normalized(Math3D::cross(worldUp, forward));

			Vec3 up = Math3D::cross(forward, right);

			Mtx pm;

			guMtxCopy(M_view, pm);
			guMtxTranspose(pm, pm);
			pm[0][3] = p.x;		pm[1][3] = p.y;		pm[2][3] = p.z;

			guMtxConcat(M_view, pm, pm);
			
			f32 rotation = psystem->rotations[i];
			if (psystem->rotationInterpolator)
				rotation = psystem->rotationInterpolator->getValue(rotation, ratio);

			f32 size = psystem->sizes[i];
			if (psystem->sizeInterpolator)
				size = psystem->sizeInterpolator->getValue(size, ratio);

			if (psystem->colorInterpolator)
				psystem->colors[i] = psystem->colorInterpolator->getValue(ratio);

			Matrix34 M_rot = Math3D::matrixRotationZ(rotation);
			f32 hs = size*0.5f;
			Vec3 p0(-hs, +hs, 0);
			Vec3 p1(-hs, -hs, 0);
			Vec3 p2(+hs, -hs, 0);
			Vec3 p3(+hs, +hs, 0);

			Vec3 vs[4] = {p0, p1, p2, p3};

			for (int i = 0; i < 4; i++) {
				vs[i] = M_rot * vs[i];
				vs[i] = Math3D::matrixVecMul(pm, vs[i]);
			}
			
			for (int i = 0; i < 4; i++) {
				f32* coords = &texCoords[2*i];
				SendVertex(vs[i], psystem->colors[i], coords[0], coords[1]);
			}
		}
	GX_End();


	return;
}
Exemplo n.º 7
0
inline void Material::ApplyTevStages(bool modulate_colors) const
{
	u32 tev_stages_cnt = 0;

	if(flags->tev_stages)
	{
		// tev stages
		for(u32 i = 0; i < flags->tev_stages; ++i)
		{
			const TevStage &ts = tev_stages[i];

			GX_SetTevOrder(i, ts.texcoord, ts.tex_map | (ts.lowBit << 8), ts.color );
			GX_SetTevSwapMode(i, ts.ras_sel, ts.tex_sel);

			GX_SetTevColorIn(i, ts.color_in.a, ts.color_in.b, ts.color_in.c, ts.color_in.d);
			GX_SetTevColorOp(i, ts.color_in.tevop, ts.color_in.tevbias, ts.color_in.tevscale, ts.color_in.clamp, ts.color_in.tevregid );
			GX_SetTevKColorSel(i, ts.color_in.sel );

			GX_SetTevAlphaIn(i, ts.alpha_in.a, ts.alpha_in.b, ts.alpha_in.c, ts.alpha_in.d);
			GX_SetTevAlphaOp(i, ts.alpha_in.tevop, ts.alpha_in.tevbias, ts.alpha_in.tevscale, ts.alpha_in.clamp, ts.alpha_in.tevregid );
			GX_SetTevKAlphaSel(i, ts.alpha_in.sel );

			GX_SetTevIndirect(i, ts.ind.indtexid, ts.ind.format, ts.ind.bias, ts.ind.mtxid,
				ts.ind.wrap_s, ts.ind.wrap_t, ts.ind.addprev, ts.ind.utclod, ts.ind.a);

			tev_stages_cnt++;
		}
	}
	else
	{
		if(flags->texture_map == 0)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0xFF, 0xFF, 4);
			GX_SetTevColorIn(GX_TEVSTAGE0, 0xF, 4, 0xA, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 0x7, 2, 0x5, 0x7);
			tev_stages_cnt++;
		}
		else if(flags->texture_map == 1)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0, 0, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0, 2, 4, 8, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 1, 2, 4, 7);
			tev_stages_cnt++;

			// 2nd stage
			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}
		else if(flags->texture_map == 2)
		{
			// 1st stage
			GX_SetTevOrder(GX_TEVSTAGE0, 0, 0, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0, 0xF, 0xF, 0xF, 8);
			GX_SetTevAlphaIn(GX_TEVSTAGE0, 7, 7, 7, 4);
			tev_stages_cnt++;

			// 2nd stage
			GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 1, 1, 0xFF);
			GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 8, 0, 0xE, 0xF);
			GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 4, 0, 6, 7);
			GX_SetTevKColorSel(GX_TEVSTAGE0 + tev_stages_cnt, 0x1f);
			GX_SetTevKAlphaSel(GX_TEVSTAGE0 + tev_stages_cnt, 0x1f);
			tev_stages_cnt++;

			// 3rd stage
			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}
		else
		{
			u32 TevKDefault[] = { 0x1F, 0x1B, 0x17, 0x13, 0x1E, 0x1A, 0x16, 0x12 };

			for(int i = 0; i < flags->texture_map; i++)
			{
				GX_SetTevOrder(i, i, i, 0xff );

				GX_SetTevColorIn(i, 0xf, 8, 0xe, i ? 0xf : 0 );
				GX_SetTevAlphaIn(i, 7, 4, 6, i ? 7 : 0 );
				GX_SetTevKColorSel(i, TevKDefault[i] );
				GX_SetTevKAlphaSel(i, TevKDefault[i] );
				tev_stages_cnt++;
			}

			GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xff, 0xff, 0xff );
			GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 2, 4, 0, 0xf );
			GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 1, 2, 0, 7 );
			tev_stages_cnt++;

			if(modulate_colors)
			{
				GX_SetTevOrder(GX_TEVSTAGE0 + tev_stages_cnt, 0xFF, 0xFF, 4);
				GX_SetTevColorIn(GX_TEVSTAGE0 + tev_stages_cnt, 0xF, 0, 0xA, 0xF);
				GX_SetTevAlphaIn(GX_TEVSTAGE0 + tev_stages_cnt, 7, 0, 5, 7);
				tev_stages_cnt++;
			}
		}

		for(u32 i = 0; i < tev_stages_cnt; i++)
		{
			GX_SetTevColorOp(GX_TEVSTAGE0 + i, 0, 0, 0, 1, 0);
			GX_SetTevAlphaOp(GX_TEVSTAGE0 + i, 0, 0, 0, 1, 0);
			GX_SetTevDirect(GX_TEVSTAGE0 + i);
			GX_SetTevSwapMode(GX_TEVSTAGE0 + i, 0, 0);
		}
	}

	// enable correct number of tev stages
	GX_SetNumTevStages(tev_stages_cnt);
}