[406] | 1 | #include "RenderSimulator.h"
|
---|
| 2 | #include "KdTree.h"
|
---|
| 3 | #include "ViewCellBsp.h"
|
---|
| 4 | #include "ViewCell.h"
|
---|
| 5 |
|
---|
| 6 | RenderSimulator::RenderSimulator()
|
---|
| 7 | {}
|
---|
| 8 |
|
---|
[409] | 9 | RenderSimulator::RenderSimulator(float objRenderCost, float vcOverhead, float moveSpeed):
|
---|
| 10 | mObjRenderCost(objRenderCost), mVcOverhead(vcOverhead), mMoveSpeed(moveSpeed)
|
---|
[406] | 11 | {
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | /*****************************************************
|
---|
| 15 | * class ViewCellRenderSimulator implementation *
|
---|
| 16 | *****************************************************/
|
---|
| 17 |
|
---|
[409] | 18 | BspViewCellRenderSimulator::BspViewCellRenderSimulator(float objRenderCost,
|
---|
[406] | 19 | float vcOverhead,
|
---|
[409] | 20 | float moveSpeed,
|
---|
[406] | 21 | BspTree *bspTree):
|
---|
[409] | 22 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
|
---|
[406] | 23 | {
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[409] | 26 | Real BspViewCellRenderSimulator::SimulateRendering()
|
---|
[406] | 27 | {
|
---|
| 28 | Real renderTime = 0;
|
---|
| 29 |
|
---|
[409] | 30 | // overhead for loading the PVS of the view cells
|
---|
| 31 | float loadPvsOverhead = 0;
|
---|
[406] | 32 |
|
---|
[409] | 33 | // probability that view point lies in a view cell
|
---|
| 34 | float pInVcTotal = 0;
|
---|
| 35 |
|
---|
| 36 | // total probability that a view cell border is crossed
|
---|
| 37 | float pCrossVcTotal = 0;
|
---|
| 38 |
|
---|
| 39 | // collect all view cells
|
---|
[406] | 40 | ViewCellContainer viewCells;
|
---|
| 41 | mBspTree->CollectViewCells(viewCells);
|
---|
| 42 |
|
---|
| 43 | ViewCellContainer::const_iterator it, it_end = viewCells.end();
|
---|
[407] | 44 |
|
---|
| 45 | // surface area substitute for probability
|
---|
[409] | 46 | PolygonContainer geom;
|
---|
[407] | 47 |
|
---|
[406] | 48 | for (it = viewCells.begin(); it != it_end; ++ it)
|
---|
| 49 | {
|
---|
[410] | 50 | // compute view cell area
|
---|
[409] | 51 | mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
|
---|
[410] | 52 | const float area = Polygon3::GetArea(geom);
|
---|
[409] | 53 | CLEAR_CONTAINER(geom);
|
---|
| 54 |
|
---|
| 55 | // area substitute for view point probability
|
---|
| 56 | float pInVc = area;
|
---|
| 57 |
|
---|
| 58 | // compute render time of PVS times probability that view point is in view cell
|
---|
| 59 | renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost);
|
---|
[406] | 60 |
|
---|
[409] | 61 | // probability that a view cell border is crossed
|
---|
| 62 | float pCrossVc = area;
|
---|
| 63 |
|
---|
| 64 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
| 65 |
|
---|
| 66 | pInVcTotal += pInVc;
|
---|
| 67 | pCrossVcTotal += pCrossVc;
|
---|
[406] | 68 | }
|
---|
| 69 |
|
---|
[409] | 70 |
|
---|
| 71 | renderTime /= pInVcTotal;
|
---|
| 72 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[406] | 73 |
|
---|
| 74 | //Debug << "render time without overhead: " << renderTime * 1e-3 << endl;
|
---|
[409] | 75 |
|
---|
| 76 | return renderTime + loadPvsOverhead;
|
---|
[406] | 77 | }
|
---|
| 78 |
|
---|
[409] | 79 | Real BspViewCellRenderSimulator::RenderPvs(ViewCell &viewCell,
|
---|
[407] | 80 | float objRenderTime) const
|
---|
[406] | 81 | {
|
---|
| 82 | return viewCell.GetPvs().GetSize() * objRenderTime;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[407] | 85 | /********************************************************
|
---|
| 86 | * class KdLeafRenderSimulator implementation *
|
---|
| 87 | *******************************************************/
|
---|
[406] | 88 |
|
---|
[409] | 89 | KdViewCellRenderSimulator::KdViewCellRenderSimulator(float objRenderCost,
|
---|
| 90 | float vcOverhead,
|
---|
| 91 | float moveSpeed,
|
---|
[406] | 92 | KdTree *kdTree):
|
---|
[409] | 93 | RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
|
---|
[406] | 94 | {
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[409] | 97 | Real KdViewCellRenderSimulator::SimulateRendering()
|
---|
[406] | 98 | {
|
---|
[407] | 99 | //mKdTree->CollectLeavesPvs();
|
---|
| 100 |
|
---|
| 101 | // total render time
|
---|
[406] | 102 | Real renderTime = 0;
|
---|
[407] | 103 | // overhead for loading a view cell
|
---|
[409] | 104 | float loadPvsOverhead = 0;
|
---|
[406] | 105 |
|
---|
[407] | 106 | // probability that view point lies in a view cell
|
---|
| 107 | float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
|
---|
[406] | 108 |
|
---|
[407] | 109 | // total probability that a view cell border is crossed
|
---|
| 110 | float pCrossVcTotal = 0;
|
---|
| 111 |
|
---|
| 112 | vector<KdLeaf *> leaves;
|
---|
| 113 | mKdTree->CollectLeaves(leaves);
|
---|
| 114 |
|
---|
| 115 | AxisAlignedBox3 box;
|
---|
| 116 |
|
---|
| 117 | vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
|
---|
| 118 |
|
---|
| 119 | for (it = leaves.begin(); it != it_end; ++ it)
|
---|
| 120 | {
|
---|
| 121 | box = mKdTree->GetBox(*it);
|
---|
| 122 |
|
---|
| 123 | // volume substitute for view point probability
|
---|
| 124 | float pInVc = 0;
|
---|
| 125 |
|
---|
| 126 | if (0)
|
---|
| 127 | pInVc = box.GetVolume();
|
---|
| 128 | else
|
---|
| 129 | pInVc = box.SurfaceArea();
|
---|
| 130 |
|
---|
| 131 | // probability that a view cell border is crossed
|
---|
| 132 | const float pCrossVc = box.SurfaceArea();
|
---|
| 133 |
|
---|
| 134 | renderTime += pInVc * RenderPvs(*it, mObjRenderCost);
|
---|
[409] | 135 | loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
|
---|
[407] | 136 |
|
---|
| 137 | pInVcTotal += pInVc;
|
---|
| 138 | pCrossVcTotal += pCrossVc;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | renderTime /= pInVcTotal;
|
---|
[409] | 142 | loadPvsOverhead /= pCrossVcTotal;
|
---|
[407] | 143 |
|
---|
[409] | 144 | return renderTime + loadPvsOverhead;
|
---|
[407] | 145 | }
|
---|
| 146 |
|
---|
[409] | 147 | Real KdViewCellRenderSimulator::RenderPvs(KdLeaf *leaf,
|
---|
[407] | 148 | float objRenderTime) const
|
---|
| 149 | {
|
---|
| 150 | return leaf->mKdPvs.GetSize() * objRenderTime;
|
---|
[406] | 151 | } |
---|