OpenGL: Managing and editing large amounts of line strips

為{幸葍}努か 提交于 2019-12-05 21:35:36

Chapter 12 of the OpenGL SuperBible has a section on "Drawing a lot of Geometry Efficiently", in which they have a demo of millions of blades of grass being animated. This is done by using a single vertex description, the glDrawElementsInstanced method, and a shader to modify each 'instance' stamped out in whatever manner you like (e.g. perturb vertices, scale & rotate, change texture lookup, etc.)

This is very similar to your 'go through all the vbos' loop, except that you would only upload vertices for a single blade of grass, and OpenGL will take care of passing a unique gl_InstanceID to your shader. You can then encode the changes each frame either procedurally, or in a 'texture' that you upload as often as needed. The book has sample code (and it may be available from the web site as well).

Edit: Confirmed that the sample code is in the downloads from the site - look at the src\grass\grass.cpp to see a sample using textures to control grass length, orientation, color, and bend.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!