Normal Mapping

Topics: Developer Forum
May 6, 2007 at 2:16 AM
Hi, I was wondering how i would go about creating a normal map shader that is compatible with the animation library and how i would create a content processor for it.
I use 3ds max and have been able to get my skinned model to use a direct x 9 noraml shader , hence i can see the model normal mapped in the view port

I dont know if this is the correct way to do this. for a previous engine the model was exported with the difuse texture and then the normal map added in code.

Is this the same with xna. I am currently exporting to FBX, every thing works fine, animations and all its just when it comes to adding a normal map effect that I am completely lost
May 7, 2007 at 11:39 AM
Have been able to get a normal shader up and running using custom effects, but dont know how to properly add it to the library, it seems to only be affected one side of the skinned model, any one know how to add a normal map using the library. I have tried the content pipe line approach and the custom effects approach. The funny thing is if I use the exact shader in max it works perfectly,
May 12, 2007 at 7:05 PM
The problem is that the Animation Library does not currently provide the Tangent and Binormal vertex channels, hopefully this will get added soon, it shouldn't be much of an operation.
May 14, 2007 at 8:12 PM
Edited May 14, 2007 at 8:14 PM
I'm only just starting to poke at this, but would the generation of Tangent and Binormal info be as simple as adding the following to XMeshImporter.cs in the content solution, after line 433:

       MeshHelper.CalculateTangentFrames(mesh,
                                         VertexChannelNames.TextureCoordinate(0),
                                         VertexChannelNames.Tangent(0),
                                         VertexChannelNames.Binormal(0));

I haven't tried it yet (still incorporating the replacement effect). Let me know if this makes sense.

Thanks!

Derek
May 30, 2007 at 3:57 PM
I've tried placing that method in a few places in the model processor, I have not had much luck.
Coordinator
Jun 6, 2007 at 11:43 PM
You'd have to make a custom effect if you want to use a normal map and per pixel lighting. This requires knowledge of how to implement a normal map. Have you done this before? If so, it won't be hard.
Jun 7, 2007 at 12:32 AM
Edited Jun 7, 2007 at 1:12 AM

dastle wrote:
You'd have to make a custom effect if you want to use a normal map and per pixel lighting. This requires knowledge of how to implement a normal map. Have you done this before? If so, it won't be hard.


I've written a custom shader that supports normal maps and per pixel lighting, thats not problem. I'm just having some difficulty with the Binormal and Tangent vertex channels. They are not currently held in the mesh after being processed by the animation component library.
Exporting those 2 additional channels would be greatly appreciated
Jun 15, 2007 at 8:58 PM
I can post a custom effect that i use if anyone would care to use it.
Jun 27, 2007 at 12:48 AM
Edited Jun 27, 2007 at 1:39 AM
dastle,
I'm not sure if you have any plans to implement the additional vertex channels for tangents and binormals into your content pipeline, but a sample of how to extend the Animated Model importer to support this would be a good if you would be so kind

Cheers
Kyle
Aug 23, 2007 at 9:01 AM
I too would greatly appreciate support for tangents and binormals. This would really improve the usability of the library in high-end graphics applications. I think dastle have done a great job with this animation library, I'm really impressed with the implementation.

Thanks dastle!
Sep 23, 2007 at 6:30 PM
Hi,
has any one been able to add support for tangents and binormals?

thanks

ktg
Sep 23, 2007 at 8:36 PM
My previous shader was messed up, you can get your binormals and tangents by calling MeshHelper.CalculateTangentFrames(); inside the if part of find meshes.

private void FindMeshes (NodeContent root)
{
if (root is MeshContent)
{
MeshContent mesh = (MeshContent)root;
mesh.OpaqueData.Add("MeshIndex", numMeshes);
numMeshes++;
meshes.Add(mesh);

////////////////////////////////////////////////////////////////////
// CHANGE: Calculate tangents and binormals for normal mapping
MeshHelper.CalculateTangentFrames(mesh,
VertexChannelNames.TextureCoordinate(0),
VertexChannelNames.Tangent(0),
VertexChannelNames.Binormal(0));
////////////////////////////////////////////////////////////////////

}
foreach (NodeContent child in root.Children)
FindMeshes(child);
}
Mar 16, 2008 at 8:40 AM
Hi,

i am using the code above to gerenate Tangents and Binormals. Debugging the Draw code the vertex declaration seems ok, yet the tangents and binormals seem to be broken. i am rendering static objects using the animation library (for testing). the shader itself seems to be fine, it works using the xna model class for rendering. any ideas?

btw, i am using xna 2.0 (ported the lib myself)

thx in advance
pettersson
Coordinator
Mar 17, 2008 at 8:03 AM
Ok guys, thanks for the input. I'll put this second on my list of things to do, after making the library compatible with 2.0. I don't have visual studio 2008 atm, but I'll grab a copy soon to port to 2.0. And, I would appreciate any quick comments on what difficulties you ran into and how you solved them for those of you who ported the lib to 2.0.