How to add effect from *.fx file?

Jul 6, 2007 at 9:08 PM
I load my effect
Effect effe = content.Load<Effect>("PerPixelLighting");

And change in model
foreach (ModelMesh mesh in model.Meshes)
foreach (ModelMeshPart part in mesh.MeshParts)
BasicPaletteEffect oldEffect = (BasicPaletteEffect)part.Effect;
part.Effect = efe;

Then create modelanimator.

Here is the error code
“The effects on the model for a ModelAnimator were changed without calling ModelAnimator.InitializeEffectParams().”

I try to put this method everywhere but stilt the same error . Help.
Aug 5, 2007 at 11:33 PM
Edited Aug 9, 2007 at 12:14 AM
Just call ModelAnimatorName.InitializeEffectParams() after drawing a model
Sep 19, 2007 at 8:53 AM
Edited Sep 19, 2007 at 9:10 AM
I have the exact same problem. No matter where and how often I call InitializeEffectParams() I get this same error when base.draw() is called. Did you find a solution Moski8?
Sep 19, 2007 at 9:24 AM
The problem is that you must write som extra code to you *.FX file.
Here is tutorial how tu write no efect *.FX file.
As you see we need this
// These are required by the Animation library
float4x4 MatrixPalette56;
float4x4 World;
and this function
// This method takes in a vertex and applies the bone transforms to it.
SKINOUTPUT Skin4( const VSINPUT input)
// Since the weights need to add up to one, store 1.0 - (sum of the weights)
float lastWeight = 1.0;
float weight = 0;
// Apply the transforms for the first 3 weights
for (int i = 0; i < 3; ++i)
weight = input.weightsi;
lastWeight -= weight;
output.position += mul( input.position, MatrixPaletteinput.indices[i]) * weight;
output.normal += mul( input.normal, MatrixPaletteinput.indices[i]) * weight;
// Apply the transform for the last weight
output.position += mul( input.position, MatrixPaletteinput.indices[3])*lastWeight;
output.normal += mul( input.normal, MatrixPaletteinput.indices[3])*lastWeight;
return output;

If you shoud use “MyPaletteEffect.fx” like a skeleton. I do that and it’s work but it was hard work.
Sep 19, 2007 at 11:26 AM
Thanks Moski8, I found the source to the error myself. I knew about the skinning stuff in the shader, unfortunately I was by mistake using an old version of my shader, before I added the skinning. Thanks again!