1 | #include "RenderSimulator.h"
|
---|
2 | #include "KdTree.h"
|
---|
3 | #include "ViewCellBsp.h"
|
---|
4 | #include "ViewCell.h"
|
---|
5 | #include "VspBspTree.h"
|
---|
6 | #include "ViewCellsManager.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 |
|
---|
12 | void SimulationStatistics::Print(ostream &app) const
|
---|
13 | {
|
---|
14 | app << "===== Render Simulation statistics ===============\n";
|
---|
15 |
|
---|
16 | app << setprecision(4);
|
---|
17 |
|
---|
18 | app << "#N_CTIME ( Simulation time [s] )\n" << Time() << " \n";
|
---|
19 |
|
---|
20 | app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n";
|
---|
21 |
|
---|
22 | app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n";
|
---|
23 |
|
---|
24 | app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n";
|
---|
25 |
|
---|
26 | app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
|
---|
27 | << avgRtWithoutOverhead << "\n";
|
---|
28 |
|
---|
29 | app << "#VALID_MAX_COST ( maximal cost of a valid view cell )\n" << validMaxCost << "\n";
|
---|
30 |
|
---|
31 | app << "#VALID_MIN_COST ( minimal cost of a valid view cell )\n" << validMinCost << "\n";
|
---|
32 |
|
---|
33 | app << "#VALID_AVG_RENDER_TIME ( average render time )\n" << validAvgRenderTime << "\n";
|
---|
34 |
|
---|
35 | app << "#VALID_AVG_RENDER_TIME_NO_OVERHEAD ( valid average render time without overhead )\n"
|
---|
36 | << validAvgRtWithoutOverhead << "\n";
|
---|
37 |
|
---|
38 | app << "===== END OF Render Simulation statistics ==========\n";
|
---|
39 | }
|
---|
40 |
|
---|
41 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
|
---|
42 | Renderer(NULL, viewCellsManager),
|
---|
43 | mObjRenderCost(0.0f),
|
---|
44 | mVcOverhead(0.0f),
|
---|
45 | mMoveSpeed(0.0f)
|
---|
46 | {}
|
---|
47 |
|
---|
48 |
|
---|
49 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
|
---|
50 | float objRenderCost,
|
---|
51 | float vcOverhead,
|
---|
52 | float moveSpeed):
|
---|
53 | Renderer(NULL, viewCellsManager),
|
---|
54 | mObjRenderCost(objRenderCost),
|
---|
55 | mVcOverhead(vcOverhead),
|
---|
56 | mMoveSpeed(moveSpeed)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
|
---|
62 | {
|
---|
63 | mObjRenderCost = objRenderCost;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | void RenderSimulator::SetVcOverhead(const float vcOverhead)
|
---|
68 | {
|
---|
69 | mVcOverhead = vcOverhead;
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | void RenderSimulator::SetMoveSpeed(const float moveSpeed)
|
---|
74 | {
|
---|
75 | mMoveSpeed = moveSpeed;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | bool RenderSimulator::RenderScene()
|
---|
80 | {
|
---|
81 | mSimulationStatistics.Reset();
|
---|
82 | mSimulationStatistics.Start();
|
---|
83 |
|
---|
84 | Real renderTime = 0;
|
---|
85 | Real validRenderTime = 0;
|
---|
86 |
|
---|
87 | // overhead for loading the PVS of the view cells
|
---|
88 | float loadPvsOverhead = 0;
|
---|
89 | float validLoadPvsOverhead = 0;
|
---|
90 |
|
---|
91 | ViewCellContainer::const_iterator it,
|
---|
92 | it_end = mViewCellsManager->GetViewCells().end();
|
---|
93 |
|
---|
94 |
|
---|
95 | for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
|
---|
96 | {
|
---|
97 | ViewCell *vc = *it;
|
---|
98 |
|
---|
99 | const bool valid = vc->GetValid();
|
---|
100 |
|
---|
101 |
|
---|
102 | // probability of view cell
|
---|
103 | const float pInVc = mViewCellsManager->GetProbability(vc);
|
---|
104 |
|
---|
105 | //Debug << "vc prob: " << pInVc << endl;
|
---|
106 |
|
---|
107 | // compute render time of PVS times probability
|
---|
108 | // that view point is in view cell
|
---|
109 | const float vcCost = pInVc *
|
---|
110 | mViewCellsManager->GetRendercost(vc/*, mObjRenderCost*/);
|
---|
111 |
|
---|
112 | renderTime += vcCost;
|
---|
113 |
|
---|
114 | // crossing the border of a view cell is depending on the move
|
---|
115 | // speed and the probability that a view cell border is crossed
|
---|
116 | loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
117 |
|
---|
118 |
|
---|
119 | //-- update statistics
|
---|
120 |
|
---|
121 | if (vcCost > mSimulationStatistics.maxCost)
|
---|
122 | mSimulationStatistics.maxCost = vcCost;
|
---|
123 | else if (vcCost < mSimulationStatistics.minCost)
|
---|
124 | mSimulationStatistics.minCost = vcCost;
|
---|
125 |
|
---|
126 | //-- different statistics for only valid view cells
|
---|
127 | if (valid)
|
---|
128 | {
|
---|
129 | validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
130 | validRenderTime += vcCost;
|
---|
131 |
|
---|
132 | if (vcCost > mSimulationStatistics.validMaxCost)
|
---|
133 | mSimulationStatistics.validMaxCost = vcCost;
|
---|
134 | else if (vcCost < mSimulationStatistics.validMinCost)
|
---|
135 | mSimulationStatistics.validMinCost = vcCost;
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | mSimulationStatistics.avgRtWithoutOverhead = renderTime;
|
---|
140 | mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
141 |
|
---|
142 | mSimulationStatistics.validAvgRtWithoutOverhead = renderTime;
|
---|
143 | mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead;
|
---|
144 |
|
---|
145 | mSimulationStatistics.Stop();
|
---|
146 |
|
---|
147 | return true;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | float RenderSimulator::GetCrossVcProbability() const
|
---|
152 | {
|
---|
153 | // assume the view cells are uniformly distributed
|
---|
154 | //NOTE: should I take move speed relative to view space or absolute?
|
---|
155 | const float vcNum =
|
---|
156 | (float)mViewCellsManager->GetViewCells().size();
|
---|
157 |
|
---|
158 | const float prop = mMoveSpeed * vcNum;
|
---|
159 |
|
---|
160 | // clamp probability between 0 and 1
|
---|
161 | return min(1.0f, prop);
|
---|
162 | }
|
---|
163 |
|
---|
164 | void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
|
---|
165 | {
|
---|
166 | simStats = mSimulationStatistics;
|
---|
167 | }
|
---|
168 |
|
---|
169 | } |
---|