views:

468

answers:

1

UPDATE 2: It now appears this is more of a modelling issue than a programming one. Whoops.

I'm new to XNA development, and despite my C# experience, I've been stuck at one spot for going on two days now.

The situation: I've created a model in 3D Studio Max 2010 which uses two materials, both are of type DirectX Shader. The model exports to FBX without error and Visual Studio compiles it properly. When I ran the Draw() method initially, it threw an exception on the 'BasicEffect' portion of one of my loops, demonstrating (at least to me) that it was loading the .fx file correctly, which must be embedded in the FBX file or something.

The problem: When using the following code

    foreach (ModelMesh mesh in map.Meshes)
    {
        foreach (Effect effect in mesh.Effects)
        {
            effect.CurrentTechnique = effect.Techniques["DefaultTechnique"];
            effect.Begin();
            effect.Parameters["World"].SetValue(Matrix.CreateTranslation(Vector3.Zero));
            effect.Parameters["View"].SetValue(ActiveCamera.ViewMatrix);
            effect.Parameters["Projection"].SetValue(ActiveCamera.ProjectionMatrix);
            effect.Parameters["WorldViewProj"].SetValue(Matrix.Identity * ActiveCamera.ProjectionMatrix);
            effect.Parameters["WorldView"].SetValue(Matrix.Identity * ActiveCamera.ViewMatrix);

            foreach (EffectPass ep in effect.CurrentTechnique.Passes)
            {
                ep.Begin();
                // something goes here?
                ep.End();
            }

            effect.End();
        }

        mesh.Draw();
    }

The only thing that happens is a white box appears covering the bottom half of the screen, regardless of camera position or angle. I got the name of the effect parameters of the default.fx file specified in Max (it's at [program files]\autodesk\3ds Max 2010\maps\fx).

I get the feeling I'm setting one or all of these incorrectly. I've tried to look up tutorials and follow their code, however none of it seems to work for my model.

Any help or ideas?

UPDATE: By making these changes:

    effect.Parameters["WorldViewProj"].SetValue(Matrix.CreateTranslation(Vector3.Zero) * ActiveCamera.ViewMatrix * Conductor.ActiveCamera.ProjectionMatrix);
effect.Parameters["WorldView"].SetValue(Matrix.CreateTranslation(Vector3.Zero) * ActiveCamera.ViewMatrix);

The model was able to draw. However, everything is completely white :(

+1  A: 

Unfortunately, especially without seeing your shader and/or knowing what error it is that you're getting, it's going to be pretty difficult to figure out what's wrong here. There are a number of things that could be going wrong.

My suggestion is to start with a simpler test. Make a box, apply a very simple shader ... and make that render. Then, add some parameter that (for example) multiplies the red component of the pixel shader by the amount passed in. And make that render successfully.

By simplifying the problem set, you are figuring out the nuances of the shaders that max exports and how you set the properties. At some point, you'll realize what you're doing wrong and will be able to apply that to your more complex shader.

I'm quite interested in hearing how this goes ... make sure you comment on this once you've fixed it so I see the outcome. Good luck! :-)

Joel Martinez
After more tinkering last night, I found that my code was working more or less and that it was a model issue, not a coding one. So once I figure out how to properly do that, I'll post the results :P
Eric Smith