在 XNA 问题中使用 3D Studio Max DirectX 着色器

发布于 2024-08-15 19:49:06 字数 1844 浏览 8 评论 0原文

更新2:现在看来,这更多的是一个建模问题,而不是编程问题。哎呀。

我是 XNA 开发的新手,尽管我有 C# 经验,但两天以来我一直停留在一个地方。

情况:我在 3D Studio Max 2010 中创建了一个模型,它使用两种材质,均为 DirectX Shader 类型。模型导出到 FBX 时没有错误,并且 Visual Studio 可以正确编译它。当我最初运行 Draw() 方法时,它在其中一个循环的“BasicEffect”部分抛出异常,表明(至少对我而言)它正在正确加载 .fx 文件,该文件必须嵌入到 FBX 中文件什么的。

问题: 使用以下代码时,

    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();
    }

唯一发生的事情是出现一个白色框,覆盖屏幕的下半部分,无论相机位置或角度如何。我获得了 Max 中指定的 default.fx 文件的效果参数名称(位于 [program files]\autodesk\3ds Max 2010\maps\fx)。

我感觉我错误地设置了其中一项或全部。我尝试查找教程并遵循他们的代码,但似乎都不适合我的模型。

有什么帮助或想法吗?

更新: 通过进行这些更改:

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

模型能够进行绘图。然而,一切都是完全白色的:(

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2024-08-22 19:49:06

不幸的是,特别是在没有看到你的着色器和/或不知道你遇到了什么错误的情况下,很难找出这里出了什么问题。有很多事情可能会出错。

我的建议是从更简单的测试开始。制作一个盒子,应用一个非常简单的着色器......然后进行渲染。然后,添加一些参数(例如)将像素着色器的红色分量乘以传入的数量。并使渲染成功。

通过简化问题集,您可以弄清楚最大导出的着色器的细微差别以及如何设置属性。在某些时候,您会意识到自己做错了什么,并且能够将其应用到更复杂的着色器中。

我很想听听这是如何进行的......修复后请务必对此发表评论,以便我看到结果。祝你好运! :-)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文