[1460] | 1 | #include "Environment.h"
|
---|
| 2 | #include "GvsPreprocessor.h"
|
---|
| 3 | #include "GlRenderer.h"
|
---|
| 4 |
|
---|
| 5 | namespace GtpVisibilityPreprocessor
|
---|
| 6 | {
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | GvsPreprocessor::GvsPreprocessor():Preprocessor()
|
---|
| 10 | {
|
---|
| 11 | environment->GetIntValue("RenderSampler.samples", mSamples);
|
---|
| 12 | cout << "number of render samples: " << mSamples << endl;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | void
|
---|
| 17 | GvsPreprocessor::GenerateRandomRay(Ray &ray)
|
---|
| 18 | {
|
---|
| 19 | int objId = RandomValue(0, mObjects.size());
|
---|
| 20 | Intersectable *object = objects[objId];
|
---|
| 21 | object->GetRandomSurfacePoint(point, normal);
|
---|
| 22 | direction = UniformRandomVector(normal);
|
---|
| 23 | SetupRay(ray, point, direction);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | void
|
---|
| 27 | GvsPreprocessor::HandleRay(Ray &ray)
|
---|
| 28 | {
|
---|
| 29 | int sampleContributions = 0;
|
---|
| 30 |
|
---|
| 31 | mKdTree->CastRay(ray);
|
---|
| 32 |
|
---|
| 33 | if (ray.leaves.size()) {
|
---|
| 34 | sampleContributions += AddNodeSamples(object, ray, pass);
|
---|
| 35 |
|
---|
| 36 | if (ray.intersections.size()) {
|
---|
| 37 | sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass);
|
---|
| 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | void
|
---|
| 43 | GvsPreprocessor::BorderSampling(Ray &ray)
|
---|
| 44 | {
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void
|
---|
| 50 | GvsPreprocessor::Pass()
|
---|
| 51 | {
|
---|
| 52 | Ray ray;
|
---|
| 53 | while (1) {
|
---|
| 54 | AvsGenerateRay(ray);
|
---|
| 55 | HandleRay(ray);
|
---|
| 56 | while ( !mRayQueue.empty() ) {
|
---|
| 57 | Ray ray = mRayQueue.pop();
|
---|
| 58 | mRayQueue.pop();
|
---|
| 59 | AdaptiveBorderSampling(ray);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | bool
|
---|
| 66 | GvsPreprocessor::ComputeVisibility()
|
---|
| 67 | {
|
---|
| 68 | long startTime = GetTime();
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | Debug << "type: gvs" << endl;
|
---|
| 72 |
|
---|
| 73 | cout<<"Gvs Preprocessor started\n"<<flush;
|
---|
| 74 | // cout<<"Memory/ray "<<sizeof(VssRay)+sizeof(RssTreeNode::RayInfo)<<endl;
|
---|
| 75 |
|
---|
| 76 | Randomize(0);
|
---|
| 77 |
|
---|
| 78 | long startTime = GetTime();
|
---|
| 79 |
|
---|
| 80 | int totalSamples = 0;
|
---|
| 81 |
|
---|
| 82 | ConstructViewCells();
|
---|
| 83 |
|
---|
| 84 | int samples = 0;
|
---|
| 85 | int i=0;
|
---|
| 86 | while (samples < mTotalSamples) {
|
---|
| 87 | for (i=0; i < mSamplesPerPass; i++, samples++) {
|
---|
| 88 |
|
---|
| 89 | if (i%10000 == 0)
|
---|
| 90 | cout<<"+";
|
---|
| 91 |
|
---|
| 92 | Vector3 origin, direction;
|
---|
| 93 | mViewCellsManager->GetViewPoint(origin);
|
---|
| 94 | direction = UniformRandomVector();
|
---|
| 95 |
|
---|
| 96 | ViewCell *viewcell = mViewCellsManager->GetViewCell(origin);
|
---|
| 97 |
|
---|
| 98 | if (viewcell && viewcell->GetValid()) {
|
---|
| 99 | // cast rays in both directions to make the number of samples comparable
|
---|
| 100 | // with the global sampling method which also casts a "double" ray per sample
|
---|
| 101 | for (int j=0; j < 2; j++) {
|
---|
| 102 | Intersectable *object = CastRay(origin, direction);
|
---|
| 103 | if (object) {
|
---|
| 104 | // if ray not outside of view space
|
---|
| 105 | float contribution;
|
---|
| 106 | int pvsContribution = 0;
|
---|
| 107 | float relativePvsContribution = 0;
|
---|
| 108 | if (object) {
|
---|
| 109 | float pdf = 1.0f;
|
---|
| 110 | if (viewcell->GetPvs().GetSampleContribution(object,
|
---|
| 111 | pdf,
|
---|
| 112 | contribution))
|
---|
| 113 | ++pvsContribution;
|
---|
| 114 | relativePvsContribution += contribution;
|
---|
| 115 | viewcell->GetPvs().AddSample(object, pdf);
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | direction = -direction;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if (samples > mTotalSamples)
|
---|
| 123 | break;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | // mVssRays.PrintStatistics(mStats);
|
---|
| 127 | mStats <<
|
---|
| 128 | "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<<endl<<
|
---|
| 129 | "#TotalSamples\n" <<samples<<endl;
|
---|
| 130 |
|
---|
| 131 | mViewCellsManager->PrintPvsStatistics(mStats);
|
---|
| 132 | // ComputeRenderError();
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | // HoleSamplingPass();
|
---|
| 136 | if (0) {
|
---|
| 137 | Exporter *exporter = Exporter::GetExporter("ray-density.x3d");
|
---|
| 138 | exporter->SetExportRayDensity(true);
|
---|
| 139 | exporter->ExportKdTree(*mKdTree);
|
---|
| 140 | delete exporter;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | // $$JB temporary removed
|
---|
| 145 | // mViewCellsManager->PostProcess(objects, mSampleRays);
|
---|
| 146 |
|
---|
| 147 | //-- several visualizations and statistics
|
---|
| 148 | Debug << "view cells after post processing: " << endl;
|
---|
| 149 | mViewCellsManager->PrintStatistics(Debug);
|
---|
| 150 |
|
---|
| 151 | //-- render simulation after merge
|
---|
| 152 | cout << "\nevaluating bsp view cells render time after merge ... ";
|
---|
| 153 |
|
---|
| 154 | mRenderSimulator->RenderScene();
|
---|
| 155 | SimulationStatistics ss;
|
---|
| 156 | mRenderSimulator->GetStatistics(ss);
|
---|
| 157 |
|
---|
| 158 | cout << " finished" << endl;
|
---|
| 159 | cout << ss << endl;
|
---|
| 160 | Debug << ss << endl;
|
---|
| 161 |
|
---|
| 162 | // $$JB temporary removed
|
---|
| 163 | //mViewCellsManager->Visualize(objects, mSampleRays);
|
---|
| 164 |
|
---|
| 165 | return true;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | }
|
---|