在opengl中绘制体素(立方体)最有效的方法是什么?

发布于 2024-09-25 08:42:19 字数 356 浏览 4 评论 0原文

我想使用 opengl 绘制体素,但似乎不支持它。我制作了一个立方体绘制函数,有 24 个顶点(每个面 4 个顶点),但当您绘制 2500 个立方体时,它会降低帧速率。我希望有更好的方法。理想情况下,我只想将位置、边缘尺寸和颜色发送到显卡。我不确定是否可以通过使用 GLSL 将指令编译为片段着色器或顶点着色器的一部分来做到这一点。

我搜索了谷歌并发现了点精灵和广告牌精灵(同一件事?)。这些可以用作更快地绘制立方体的替代方法吗?如果我使用 6 个,每张脸一个,那么向显卡发送的信息似乎会少得多,并有望获得更好的帧速率。

另一种想法是也许我可以使用一个drawelements调用来绘制多个立方体?

也许有一种我不知道的更好的方法?任何帮助表示赞赏。

I would like to draw voxels by using opengl but it doesn't seem like it is supported. I made a cube drawing function that had 24 vertices (4 vertices per face) but it drops the frame rate when you draw 2500 cubes. I was hoping there was a better way. Ideally I would just like to send a position, edge size, and color to the graphics card. I'm not sure if I can do this by using GLSL to compile instructions as part of the fragment shader or vertex shader.

I searched google and found out about point sprites and billboard sprites (same thing?). Could those be used as an alternative to drawing a cube quicker? If I use 6, one for each face, it seems like that would be sending much less information to the graphics card and hopefully gain me a better frame rate.

Another thought is maybe I can draw multiple cubes using one drawelements call?

Maybe there is a better method altogether that I don't know about? Any help is appreciated.

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

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

发布评论

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

评论(3

糖粟与秋泊 2024-10-02 08:42:19

用立方体绘制体素几乎总是错误的方法(例外情况是光线追踪)。您通常想要做的是将数据放入 3D 纹理并根据相机位置渲染切片。请参阅此页面: https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch39.html ,您可以通过搜索“体积渲染 GPU”找到其他技术。

编辑:在写上面的答案时,我没有意识到OP很可能对《我的世界》如何做到这一点感兴趣。有关加速 Minecraft 风格光栅化的技术,请查看用于渲染大量立方体的剔除技术。尽管随着图形硬件的最新进步,通过光线追踪渲染 Minecraft 可能会成为现实。

Drawing voxels with cubes is almost always the wrong way to go (the exceptional case is ray-tracing). What you usually want to do is put the data into a 3D texture and render slices depending on camera position. See this page: https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch39.html and you can find other techniques by searching for "volume rendering gpu".

EDIT: When writing the above answer I didn't realize that the OP was, most likely, interested in how Minecraft does that. For techniques to speed-up Minecraft-style rasterization check out Culling techniques for rendering lots of cubes. Though with recent advances in graphics hardware, rendering Minecraft through raytracing may become the reality.

拥有 2024-10-02 08:42:19

What you're looking for is called instancing. You could take a look at glDrawElementsInstanced and glDrawArraysInstanced for a couple of possibilities. Note that these were only added as core operations relatively recently (OGL 3.1), but have been available as extensions quite a while longer.

nVidia's OpenGL SDK has an example of instanced drawing in OpenGL.

一抹苦笑 2024-10-02 08:42:19

首先,您确实应该使用 GLSL 查看 OpenGL 3+。这已经成为相当长一段时间的标准。其次,大多数 Minecraft 风格的实现都在 CPU 端使用网格创建。该技术涉及查看所有块位置并创建一个渲染所有暴露面的三角形的顶点缓冲区对象。 VBO 仅在体素发生变化时生成,并在帧之间保持不变。理想的实现是将相同纹理的共面面组合成更大的面。

First you really should be looking at OpenGL 3+ using GLSL. This has been the standard for quite some time. Second, most Minecraft-esque implementations use mesh creation on the CPU side. This technique involves looking at all of the block positions and creating a vertex buffer object that renders the triangles of all of the exposed faces. The VBO is only generated when the voxels change and is persisted between frames. An ideal implementation would combine coplanar faces of the same texture into larger faces.

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