Saturday, February 28, 2009

tac: Converging on a graphics solution

After weeks of experimentation, I think I've converged on a best solution (for now): Most of the game will be drawn with opaque triangles (fast), which should work great for most map-elements that have simple shape (such as floor tiles, walls, boxes, hedges, etc.). Then in the second pass, we'll draw alpha-masked sprites using alpha testing. The number of alpha-masked sprites should be minimal (such as units, enemies, and some decorations) to maintain 30+ FPS. We'll need depth testing to make this 2-pass drawing work, so no need to sort on my own.

Another detail, thanks to some Apple developer forum folks: Put opaque and alpha sprites in different atlases, and minimize their size. Opaque textures don't need alpha channel!

With the opaque sprites, we can probably afford more than 2 triangles per sprite. This will allow for more interesting shapes than quadrangles. Of course, at a certain point, it'll be cheaper to use alpha-masking than a ton of triangles. I should probably write a tool to do mesh simplification in 2D (start with a highly detailed triangulation where each pixel is triangulated), with tweakable thresholds, and then let artists tweak the 2D triangulation manually.

Spatial partitioning will still be necessary to cull the number of vertices we send. This affects FPS greatly.

All this is what the tech note suggests, and it sounds like my only real option. There just doesn't seem to be a fast way to raster tons of alpha-masked sprites using OpenGL ES.

No comments: