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 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
51 | CLEAR_CONTAINER(geom);
|
---|
52 |
|
---|
53 | const float area = Polygon3::GetArea(geom);
|
---|
54 | // area substitute for view point probability
|
---|
55 | float pInVc = area;
|
---|
56 |
|
---|
57 | // compute render time of PVS times probability that view point is in view cell
|
---|
58 | renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
59 |
|
---|
60 | // probability that a view cell border is crossed
|
---|
61 | float pCrossVc = area;
|
---|
62 |
|
---|
63 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
64 |
|
---|
65 | pInVcTotal += pInVc;
|
---|
66 | pCrossVcTotal += pCrossVc;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | renderTime /= pInVcTotal;
|
---|
71 | loadPvsOverhead /= pCrossVcTotal;
|
---|
72 |
|
---|
73 | //Debug << "render time without overhead: " << renderTime * 1e-3 << endl;
|
---|
74 |
|
---|
75 | return renderTime + loadPvsOverhead;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
79 | float objRenderTime) const
|
---|
80 | {
|
---|
81 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /********************************************************
|
---|
85 | * class KdLeafRenderSimulator implementation *
|
---|
86 | *******************************************************/
|
---|
87 |
|
---|
88 | KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
|
---|
89 | float vcOverhead,
|
---|
90 | float moveSpeed,
|
---|
91 | KdTree *kdTree):
|
---|
92 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
93 | {
|
---|
94 | }
|
---|
95 |
|
---|
96 | Real KdViewCellRenderSimulator::SimulateRendering()
|
---|
97 | {
|
---|
98 | //mKdTree->CollectLeavesPvs();
|
---|
99 |
|
---|
100 | // total render time
|
---|
101 | Real renderTime = 0;
|
---|
102 | // overhead for loading a view cell
|
---|
103 | float loadPvsOverhead = 0;
|
---|
104 |
|
---|
105 | // probability that view point lies in a view cell
|
---|
106 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
107 |
|
---|
108 | // total probability that a view cell border is crossed
|
---|
109 | float pCrossVcTotal = 0;
|
---|
110 |
|
---|
111 | vector<KdLeaf *> leaves;
|
---|
112 | mKdTree->CollectLeaves(leaves);
|
---|
113 |
|
---|
114 | AxisAlignedBox3 box;
|
---|
115 |
|
---|
116 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
117 |
|
---|
118 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
119 | {
|
---|
120 | box = mKdTree->GetBox(*it);
|
---|
121 |
|
---|
122 | // volume substitute for view point probability
|
---|
123 | float pInVc = 0;
|
---|
124 |
|
---|
125 | if (0)
|
---|
126 | pInVc = box.GetVolume();
|
---|
127 | else
|
---|
128 | pInVc = box.SurfaceArea();
|
---|
129 |
|
---|
130 | // probability that a view cell border is crossed
|
---|
131 | const float pCrossVc = box.SurfaceArea();
|
---|
132 |
|
---|
133 | renderTime += pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
134 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
135 |
|
---|
136 | pInVcTotal += pInVc;
|
---|
137 | pCrossVcTotal += pCrossVc;
|
---|
138 | }
|
---|
139 |
|
---|
140 | renderTime /= pInVcTotal;
|
---|
141 | loadPvsOverhead /= pCrossVcTotal;
|
---|
142 |
|
---|
143 | return renderTime + loadPvsOverhead;
|
---|
144 | }
|
---|
145 |
|
---|
146 | Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
147 | float objRenderTime) const
|
---|
148 | {
|
---|
149 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
150 | } |
---|