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