Wednesday, August 19, 2009

Fun and Games with Translucent Entities

I've been spending a lot of time working on translucent entity depth sorting. The sorting itself is trivial, it's an already solved problem: just store translucent entities in a separate list (not with cl_visedicts), calc the distance from the viewpoint (no need to sqrt it) and qsort the result (if there's only 1 or 2 then you can skip the qsort). You could alternatively do something nice with a BSP tree walk, but the qsort method is gonna be faster and simpler in most cases where not every visleaf has a translucent entity in it. The consequences in terms of DirectQ's current rendering structure are however quite appalling. To keep the code mostly simpler, DirectQ (and MHQuake before it) have always merged inline brushmodels (doors, plats, etc) with the main world texturechains, and just drawn everything in a single pass. That won't work with translucent inline brushmodels (windows, etc) as it breaks the sorting and draws them out-of-order from other entities. So the end result is that I'm gonna need to implement something similar to original GLQuake, which means yet another different entity drawing function.

If instanced brushmodels (health and ammoboxes) didn't exist this wouldn't be such a big deal, but right now it's annoying me. I almost cracked and started work on one of my longer term goals, which is to implement a common in-memory format for all model types, but in the end decided that the inevitable delay isn't worth it. I'll live with ugly code for 1.7, and keep the nicer solution in mind for the future.

0 comments: