[243] | 1 | //---- initialisation
|
---|
| 2 | Stack.Push(kDTree.Root);
|
---|
| 3 | //---- while there are some nodes in the stack or the query queue
|
---|
| 4 | while (!Stack.Empty() $||$ !QueryQueue.Empty()) {
|
---|
| 5 | //---- PART 1: processing finished occlusion queries
|
---|
| 6 | while (!QueryQueue.Empty() &&
|
---|
| 7 | (ResultAvailable(QueryQueue.Front()) $||$ Stack.Empty())) {
|
---|
| 8 | if (!ResultAvailable(QueryQueue.Front())) {
|
---|
| 9 | //--- result is not available and the stack is empty
|
---|
| 10 | //--- check if we can do some conservative decision
|
---|
| 11 | N = QueryQueue.GetLeastCostNode();
|
---|
| 12 | if (N.renderingCost < MaxRenderCost) {
|
---|
| 13 | RenderSubtree(N);
|
---|
| 14 | QueryQueue.DequeLeastCostNode();
|
---|
| 15 | //-- we do not change N's visibility classfication -
|
---|
| 16 | //-- N remains in the cut for the next frame
|
---|
| 17 | } else
|
---|
| 18 | //-- wait for the availability of the result
|
---|
| 19 | while (!QueryQueue.ResultAvailable) Wait();
|
---|
| 20 | } else {
|
---|
| 21 | N = QueryQueue.Dequeue();
|
---|
| 22 | //-- check the result of the query
|
---|
| 23 | if ( N.visiblePixels $>$ VisibilityThreshold ) {
|
---|
| 24 | N.visibility = VISIBLE;
|
---|
| 25 | if (IsLeaf(N))
|
---|
| 26 | Render(N);
|
---|
| 27 | else {
|
---|
| 28 | //-- pull down
|
---|
| 29 | Stack.Push(FarChild(N)); Stack.Push(CloseChild(N));
|
---|
| 30 | }
|
---|
| 31 | } else {
|
---|
| 32 | N.visibility = INVISIBLE;
|
---|
| 33 | //-- pull up
|
---|
| 34 | PullUpInvisibility(N);
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | //---- PART 2: kd-tree traversal
|
---|
| 40 | if (!Stack.Empty()) {
|
---|
| 41 | N = Stack.Pop();
|
---|
| 42 | N.lastVisited = frameID;
|
---|
| 43 | if (InsideViewFrustum(N)) {
|
---|
| 44 | //-- skip testing of all nodes above the cut
|
---|
| 45 | if (!IsAboveTheCut(N)) {
|
---|
| 46 | IssueOcclustionQuery(N); QueryQueue.Enqueue(N);
|
---|
| 47 | if (WasVisible(N) $&&$ IsLeaf(N))
|
---|
| 48 | Render(N);
|
---|
| 49 | else {
|
---|
| 50 | //-- go down the kD-tree
|
---|
| 51 | Stack.Push(FarChild(N)); Stack.Push(CloseChild(N));
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|