Question

Background:

I am creating a game that presents the world in an isometric perspective, achieved by drawing isometric tiles. My current implementation is naive, using the painter's method, drawing from back to front, from bottom to top, using surface blits from tile images.

The Problem:

I'm concerned (maybe unduly so, please let me know if this is the case) about overdraw. Here's a small snapshot of a single layer of tiles:

Overdraw

The areas hi-lit in pink are the areas where the back-to-front, bottom-to-top method blits pixels to the canvas more than once. This is a small and contrived example, but in practice I hope to accomplish something more along the lines of this:

Credit eBoy

(image credit eBoy)

With an image as complex as this, and a tile-based implementation, each screen pixel is drawn to several times before the final image is composited, which feels like it's really inefficient. Since these are just 2D images with, in the end, one-bit alpha masks, there aren't as many concerns as there would be with 3D (e.g. no wasted lighting or transform math) but it still seems there should be a more elegant way of determining whether a pixel should be drawn or not based on whether or not it would be occluded in the final composition.

Solutions?

The best solution I've come up with so far is to:

  • Reverse the drawing order and draw front-to-back, top-to-bottom.
  • Keep a single bit per pixel fake z buffer that records whether or not a pixel has been drawn yet.
  • Only draw a tile if some of the pixels it covers haven't been drawn yet.

Is there a better way to do this? Are blit operations superefficient and I'm tilting at windmills here?

Était-ce utile?

La solution

Windmills. Especially if you're using OpenGL-accelerated SDL2 blits.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top