English 中文(简体)
Using 3D Studio Max DirectX shader in XNA problem
原标题:

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]autodesk3ds Max 2010mapsfx).

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 :(

问题回答

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! :-)





相关问题
copying a texture in xna into another texture

I am loading a Texture2D that contains multiple sprite textures. I would like to pull the individual textures out when I load the initial Texture to store into separate Texture2D objects, but can t ...

XNA Antialias question!

I ve got problems with XNA and antialiasing. I can activate it using graphics.PreferMultiSampling = true; graphics.ApplyChanges(); however - it s only 2x antialiasing. Even if I set ...

Take screen shot in XNA

How can I take a screen shot of the screen in XNA? Is it possible without System.Drawing.Graphics.CopyFromScreen or Win32API? If it s not possible, Is there any way to draw a System.Drawing.Bitmap to ...

XNA .Fbx textures

I m using the standard .fbx importer with custom shaders in XNA. The .fbx model is UV wrapped properly and is textured appropriately when I use BasicEffect. However when I use my custom effect I have ...

Can t install XNA

I m trying to install XNA. When the installation starts I got an error that says "XNA GSE 1.0 refresh requires Visual C# 2005 express edition sp1..." I use Windows 7 and I have Visual Studio 2008 &...

Is there a 3D equivalant to clamp in XNA?

I m building a 3D game but i only plan on using a 2D perspective thus not taking the z axis into the equasion, i want to be able to limit the movement of one of my models so it doesn t move out of the ...

Fetching the vertices from the backbuffer (HLSL) on XNA

Hello and sorry for the obscure title :} I`ll try to explain the best i can. First of all, i am new to HLSL but i understand about the pipeline and stuff that are from the fairy world. What i`m ...

Simple XNA 2d physics library

Working on a 2D project and wanted some recommendations on a simple 2d physics library for use in C# with the XNA framework. I was looking at Farseer or physics2d. Anyone have any other suggestions? ...

热门标签