How to render large number of similar objects?

后端 未结 2 503
误落风尘
误落风尘 2021-01-15 21:04

I have large number of objects (at least 10 000 particles) like triangles, squares, circles or spheres. Actually now I have one object which I render many times. It\'s looks

2条回答
  •  猫巷女王i
    2021-01-15 21:40

    1. Factor out the shader binding and unbinding. Bind the shader once, draw everything that uses that shader, and then unbind it. Group your objects by shader. If you have a more complicated material system, you'll want to draw everything with the same material properties at once (e.g. uniforms like texture and lighting components). While you're at it, leave the vertex attributes bound and only turn them off when you're done. All of this minimizes the number of OpenGL calls you do.

    2. If you can, pack your geometry into optimally-sized VBOs (which should vary by your GPU). I suspect you can pack all of your shapes sequentially into one buffer and then use an offset to pick which one to draw. This will save you a VBO switch.

    3. If you're going to be drawing the same thing lots of times, consider instanced rendering

    4. If you're going to be drawing a lot of things a lot of times, group them into batches of like type.

    5. If you're trying to make a particle system, look into making a GPU particle system. Particle attributes like position and velocity get stored in textures, and then fragment shaders update those attributes once per draw call. After they have been updated, a long list of indices ((u,v) coordinates) is passed in as vertex data, which is used to index into the particle textures to retrieve the data. Each particle is then turned into triangles or quads in the geometry shader, and finally rendered to the screen.

提交回复
热议问题