SyntaxHighlighter

Monday 1 July 2013

Day 16: A week and four days to Animation13

AR with XNA 4.1

Fixed the rest of the code, updated the draw calls to be version 4.1 compatible (removed some redundant calls to scene.draw, stepped through entire code and fixed dodgy calls, new required calls, etc) and I get a video feed from the camera! I'd go so far as to say it's all working, except the program freezes after one frame, with an error: 
"The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing."
Excellent, now I'm investigating as to what the current vertex shader is playing at.

Update: All fixed! It was an issue with the shadow mapping:

Version 3 code looked like:
Model.CastShadows = true;
Model.ReceiveShadows = true;

whereas version 4.1 requires:
scene.ShadowMap = new MultiLightShadowMap(); // when initializing
...
LightNode.CastShadows = true; // when creating global light sources in the scene
...
Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
Model.Shader = new SimpleShadowShader(scene.ShadowMap);
Model.ShaderTechnique = "DrawWithShadowMap";

But if the model is a primitive model (e.g. a box, square, etc not a loaded textured model), it doesn't need the final line assigning the "DrawWithShadowMap" Shader Technique. This was the bit that had me baffled, apparently the special MultiLightShadowMap shader was only written for primitive models. So whenever I had a demo enabled that used a primitive model the program crashed with an exception. But the error message was absolutely useless at explaining what the problem was! The stack trace leads to the universal call that initiates the drawing of the scene, and ends up with a null pointer exception at the point where the program is passing vertex information to a shader.

Line 5 makes the model receive or cast shadows. Line 6  assigns a shadow shader for this model that uses the IShadowMap we assigned to the scene (line 1).

Once this was done the code ran properly, video feed from the camera came up, demos all running smoothly.

Few quirks I noticed, firstly all the models when shadows are enabled seem far darker than they should be. What were once white surfaces now appear darkish grey. The orange and black giant ant now appears completely black. A quick solution is to just disable shadows but then the objects look a bit flat and lifeless.

Possible solution is to find a shader that handles shadows better than the current one.

Another quirk, in the ship flying through fire demo, the smoke from the flames is much thicker and darker than it used to be. And there are no shadows enabled in that demo so it isn't the shadows. Strange.

123D Catch

I exported the .fbx file of my head from our previous 123D Catch project (see Day 13 here) and loaded into the new XNA 4.1 AR demo program. I removed the shadowmap shader assignments, and the result was quite fantastic:

Me and my head
Eerie but promising. The dark bits on the side of the model or shadows from the ridges on the model. Even though I completely disabled the shadow map shader for this demo, there are still these shifting black shadows haunting my dashing looks, I presume the global light sources have some in built shadow generation properties? It isn't likely, the tutorial code explicitly said that light sources cannot cast shadows unless you also assign the aforementioned shader etc etc which I purposefully didn't do for this demo. Puzzling.

GLC player

I also looked into GLC player and why the textures on my head were completely scrambled when loading an .obj file into the program. The .obj was exported with a jpeg texture and a .mtl mapping them. GLC loads up all three of them properly, and you can apply or remove the texture as you would expect, but the texture just shows up completely scrambled colours ranging between my skin and hair colour.

I loaded the same exported .obj into Blender and the textures worked fine there, so it seems to be particular to GLC. I headed over to the GLC forums (pointed out to me courtesy of Toby), but they aren't very active (the latest post was April 2013). I signed up with a new account to post the problem (i.e. why the 123D Catch exported object has scrambled textures) but you need to get an admin to approve your account before you can post anything so I'm just waiting on that for now.



Tomorrow, few things pending. Firstly automate the model adding procedure (gonna be great fun), secondly work out how to display a gallery of heads (that are generated on the fly from 123D Catch) on a computer in another room being updated in real time (this is what GLC was going to do for us, if we can persuade it to play nice with our, um, strikingly handsome textures).

The fun endeth not!

No comments:

Post a Comment

Note: only a member of this blog may post a comment.