使用 Libgdx 进行高效的 3D 块渲染 [英] Efficient 3D block rendering with Libgdx

查看:37
本文介绍了使用 Libgdx 进行高效的 3D 块渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我对 3D 编程和 libgdx 还很陌生.我看了一些教程,我已经渲染了我想要的场景.我有一些 1x1x1 的块,使用 ModelBuilder.createRect() 为每个可见的面创建,所以如果另一个块覆盖了这个块的一个面,则没有为此块创建的矩形.也不需要顶部和底部矩形,因为我永远看不到它们(地板除外).所以我想,这是非常有效的.我还启用了 Backface culling 并且我做了 Viewfrustum culling.然而,如果我朝一个方向看,那里有很多块在我的视锥中,FPS 会下降到 15-20.这对我来说还是可以的,因为我的笔记本电脑已经超过 5 年了,它的性能不是最好的,但是 这个答案让我思考.

To start with,I am pretty new to 3D programming and libgdx. I looked at a few tutorials and I already render the scene I want. I have some 1x1x1 blocks, created with ModelBuilder.createRect() for every visible face, so if another block covers a face of this block, there is no rect created for this block. Also the top and bottom rect is not needed, as I can never see them (except for the floor). So I thought, that this is pretty efficient. I also have Backface culling enabled and I do Viewfrustum culling. However, if I look in a direction, where many blocks are in my viewfrustum the FPS go down to 15-20. This is still okay for me, as my laptop is over 5 years old and its performance is not the best, but this answer made me think.

模型构建器仅用于调试".好的,但是我应该如何创建我的盒子?为什么我应该在建模应用程序(如 Blender)中为简单的正方形创建一个 Model?通过这样做,我什至无法剔除被其他块占据的面.所以我的问题是:如何以最有效的方式创建和渲染这些框?

"ModelBuilder is used for debug only". Okay, but how should i then create my boxes? Why should i create a Model in a Modeling app (like Blender), for simple squares? By doing this i couldn't even cull the faces, which are occupied by other blocks. So my question is: How can i create and render those boxes the most efficient way?

推荐答案

ModelBuilder#createRect 将为每个矩形创建一个新模型.当渲染一个(一部分)模型实例时,它意味着一个绘制调用.因此 ModelBuilder#createRect 效率极低.最好将多个矩形组合成一个(a 的一部分)模型.这可以使用:

ModelBuilder#createRect will create a new model for each rectangle. When rendering a (part of a) model instance, it implies a draw call. Therefor ModelBuilder#createRect is extremely inefficient. It is better to combine multiple rectangle into a single (part of a) Model. This can be done using:

modelBuilder.begin();
MeshPartBuilder mpb = modelBuilder.part(....);
mpb.rect(...); // first rect.
mpb.rect(...); // second rect.
// etc.
Model model = modelBuilder.end();

请注意,对于例如,这仍然不够有效.体素引擎.如果您的目标是优化体素,您可能希望在自定义 RenderableProvider 中构建网格(在截锥体剔除和深度排序之后).这是一个例子:https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel

Note that this is still not efficient enough for e.g. a voxel engine. If you are aiming to optimize for voxels, you'll probably want to build the mesh (after frustum culling and depth sorting) in a custom RenderableProvider. Here's an example: https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests/src/com/badlogic/gdx/tests/g3d/voxel

这篇关于使用 Libgdx 进行高效的 3D 块渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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