#include "Environment.h" #include "GvsPreprocessor.h" #include "GlRenderer.h" namespace GtpVisibilityPreprocessor { GvsPreprocessor::GvsPreprocessor():Preprocessor() { environment->GetIntValue("RenderSampler.samples", mSamples); cout << "number of render samples: " << mSamples << endl; } void GvsPreprocessor::GenerateRandomRay(Ray &ray) { int objId = RandomValue(0, mObjects.size()); Intersectable *object = objects[objId]; object->GetRandomSurfacePoint(point, normal); direction = UniformRandomVector(normal); SetupRay(ray, point, direction); } void GvsPreprocessor::HandleRay(Ray &ray) { int sampleContributions = 0; mKdTree->CastRay(ray); if (ray.leaves.size()) { sampleContributions += AddNodeSamples(object, ray, pass); if (ray.intersections.size()) { sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); } } } void GvsPreprocessor::BorderSampling(Ray &ray) { } void GvsPreprocessor::Pass() { Ray ray; while (1) { AvsGenerateRay(ray); HandleRay(ray); while ( !mRayQueue.empty() ) { Ray ray = mRayQueue.pop(); mRayQueue.pop(); AdaptiveBorderSampling(ray); } } } bool GvsPreprocessor::ComputeVisibility() { long startTime = GetTime(); Debug << "type: gvs" << endl; cout<<"Gvs Preprocessor started\n"<GetViewPoint(origin); direction = UniformRandomVector(); ViewCell *viewcell = mViewCellsManager->GetViewCell(origin); if (viewcell && viewcell->GetValid()) { // cast rays in both directions to make the number of samples comparable // with the global sampling method which also casts a "double" ray per sample for (int j=0; j < 2; j++) { Intersectable *object = CastRay(origin, direction); if (object) { // if ray not outside of view space float contribution; int pvsContribution = 0; float relativePvsContribution = 0; if (object) { float pdf = 1.0f; if (viewcell->GetPvs().GetSampleContribution(object, pdf, contribution)) ++pvsContribution; relativePvsContribution += contribution; viewcell->GetPvs().AddSample(object, pdf); } } direction = -direction; } } if (samples > mTotalSamples) break; } // mVssRays.PrintStatistics(mStats); mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3<PrintPvsStatistics(mStats); // ComputeRenderError(); } // HoleSamplingPass(); if (0) { Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); exporter->SetExportRayDensity(true); exporter->ExportKdTree(*mKdTree); delete exporter; } // $$JB temporary removed // mViewCellsManager->PostProcess(objects, mSampleRays); //-- several visualizations and statistics Debug << "view cells after post processing: " << endl; mViewCellsManager->PrintStatistics(Debug); //-- render simulation after merge cout << "\nevaluating bsp view cells render time after merge ... "; mRenderSimulator->RenderScene(); SimulationStatistics ss; mRenderSimulator->GetStatistics(ss); cout << " finished" << endl; cout << ss << endl; Debug << ss << endl; // $$JB temporary removed //mViewCellsManager->Visualize(objects, mSampleRays); return true; } }