StrikeAthius
I r an experienced c++ programmer
Posts: 406
I actually considered doing hardware occlusion queries to cull portals. Basically you would render whatever current cell, then render its portals using occlusion queries. If a portal had any fragments that passed the z buffer, you know it is at least partially in view and you can continue the test from there. The only real problem is, you'd have to know the results from 1 batch of portals before being able to do another ply, and I can almost gaurantee there is some kind of performance cost for each batch of occlusion queries (if it is processed on the graphics hardware, there is communication across the bus, which is a bottleneck, and a few portals per test is a very trivial amount of data to process). one cool thing about hardware occlusion queries is it would actually eliminate the need for disabling a sector's adjoins in the case of opening doors. If the cell's objects were rendered alongside the cell itself, the portal culling would automatically take into account the possibility of an object completely blocking a line of sight through a portal; for free. In general, though, it wouldn't be worth it.
I definitely understand where you're coming from, though. All the math and such involved seems like (and can prove to be) a good deal of overhead, but I think in the end it is probably worth it. I'm considering some ideas for speeding up the culling process by reducing the number of portals. Frankly, in the average JK level, there are way more portals than there really need to be. Note: I'm talking about PORTALS not necessarily adjoins. Sector adjoins are critical to maintain convex polyhedra. However, 'cell clusters' could be formed by 'merging' multiple adjacent cells into one group (with the group usually having a concave shape, but this is ok). The optimization comes into play by eating portals that almost always depend on the visibility of another portal.
Consider the following theoretical example:
Take your basic starting sector in JED. Now cleave and delete a square shape from the center of the sector. You've now created 6 portals, when really no matter which way the camera is oriented in the sector, you're pretty much going to get all the cells flagged as visible, yet you are still casting a culling frustum through all 6 portals or whatever. Clustering these cells together would remove a lot of CPU computation and although creating overdraw, the graphics hardware can handle it. The CPU remains free during this saved time to perform pathfinding or script execution or process particles. Even if you were in a hallway connected to this room, chances are almost all of the sectors would still be tested positive for visibility. Now the portal between the hallway and this cluster of cells should be preserved.
I can think of 2 problems straight off the bat, though:
a) the process of actually clustering cells. how do you know which portals
are redundant?
b) concave polyhedra can result in false positives for portals leading out from the cell cluster, resulting in overdraw since none of the geometry actually in that cell cluster can reject portals. however, even eating just 1 portal for every other 1 portal would result in potentially half as many portal culls; and the resulting overdraw would probably be pretty minimal to where it might be worthwhile. exact visibility portal culling requires that the current portal to test be clipped to the current culling frustum (which is not a traditional 6-plane frustum, but has N+2 number of planes, where N is the number of edges of the previously clipped portal polygon) and poly-to-poly clipping is a fairly expensive operation to perform many times per frame (the operation is roughly O(N*M) where N is the number of edges in the clipper polygon, and M is the number of points in the clippee polygon).
[ B A H ]
Bad *** by nature,
Hackers by choice