Help me understand why there is no shading

Topics: User Forum
Feb 15, 2009 at 12:33 PM
I am new to this library and a beginner when it comes to skinned animation.

I have the dwarf tutorial up and running, everything is fine, except there is no lighting or shading. 
I am also trying out one of my own models. It also draws fine, but again without shading. What am I missing?

The LoadContent method contains the following code, but the code is never entered because the effects in the collection are neither BasicEffect or BasicPaletteEffect, just Effect. This goes for both the dwarf and my own .fbx model.
Is this an error caused by importing or does it matter at all?

Thank you for any help.

(ModelMesh mesh in model.Meshes)



foreach (Effect effect in mesh.Effects)




if (effect is BasicEffect)




BasicEffect basic = (BasicEffect)effect;


basic.View = view;

basic.Projection = projection;



else if (effect is BasicPaletteEffect)




BasicPaletteEffect palette = (BasicPaletteEffect)effect;


palette.View = view;

palette.Projection = projection;


// enable some lighting



palette.DirectionalLight0.Direction =

new Vector3(0, 0, 1);





Mar 6, 2009 at 2:58 AM
I've just found out today, some hours ago, that this code is useless in the dwarf example. It never runs. You can delete & it's the same. Also, it's assigning values to the model inner objects, but this model is not public (global) and never returned by the function. So (please correct me if I'm wrong) it does nothing. I think that this code is supposed to be used if you don't use this library or if your model is not skinned. But anyway, the model object should be returned somehow (i've found many desing mistakes like this & believe me, they REALLY complicate the understanding of the whole thing. Specially with matrices (world, view & projection) & effects.

It's strange that u get no color nor lighting though. Have u just unpacked & runned the example or u've been tweaking it? Do u have the textures & evrth in the correct place?
Check this out:

// Replace the old effects with your custom shader
foreach (ModelMesh mesh in model.Meshes)
    foreach (ModelMeshPart part in mesh.MeshParts)
        BasicPaletteEffect oldEffect = (BasicPaletteEffect)part.Effect;
        Effect newEffect = myEffect.Clone(graphics.GraphicsDevice);
        part.Effect = newEffect; oldEffect.Dispose();

In the  Effect newEffect = myEffect.Clone(graphics.GraphicsDevice);  line the meshPart texture is retrieved & stored in the new effect (custom, from your fx file) that will replace the original model effect. So if u put a breakpoint there, you should be able to see a Texture object (instead of null). If u get null then u are having a problem with textures (so check the location of them).

Effects stuff is still not very clear for me as I don't know HLSL.
I hope this helps :)

Good luck,