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