|
基于LOD的大规模真实感室外场景实时渲染技术的初步研究 part II&III(2) Begin Push the root node to the cur_Queue level = 0 Loop Not reach the Full resolution) { For Each Quad-Tree Node in Cur_Queue { If(Node is not inside the view frustum) { Simple Skip this Node } else if(level = Full Resolution level –1 ) { Draw The Node } else { For Each Sub-Node in this Node Check dependcy If(SubNodeCanSubdivid() and SubNodeNeedActive()) { Push this sub Node to Next_level_Queue Set this sub Node flag to VS_ACTIVE } Else { Set this sub Node flag to VS_Disable }End if End for If No sub Node is active { Disable this Node Set all four sub-node flag to VS_DISABLE Draw the Node } else if Some Sub-Node is active { Draw the Node }End if }End if } End for Swap (cur_Queue,Next_level_Queue); level = next level }End Loop End Function Function NodeCanSubdivid as BOOL Begin Check the four Neighbor Node. If All Neighbor Node is Active return TRUE Else return FALSE End If End Function 6. 优化 上面介绍的算法在理论上是比较严谨的,但是稍微显的有些复杂,同时速度也不是十分的快。下面,我将对它进行一些优化和简化。 在上面的算法中,当一个节点的四个子节点中有一部分被分割,另一部分不被分割的时候,给我们渲染带来很大的麻烦,而且每处理一个节点的时候,我们都要检查四个子节点,比较麻烦。为此参照[参考文献13]给出如下规则:当一个节点的四个子节点中任何一个需要继续分割的时候,四个子节点都进行分割。在本文的程序里,这个规则进一步成:一个节点需要分割的时候,就把其四个子节点都生成并放入到下一层次的队列中去。 按照这种简化的思想,图4.4 中的标记数组对应的地形网格最终将如图4.10所示。对比图4.4右图,我们发现其实简化后的算法生成的地形细节更多,也就是说需要绘制更多的三角形。但是由于需要判断的条件少的多,因此在运速度上,反而是简化后的算法要更占有优势。 图4.10(图4.4 )中的标记数组对应地形的简化生成算法 下面我给出优化后的伪代码,对比上面的算法,它显得更加的简洁了。 Function GenerateMesh
|