有多少(低多边形)模型可以XNA处理? [英] How many (low poly) models can XNA handle?

查看:150
本文介绍了有多少(低多边形)模型可以XNA处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,下面是一个模糊的问题,但我打,我没有在XNA预见的性能问题。



我有一个低多边形模型(它有18个面和14个顶点),我试图绘制到屏幕的次数(高!)号码。我得到了60 FPS(一个体面的机器上),直到我画这个模型5000+倍。我是不是要求太多了吗?我非常想翻一番,至少或三倍数量(10-15k)。



我对实际绘制模型的代码如下。我试图消除来自绘制循环尽可能多的计算,有没有更多的,我可以从中挤压,或更好的替代品一起



请注意:tile.Offset初始化,并不是每一个周期计算一次。

 的foreach(在瓷砖VAR瓦)
{
VAR基于myModel = tile.Model;
矩阵[] =变换新的Matrix [myModel.Bones.Count]
myModel.CopyAbsoluteBoneTransformsTo(转换);

的foreach(ModelMesh网在myModel.Meshes)
{
的foreach(在mesh.Effects BasicEffect效果​​)
{
// effect.EnableDefaultLighting( );
effect.World =转换[mesh.ParentBone.Index]
* Matrix.CreateTranslation(tile.Offset);
effect.View = CameraManager.ViewMatrix;
effect.Projection = CameraManager.ProjectionMatrix;
}
mesh.Draw();
}
}


解决方案

您'重新很清楚一下批处理限制即可。请参见本演示并的this答案并的有关详细信息,这个答案。简单地说:有多少绘制调用,您可以提交到GPU每秒限制



批处理限制是基于CPU的限制,所以你大概看到,一旦你得到你的5000+型号你的CPU被盯住。更糟糕的是,当你的游戏做其他计算,这将减少提供给提交这些批次的CPU时间。



(而且需要注意的是,相反是很重要的,你是几乎可以肯定的的击球GPU的限制。没有必要担心目复杂呢。)



有许多方法来减少你的批次数。平截扑杀就是其中之一。也许是最好的之一,你的情况是persue 几何实例中,这可以让你在一个单一的一批画多个模型。下面是做到这一点的 XNA样品



更妙的是,如果是静态几何,可你只是烤所有到一个或几个大网格?


I'm aware that the following is a vague question, but I'm hitting performance problems that I did not anticipate in XNA.

I have a low poly model (It has 18 faces and 14 vertices) that I'm trying to draw to the screen a (high!) number of times. I get over 60 FPS (on a decent machine) until I draw this model 5000+ times. Am I asking too much here? I'd very much like to double or triple that number (10-15k) at least.

My code for actually drawing the models is given below. I have tried to eliminate as much computation from the draw cycle as possible, is there more I can squeeze from it, or better alternatives all together?

Note: tile.Offset is computed once during initialisation, not every cycle.

foreach (var tile in Tiles)
        {
            var myModel = tile.Model;
            Matrix[] transforms = new Matrix[myModel.Bones.Count];
            myModel.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in myModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    // effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] 
                                 * Matrix.CreateTranslation(tile.Offset);
                    effect.View = CameraManager.ViewMatrix;
                    effect.Projection = CameraManager.ProjectionMatrix;
                }
                mesh.Draw();
            }
        }

解决方案

You're quite clearly hitting the batch limit. See this presentation and this answer and this answer for details. Put simply: there is a limit to how many draw calls you can submit to the GPU each second.

The batch limit is a CPU-based limit, so you'll probably see that your CPU gets pegged once you get to your 5000+ models. Worse still, when your game is doing other calculations, it will reduce the CPU time available to submit those batches.

(And it's important to note that, conversely, you are almost certainly not hitting GPU limits. No need to worry about mesh complexity yet.)

There are a number of ways to reduce your batch count. Frustrum culling is one. Probably the best one to persue in your case is Geometry Instancing, this lets you draw multiple models in a single batch. Here is an XNA sample that does this.

Better still, if it's static geometry, can you simply bake it all into one or a few big meshes?

这篇关于有多少(低多边形)模型可以XNA处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆