[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 |
|
---|
[863] | 9 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 10 |
|
---|
| 11 |
|
---|
[463] | 12 | void SimulationStatistics::Print(ostream &app) const
|
---|
| 13 | {
|
---|
[1020] | 14 | app << "============== Render Simulation statistics ==============\n";
|
---|
[463] | 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 |
|
---|
[475] | 26 | app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n"
|
---|
| 27 | << avgRtWithoutOverhead << "\n";
|
---|
[463] | 28 |
|
---|
[574] | 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 |
|
---|
[1020] | 38 | app << "=========== END OF Render Simulation statistics ==========\n";
|
---|
[414] | 39 | }
|
---|
| 40 |
|
---|
[1020] | 41 |
|
---|
[473] | 42 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager):
|
---|
[564] | 43 | Renderer(NULL, viewCellsManager),
|
---|
| 44 | mObjRenderCost(0.0f),
|
---|
| 45 | mVcOverhead(0.0f),
|
---|
[574] | 46 | mMoveSpeed(0.0f)
|
---|
[406] | 47 | {}
|
---|
| 48 |
|
---|
[564] | 49 |
|
---|
[473] | 50 | RenderSimulator::RenderSimulator(ViewCellsManager *viewCellsManager,
|
---|
| 51 | float objRenderCost,
|
---|
[439] | 52 | float vcOverhead,
|
---|
| 53 | float moveSpeed):
|
---|
[497] | 54 | Renderer(NULL, viewCellsManager),
|
---|
[439] | 55 | mObjRenderCost(objRenderCost),
|
---|
| 56 | mVcOverhead(vcOverhead),
|
---|
[574] | 57 | mMoveSpeed(moveSpeed)
|
---|
[406] | 58 | {
|
---|
| 59 | }
|
---|
[463] | 60 |
|
---|
[564] | 61 |
|
---|
[463] | 62 | void RenderSimulator::SetObjectRenderCost(const float objRenderCost)
|
---|
| 63 | {
|
---|
| 64 | mObjRenderCost = objRenderCost;
|
---|
[439] | 65 | }
|
---|
[406] | 66 |
|
---|
[564] | 67 |
|
---|
[463] | 68 | void RenderSimulator::SetVcOverhead(const float vcOverhead)
|
---|
| 69 | {
|
---|
| 70 | mVcOverhead = vcOverhead;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[574] | 73 |
|
---|
[463] | 74 | void RenderSimulator::SetMoveSpeed(const float moveSpeed)
|
---|
| 75 | {
|
---|
| 76 | mMoveSpeed = moveSpeed;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[574] | 79 |
|
---|
[468] | 80 | bool RenderSimulator::RenderScene()
|
---|
[440] | 81 | {
|
---|
[468] | 82 | mSimulationStatistics.Reset();
|
---|
| 83 | mSimulationStatistics.Start();
|
---|
[406] | 84 |
|
---|
| 85 | Real renderTime = 0;
|
---|
[574] | 86 | Real validRenderTime = 0;
|
---|
| 87 |
|
---|
[409] | 88 | // overhead for loading the PVS of the view cells
|
---|
| 89 | float loadPvsOverhead = 0;
|
---|
[574] | 90 | float validLoadPvsOverhead = 0;
|
---|
| 91 |
|
---|
[468] | 92 | ViewCellContainer::const_iterator it,
|
---|
| 93 | it_end = mViewCellsManager->GetViewCells().end();
|
---|
[418] | 94 |
|
---|
[475] | 95 |
|
---|
[468] | 96 | for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
|
---|
[406] | 97 | {
|
---|
[468] | 98 | ViewCell *vc = *it;
|
---|
[409] | 99 |
|
---|
[580] | 100 | const bool valid = vc->GetValid();
|
---|
[574] | 101 |
|
---|
[564] | 102 |
|
---|
[468] | 103 | // probability of view cell
|
---|
| 104 | const float pInVc = mViewCellsManager->GetProbability(vc);
|
---|
[551] | 105 |
|
---|
[605] | 106 | //Debug << "vc prob: " << pInVc << endl;
|
---|
| 107 |
|
---|
[482] | 108 | // compute render time of PVS times probability
|
---|
| 109 | // that view point is in view cell
|
---|
| 110 | const float vcCost = pInVc *
|
---|
[728] | 111 | mViewCellsManager->GetRendercost(vc/*, mObjRenderCost*/);
|
---|
[479] | 112 |
|
---|
[605] | 113 | renderTime += vcCost;
|
---|
| 114 |
|
---|
[551] | 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
|
---|
[468] | 117 | loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
|
---|
[605] | 118 |
|
---|
[728] | 119 |
|
---|
[574] | 120 | //-- update statistics
|
---|
[482] | 121 |
|
---|
[468] | 122 | if (vcCost > mSimulationStatistics.maxCost)
|
---|
| 123 | mSimulationStatistics.maxCost = vcCost;
|
---|
| 124 | else if (vcCost < mSimulationStatistics.minCost)
|
---|
| 125 | mSimulationStatistics.minCost = vcCost;
|
---|
[574] | 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 | }
|
---|
[448] | 138 | }
|
---|
| 139 |
|
---|
[468] | 140 | mSimulationStatistics.avgRtWithoutOverhead = renderTime;
|
---|
| 141 | mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
|
---|
[574] | 142 |
|
---|
| 143 | mSimulationStatistics.validAvgRtWithoutOverhead = renderTime;
|
---|
| 144 | mSimulationStatistics.validAvgRenderTime = renderTime + loadPvsOverhead;
|
---|
[448] | 145 |
|
---|
[468] | 146 | mSimulationStatistics.Stop();
|
---|
[448] | 147 |
|
---|
[468] | 148 | return true;
|
---|
[448] | 149 | }
|
---|
| 150 |
|
---|
[479] | 151 |
|
---|
[477] | 152 | float RenderSimulator::GetCrossVcProbability() const
|
---|
[448] | 153 | {
|
---|
[477] | 154 | // assume the view cells are uniformly distributed
|
---|
[479] | 155 | //NOTE: should I take move speed relative to view space or absolute?
|
---|
[477] | 156 | const float vcNum =
|
---|
| 157 | (float)mViewCellsManager->GetViewCells().size();
|
---|
[476] | 158 |
|
---|
[479] | 159 | const float prop = mMoveSpeed * vcNum;
|
---|
| 160 |
|
---|
| 161 | // clamp probability between 0 and 1
|
---|
| 162 | return min(1.0f, prop);
|
---|
[448] | 163 | }
|
---|
[449] | 164 |
|
---|
[468] | 165 | void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
|
---|
[449] | 166 | {
|
---|
[468] | 167 | simStats = mSimulationStatistics;
|
---|
[860] | 168 | }
|
---|
| 169 |
|
---|
[449] | 170 | } |
---|