Tuesday, October 27, 2009

Not too much done today

Been writing code all day in work, so I didn't feel like doing much DirectQ when I got home. Made a few changes though; I've replaced the previous r_infiniteperspective cvar, and the whole handling of the projection matrix, with an older technique from a previous MHQuake. I now measure the size of the map at load time (basically while building surface verts) and set a dynamic far clipping plane depending on that, which is upper bounded to 32768 and lower bounded to 2048. I've also reworked the sky slightly so that it's properly compatible and so that fog looks right (and consistent) on it at variable far clipping distances.

So this means that DirectQ will no longer use an infinite projection matrix, but I'm wondering how much of a big deal it is. It's something that's really only practically useful for shadow volumes, and the main reason I had one was to allow me to draw the sky at an arbitrary distance without having to worry about overlapping geometry. Now that I've fixed that, and given that I don't have shadow volumes, I'm not losing too much sleep over it.

Of course, the real reason to do this is for better compatibility with 3D cards that may barf on infinity. It's also why non-infinite is the new way.

The beauty of this approach is that the far clipping plane will now dynamically scale depending on the size of the map (I assume that maps with dimensions > 32768 will be reasonably partitioned so that you don't see the full distance at any one time), so it handles arbitrary sized maps from small to huge with equal ease, and with no user intervention required. A tweak might be to use the visdata in the map to evaluate the max distance that can actually be seen, then build the far clip based on that.

One final thing I've done here is draw the sky at twice the standard far clipping plane, primarily to avoid any "poke-through" situations. It doesn't seem required, (the Z-fail technique used for all sky drawing should prevent it in most cases), but it was trivial to implement and feels right.

Now I really need to get back to the ProQuake messaging system...

0 comments: