如何在OpenGL中绘制景观而不使用数百万个三角形?

huangapple go评论74阅读模式
英文:

How to draw a landscape without using millions triangles in opengl?

问题

我已经创建了使用OpenSimplex噪声生成地景的程序(C++/OpenGL),并将其绘制为一个网格(因此我每帧只需调用一次绘制函数)。我正在使用glDrawElements函数。该网格包含1023 * 1023个矩形=1023 * 1023 * 2个三角形,地形看起来像PS1游戏,并且使用了超过500MB的RAM。如何使地形更加平滑(像现代游戏中的地形),而不使用那么多三角形?

编辑:是否可以使用几个不同详细级别的VBO,从最详细的VBO中绘制最近的三角形,从较不详细的VBO中绘制较远的三角形等等?

英文:

I have created the program (C++/OpenGL) which generates landscape using OpenSimplex noise and drawing it as one mesh (so I have to call draw function only once per frame). I am using glDrawElements function. The mesh contains 1023 * 1023 rectangles = 1023 * 1023 * 2 triangles, and the landscape looks like in PS1 games and using over 500 mb of RAM. How can I make smooth landscape (like in modern games) without using so many triangles?

Edit: Would it be effecient to have few VBO's, which are differently detailed, and draw nearest triangles from the most detailed VBO, farer from less detailed etc?

答案1

得分: 6

现代游戏通常使用一系列技术来渲染高质量的场景。

  1. 视锥剔除(舍弃不在屏幕上的三角形)。通常涉及将GEO分割成许多较小的块,当它们不在屏幕上可见时,可以忽略它们。
  2. 地形多分辨率映射(Geo Mip-Mapping)(用较低细节版本替换远处的地形,用高分辨率版本替换近处的地形)。通常只涉及重复使用预定义的一组索引以用于给定的细节层级(其中底层数据保持不变,但索引数据为最高细节层级的每个顶点指定,第二细节层级的每个其他顶点指定,第三细节层级的每个第四个顶点指定,依此类推)。
  3. 曲面细分着色器(Tessellation shaders)(在一些地形上添加更多的三角形以平滑粗糙的边缘)。
  4. 凹凸/法线贴图(或其他逐像素光照效果)。使用纹理数据为正在渲染的三角形添加更多的表面变化。

基本上,如果你想要平滑的地形,你需要添加以下之一:

  1. 更多的三角形,或者
  2. 额外的纹理数据(例如法线或置换贴图)。

关键是尽量减少在给定帧渲染所需的三角形数量,而不是担心总共有多少三角形。

附注:1024 * 1024 * vec3 代表18MB的顶点数据(+18MB的法线数据,+24MB的索引数据)。如今,GPU有几GB的内存可用,所以几MB并不是什么大问题。再次强调,地形多分辨率映射将将索引数据的量降至最低。

英文:

Modern games typically use a series of techniques to render high quality scenery.

  1. View-Frustum culling (throw away triangles that are not on screen). This usually involves splitting your GEO into a number of smaller chunks that can be ignored when they are not visible on screen.
  2. Geo Mip-Mapping (Replace far away geo with lower LOD versions, and near GEO with high res versions). Often this just involves re-using a predefined set of indices for given LODS (where the underlying vertex data stays the same, but the index data specifies every vert for the highest lod, every other vertex for the second lod, every 4th vertex for the 3rd lod, and so on)
  3. Tessellation shaders (add more triangles to a bit of GEO to smooth off the rough edges)
  4. Bump/Normal mapping (or other per-pixel lighting effects). Use texture data to add more surface variation to a triangle being rendered.

Basically, if you want smooth GEO, you're going to need to add either

  1. more triangles, or
  2. additional texture data (e.g. normal or displacement maps).

The trick is minimising the amount the triangles you need to render a given frame, rather than worrying about how many triangles you have in total.

p.s. 1024 * 1024 * vec3 is 18Mb of vertex data (+18Mb of normal data, +24Mb of index data). These days we have Gigs of ram available for the GPU, so a few megs is not that big of a deal. Again, Geo-Mipmapping will reduce the amount of index data down to a minimum.

huangapple
  • 本文由 发表于 2023年7月3日 14:50:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602441.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定