C# XNA Normals, Diffuse, and Specular for a Model?

Started by
2 comments, last by Starnick 11 years, 6 months ago
I'm a beginner in XNA, trying my luck at a basic 3D game.

I have some very talented 3D modellers backing me, and while I have on issue importing the .fbx files (the models themselves) into my basic 3D universe in XNA, I have no idea how include the normal maps, diffuse, and specular that they've included with their models.

The normal, diffuse and specular are all in .tga image file format, and I don't know how I can add those to the drawing of my model.

Right now my code for drawing the 3D object is as follows:

[source lang="csharp"] private void DrawObject(Model spaceStation, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in spaceStation.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}[/source]
Advertisement
Two things need to happen:

1. You need an Effect that supports normal mapping. The default BasicEffect in XNA doesn't handle normal or specular maps, just diffuse.

2. You need to have those extra textures go through your content pipeline much like the diffuse texture. And set them to your effect when you're rendering your model.

I recall back when XNA 3.0 was released, the FBX importer was enhanced to allow for multiple textures. See this blog post. Also there is an official normal mapping tutorial from the app hub website that uses the process described in the blog post.

Two things need to happen:

1. You need an Effect that supports normal mapping. The default BasicEffect in XNA doesn't handle normal or specular maps, just diffuse.



How can I do just the diffuse then with the BasicEffect? All the tutorials for BasicEffect I've found only use Diffuse as a DiffuseColor Vector. I actually have an image map for it, which I can't find resources on how to use with BasicEffect.

Also, if I need an effect other than BasicEffect, where can I find resources for it?

I checked out the Normal Mapping example on MSDN, the one with the lizard. Looks mighty complicated.
Take a look at the MSDN documentation for BasicEffect. To enable diffuse textures, you need to set "TexturesEnabled" to true and set the diffuse map (should be a texture2d) to "Texture".

This topic is closed to new replies.

Advertisement