1 | #include "RenderSimulator.h"
|
---|
2 | #include "KdTree.h"
|
---|
3 | #include "ViewCellBsp.h"
|
---|
4 | #include "ViewCell.h"
|
---|
5 |
|
---|
6 | RenderSimulator::RenderSimulator()
|
---|
7 | {}
|
---|
8 |
|
---|
9 | RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed):
|
---|
10 | mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed)
|
---|
11 | {
|
---|
12 | }
|
---|
13 |
|
---|
14 | /*****************************************************
|
---|
15 | * class ViewCellRenderSimulator implementation *
|
---|
16 | *****************************************************/
|
---|
17 |
|
---|
18 | BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost,
|
---|
19 | float vcOverhead,
|
---|
20 | float moveSpeed,
|
---|
21 | BspTree *bspTree):
|
---|
22 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
23 | {
|
---|
24 | }
|
---|
25 |
|
---|
26 | Real BspViewCellRenderSimulator::SimulateRendering()
|
---|
27 | {
|
---|
28 | Real renderTime = 0;
|
---|
29 |
|
---|
30 | // overhead for loading the PVS of the view cells
|
---|
31 | float loadPvsOverhead = 0;
|
---|
32 |
|
---|
33 | // probability that view point lies in a view cell
|
---|
34 | float pInVcTotal = 0;
|
---|
35 |
|
---|
36 | // total probability that a view cell border is crossed
|
---|
37 | float pCrossVcTotal = 0;
|
---|
38 |
|
---|
39 | // collect all view cells
|
---|
40 | ViewCellContainer viewCells;
|
---|
41 | mBspTree->CollectViewCells(viewCells);
|
---|
42 |
|
---|
43 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
44 |
|
---|
45 | // surface area substitute for probability
|
---|
46 | PolygonContainer geom;
|
---|
47 |
|
---|
48 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
49 | {
|
---|
50 | // compute view cell area
|
---|
51 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
52 | const float area = Polygon3::GetArea(geom);
|
---|
53 | CLEAR_CONTAINER(geom);
|
---|
54 |
|
---|
55 | // area substitute for view point probability
|
---|
56 | float pInVc = area;
|
---|
57 |
|
---|
58 | // compute render time of PVS times probability that view point is in view cell
|
---|
59 | renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
60 |
|
---|
61 | // probability that a view cell border is crossed
|
---|
62 | float pCrossVc = area;
|
---|
63 |
|
---|
64 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
65 |
|
---|
66 | pInVcTotal += pInVc;
|
---|
67 | pCrossVcTotal += pCrossVc;
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | renderTime /= pInVcTotal;
|
---|
72 | loadPvsOverhead /= pCrossVcTotal;
|
---|
73 |
|
---|
74 | //Debug << "render time without overhead: " << renderTime * 1e-3 << endl;
|
---|
75 |
|
---|
76 | return renderTime + loadPvsOverhead;
|
---|
77 | }
|
---|
78 |
|
---|
79 | Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
80 | float objRenderTime) const
|
---|
81 | {
|
---|
82 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /********************************************************
|
---|
86 | * class KdLeafRenderSimulator implementation *
|
---|
87 | *******************************************************/
|
---|
88 |
|
---|
89 | KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
|
---|
90 | float vcOverhead,
|
---|
91 | float moveSpeed,
|
---|
92 | KdTree *kdTree):
|
---|
93 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
94 | {
|
---|
95 | }
|
---|
96 |
|
---|
97 | Real KdViewCellRenderSimulator::SimulateRendering()
|
---|
98 | {
|
---|
99 | //mKdTree->CollectLeavesPvs();
|
---|
100 |
|
---|
101 | // total render time
|
---|
102 | Real renderTime = 0;
|
---|
103 | // overhead for loading a view cell
|
---|
104 | float loadPvsOverhead = 0;
|
---|
105 |
|
---|
106 | // probability that view point lies in a view cell
|
---|
107 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
108 |
|
---|
109 | // total probability that a view cell border is crossed
|
---|
110 | float pCrossVcTotal = 0;
|
---|
111 |
|
---|
112 | vector<KdLeaf *> leaves;
|
---|
113 | mKdTree->CollectLeaves(leaves);
|
---|
114 |
|
---|
115 | AxisAlignedBox3 box;
|
---|
116 |
|
---|
117 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
118 |
|
---|
119 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
120 | {
|
---|
121 | box = mKdTree->GetBox(*it);
|
---|
122 |
|
---|
123 | // volume substitute for view point probability
|
---|
124 | float pInVc = 0;
|
---|
125 |
|
---|
126 | if (0)
|
---|
127 | pInVc = box.GetVolume();
|
---|
128 | else
|
---|
129 | pInVc = box.SurfaceArea();
|
---|
130 |
|
---|
131 | // probability that a view cell border is crossed
|
---|
132 | const float pCrossVc = box.SurfaceArea();
|
---|
133 |
|
---|
134 | renderTime += pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
135 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
136 |
|
---|
137 | pInVcTotal += pInVc;
|
---|
138 | pCrossVcTotal += pCrossVc;
|
---|
139 | }
|
---|
140 |
|
---|
141 | renderTime /= pInVcTotal;
|
---|
142 | loadPvsOverhead /= pCrossVcTotal;
|
---|
143 |
|
---|
144 | return renderTime + loadPvsOverhead;
|
---|
145 | }
|
---|
146 |
|
---|
147 | Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
148 | float objRenderTime) const
|
---|
149 | {
|
---|
150 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
151 | } |
---|