Shadows casting from *.fbx model

Apr 15, 2012 at 3:40 PM


I'm trying to put model from fbx file into the scene and render it with shadows, the ones that textured primitives use. 
Here is the code I use:

ModelLoader loader = new ModelLoader();

Model teapotModel = (Model)loader.Load("", "teapot_modeltest");

teapotNode = new GeometryNode("teapot");

teapotNode.Model = teapotModel;

((Model)teapotNode.Model).UseInternalMaterials = true;

((Model)teapotNode.Model).ShadowAttribute = ShadowAttribute.ReceiveCast;

((Model)teapotNode.Model).Shader = new SimpleShadowShader(scene.ShadowMap);�

teapotNode.Model.ShowBoundingBox = true; �

groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml"); � � �

scene.RootNode.AddChild(groundMarkerNode);groundMarkerNode.AddChild(teapotNode); �


It throws this exception:

An unhandled exception of type 'System.ArgumentNullException' occurred in Microsoft.Xna.Framework.Graphics.dllAdditional information: This method does not accept null for this parameter.

At this line:

scene.Draw(gameTime.ElapsedGameTime, gameTime.IsRunningSlowly);

If I remove this line:

((Model)teapotNode.Model).Shader = new SimpleShadowShader(scene.ShadowMap);

Model appears but there is no shadow. I'm new in this library, been using it for two weeks or so.

Any help would be appreciated, cause it is a really great library to work with.

Apr 18, 2012 at 3:01 PM

It actually may not work with regular Model class right now. I've only tested with PrimitiveModel types for shadow mapping, if I remember correctly since that's what I needed for my research purpose. In any case, make sure scene.ShadowMap is not null first of all. If that's not a cause of an issue, then there's probably some bug in the SimpleShadowShader. In that case, please send me your teapot model so that I can do more testing later on. It'll probably be after ISMAR deadline though (late May)


Apr 23, 2012 at 3:31 PM
Edited Apr 23, 2012 at 5:34 PM

Well yes it works perfectly on primitiveModel types like spheres boxes and stuff like that. Anyway I added more models to scene like boxes and shadows appeared, but as soon as I assign shader to model from Max it crashes. And about that teapot model it's just a simple teapot exported from Max in fbx format. I was trying to make it work first and then I would move on with my vehicle model I did earlier.
I found that shadows in version 3.6 works fine so I switch back to it, or maybe there is a simple way to use that *.fx in 4 version?, but probably it require shader recompiling since it is different VS and PS versions.

Thank you for answer anyway :).

Oct 10, 2012 at 2:17 PM

Unfortunately, I have the same problem. :( Is there any solution?

Oct 24, 2012 at 8:11 PM

I've made them to work only for primitive models with textures. XNA 4.0 is strict on the requirement of what vertex contains (normal, color, texture coord, binormal, etc) so you will need to extend MultiLightShadowMap.fx for regular model with whatever vertex info is included. We only needed simple primitive models, so I didn't create bunch of .fx that works with regular models.


Nov 6, 2012 at 8:09 PM

Dear Ohan, I think i figured out why it throws that exception for shadow casting for FBX models.

There is this line in Tutorial 8:

geometryNode.Model.ShaderTechnique = "DrawWithShadowMap"

When I copy this line into my code, it works, for non-primitive models too! ;)


Nov 7, 2012 at 5:19 PM
Edited Nov 7, 2012 at 5:29 PM

Hi bedarob!

Works to me, many thanks for sharing!