user1760770
user1760770

Reputation: 395

Opengl low FPS when looking certain direction

I'm drawing surface composed of thousands of cubes. However when I'm looking in positive Z direction - that's where the light is, I get low fps and artifacts. This is how it looks when I'm looking in negative Z direction: 1 This is how it looks when I'm looking in positive Z direction, also drops fps noticeably: 1

Upvotes: 0

Views: 331

Answers (2)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

How bad is this dip in performance? If you do a Z-only pre-pass of your geometry, skipping writes to the color buffer (and using a very simple pass-through fragment shader) you can improve performance greatly in situations where you have poorly-ordered/unsorted geometry and are fill-rate limited. This only helps when you are doing complicated fragment processing, however; it introduces twice the vertex transform overhead since you basically draw everything twice. Your situation could be either vertex or fragment bound, since composing surfaces of cubes is not exactly the most efficient way of rendering large planar surfaces.

My other suggestion, since you mention rendering a scene composed of "thousands of cubes" would be to implement something akin to voxel collapsing. All of your cubes in this example appear to be in the same plane, you can easily replace the faces for a collection of such cubes with fewer faces that combine adjacent cubes. Minecraft does this, by periodically re-meshing dynamically updated portions of the scene using a greedy meshing algorithm.

Of course, spatial partitioning is another issue, but I assume you already have some sort of system in-place?

Upvotes: 0

Jean-Simon Brochu
Jean-Simon Brochu

Reputation: 950

You are probably dependent of the order in which your cubes are rendered. That would explain why there is a difference between looking +Z or -Z. When rendering back to front, EVERY fragment of every cube is rendered. When rendering front to back with depth test, most fragments will be discarded. As for the artefacts you are seeing, could be Z-fighting, but that's a long shot.

Upvotes: 3

Related Questions