You can use your own effects with the animation library, and apply your own normal mapping, lighting algorithms, bump maps, or whatever else you please to animated models.

You can download the tutorial solution here: CustomShader.zip

Setting Up the Project

Creating the Effect

  • The first step is to create a custom effect that you want to use. There are one or two restrictions for your effect:
    • If the mesh is not skinned, you must have a "Matrix World;" parameter in your effect.
    • If the mesh is skinned, you must have both a "Matrix World;" parameter and a "float4x4 MatrixPalette[ palette size constant ];" parameter
  • Add a new text file to your project and name it "MyPaletteEffect.fx"
  • Write the effect code

Using the Effect in the Code

  • There are three ways to use a custom effect.
  • First, remove this block:
    // Remove this from LoadGraphicsContent
    foreach (ModelMesh mesh in model.Meshes)
    {
        foreach (BasicPaletteEffect effect in mesh.Effects)
        {
            effect.View = view;
            effect.Projection = projection;
        }
    }
    // Remove this code from Update if applicable
    foreach (ModelMesh mesh in dwarfAnimator.Model.Meshes)
        foreach (BasicPaletteEffect effect in mesh.Effects)
            effect.View = view;

    foreach (ModelMesh mesh in ground.Model.Meshes)
        foreach (BasicEffect effect in mesh.Effects)
            effect.View = view;

    // Add this code to Update
    foreach (ModelMesh mesh in dwarfAnimator.Model.Meshes)
        foreach (Effect effect in mesh.Effects)
            effect.Parameters["View"].SetValue(view);

    foreach (ModelMesh mesh in ground.Model.Meshes)
        foreach (Effect effect in mesh.Effects)
            effect.Parameters["View"].SetValue(view);

Last edited Apr 9, 2007 at 3:05 AM by dastle, version 16

Comments

No comments yet.