Tuesday, 15 May 2012

c# - How (update,set, apply) dynamically color on a model of a XNA project? -



c# - How (update,set, apply) dynamically color on a model of a XNA project? -

i encounter problem set background color on model instantiated. can alter texture not alter color. there parameter alter color ? or alter opacity ? looking way highlight model.

thank much

here code used: works except 2 lastly line. searched can not find name parameter color , opacity

//does not work

effect.parameters["color"].setvalue(new vector3(0,1,0)); effect.parameters["opacity"].setvalue(0.5f);

void drawmodelhardwareinstancing(model model, matrix[] modelbones, matrix[] instances, matrix view, matrix projection) { ....... foreach (modelmesh mesh in model.meshes) { foreach (modelmeshpart meshpart in mesh.meshparts) { // tell gpu read both model vertex buffer plus our instancevertexbuffer. game.graphicsdevice.setvertexbuffers( new vertexbufferbinding(meshpart.vertexbuffer, meshpart.vertexoffset, 0), new vertexbufferbinding(instancevertexbuffer, 0, 1) ); game.graphicsdevice.indices = meshpart.indexbuffer; // set instance rendering effect. effect effect = meshpart.effect; //effect.currenttechnique = effect.techniques["hardwareinstancing"]; effect.parameters["world"].setvalue(modelbones[mesh.parentbone.index]); //work perfect effect.parameters["view"].setvalue(view); effect.parameters["projection"].setvalue(projection); effect.parameters["texture"].setvalue(textureinstancedmodel); /* ***************************** */ //does not work effect.parameters["color"].setvalue(new vector3(0,1,0)); effect.parameters["opacity"].setvalue(0.5f); /* ***************************** */ // draw instance copies in single call. foreach (effectpass pass in effect.currenttechnique.passes) { pass.apply(); game.graphicsdevice.drawinstancedprimitives(primitivetype.trianglelist, 0, 0, meshpart.numvertices, meshpart.startindex, meshpart.primitivecount, instances.length); } } ........ }

c# colors xna drawing effects

No comments:

Post a Comment