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 |
|
---|
42 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
|
---|
43 | Renderer(NULL, viewCellsManager),
|
---|
44 | mObjRenderCost(0.0f),
|
---|
45 | mVcOverhead(0.0f),
|
---|
46 | mMoveSpeed(0.0f)
|
---|
47 | {}
|
---|
48 |
|
---|
49 |
|
---|
50 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
|
---|
51 | float objRenderCost,
|
---|
52 | float vcOverhead,
|
---|
53 | float moveSpeed):
|
---|
54 | Renderer(NULL, viewCellsManager),
|
---|
55 | mObjRenderCost(objRenderCost),
|
---|
56 | mVcOverhead(vcOverhead),
|
---|
57 | mMoveSpeed(moveSpeed)
|
---|
58 | {
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
|
---|
63 | {
|
---|
64 | mObjRenderCost = objRenderCost;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | void RenderSimulator::SetVcOverhead(const float vcOverhead)
|
---|
69 | {
|
---|
70 | mVcOverhead = vcOverhead;
|
---|
71 | }
|
---|
72 |
|
---|
73 |
|
---|
74 | void RenderSimulator::SetMoveSpeed(const float moveSpeed)
|
---|
75 | {
|
---|
76 | mMoveSpeed = moveSpeed;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | bool RenderSimulator::RenderScene()
|
---|
81 | {
|
---|
82 | mSimulationStatistics.Reset();
|
---|
83 | mSimulationStatistics.Start();
|
---|
84 |
|
---|
85 | Real renderTime = 0;
|
---|
86 | Real validRenderTime = 0;
|
---|
87 |
|
---|
88 | // overhead for loading the PVS of the view cells
|
---|
89 | float loadPvsOverhead = 0;
|
---|
90 | float validLoadPvsOverhead = 0;
|
---|
91 |
|
---|
92 | ViewCellContainer::const_iterator it,
|
---|
93 | it_end = mViewCellsManager->GetViewCells().end();
|
---|
94 |
|
---|
95 |
|
---|
96 | for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
|
---|
97 | {
|
---|
98 | ViewCell *vc = *it;
|
---|
99 |
|
---|
100 | const bool valid = vc->GetValid();
|
---|
101 |
|
---|
102 |
|
---|
103 | // probability of view cell
|
---|
104 | const float pInVc = mViewCellsManager->GetProbability(vc);
|
---|
105 |
|
---|
106 | //Debug << "vc prob: " << pInVc << endl;
|
---|
107 |
|
---|
108 | // compute render time of PVS times probability
|
---|
109 | // that view point is in view cell
|
---|
110 | const float vcCost = pInVc *
|
---|
111 | mViewCellsManager->GetRendercost(vc/*, mObjRenderCost*/);
|
---|
112 |
|
---|
113 | renderTime += vcCost;
|
---|
114 |
|
---|
115 | // crossing the border of a view cell is depending on the move
|
---|
116 | // speed and the probability that a view cell border is crossed
|
---|
117 | loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
118 |
|
---|
119 |
|
---|
120 | //-- update statistics
|
---|
121 |
|
---|
122 | if (vcCost > mSimulationStatistics.maxCost)
|
---|
123 | mSimulationStatistics.maxCost = vcCost;
|
---|
124 | else if (vcCost < mSimulationStatistics.minCost)
|
---|
125 | mSimulationStatistics.minCost = vcCost;
|
---|
126 |
|
---|
127 | //-- different statistics for only valid view cells
|
---|
128 | if (valid)
|
---|
129 | {
|
---|
130 | validLoadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
131 | validRenderTime += vcCost;
|
---|
132 |
|
---|
133 | if (vcCost > mSimulationStatistics.validMaxCost)
|
---|
134 | mSimulationStatistics.validMaxCost = vcCost;
|
---|
135 | else if (vcCost < mSimulationStatistics.validMinCost)
|
---|
136 | mSimulationStatistics.validMinCost = vcCost;
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | mSimulationStatistics.avgRtWithoutOverhead = renderTime;
|
---|
141 | mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
142 |
|
---|
143 | mSimulationStatistics.validAvgRtWithoutOverhead = renderTime;
|
---|
144 | mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead;
|
---|
145 |
|
---|
146 | mSimulationStatistics.Stop();
|
---|
147 |
|
---|
148 | return true;
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | float RenderSimulator::GetCrossVcProbability() const
|
---|
153 | {
|
---|
154 | // assume the view cells are uniformly distributed
|
---|
155 | //NOTE: should I take move speed relative to view space or absolute?
|
---|
156 | const float vcNum =
|
---|
157 | (float)mViewCellsManager->GetViewCells().size();
|
---|
158 |
|
---|
159 | const float prop = mMoveSpeed * vcNum;
|
---|
160 |
|
---|
161 | // clamp probability between 0 and 1
|
---|
162 | return min(1.0f, prop);
|
---|
163 | }
|
---|
164 |
|
---|
165 | void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
|
---|
166 | {
|
---|
167 | simStats = mSimulationStatistics;
|
---|
168 | }
|
---|
169 |
|
---|
170 | } |
---|