Ignore:
Timestamp:
01/22/07 20:25:06 (17 years ago)
Author:
bittner
Message:

pvs efficiency tuning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r2014 r2015  
    2828 
    2929 
     30 
    3031#define USE_RAY_LENGTH_AS_CONTRIBUTION 0 
    3132#define DIST_WEIGHTED_CONTRIBUTION 0 
     
    3738namespace GtpVisibilityPreprocessor { 
    3839 
     40 
     41PerfTimer viewCellCastTimer; 
     42PerfTimer pvsTimer; 
     43PerfTimer objTimer; 
    3944 
    4045// HACK 
     
    16941699 
    16951700  VssRayContainer::const_iterator it, it_end = rays.end(); 
    1696    
     1701 
    16971702  for (it = rays.begin(); it != it_end; ++ it)  
    16981703        { 
     
    17071712        } 
    17081713 
     1714  cout<<"view cell cast time:"<<viewCellCastTimer.TotalTime()<<" s"<<endl; 
     1715  cout<<"pvs time:"<<pvsTimer.TotalTime()<<" s"<<endl; 
     1716   
    17091717  return sum; 
    17101718} 
     
    22352243 
    22362244 
     2245void 
     2246ViewCellsManager::SortViewCellPvs() 
     2247{ 
     2248 
     2249  ViewCellContainer::iterator it, it_end = mViewCells.end(); 
     2250  for (it = mViewCells.begin(); it != it_end; ++ it) { 
     2251        ObjectPvs &pvs = (*it)->GetPvs(); 
     2252        if (pvs.RequiresResortLog()) 
     2253          pvs.Sort(); 
     2254  } 
     2255} 
     2256 
    22372257void ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell, 
    22382258                                                                                                   VssRay &ray,  
     
    22422262{ 
    22432263  // check if we are outside of view space 
    2244         if (!obj || !viewCell->GetValid()) 
    2245                 return; 
    2246          
    2247         // if ray not outside of view space 
    2248         float relContribution = 0.0f; 
    2249         float absContribution = 0.0f; 
    2250          
    2251         if (obj)  
    2252           { 
    2253                 // todo: maybe not correct for kd node pvs 
    2254                 if (addRays)  
    2255                 { 
    2256                         float pdf = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf); 
    2257                          
    2258                         if (pdf == ray.mPdf)  
    2259                         { 
    2260                                 absContribution = 1.0f; 
    2261                                 if (viewCell->GetPvs().RequiresResort())  
    2262                                         viewCell->GetPvs().SimpleSort(); 
    2263                         } 
    2264                 }  
    2265                 else  
    2266                 { 
    2267                         if (viewCell->GetPvs().GetSampleContribution( 
    2268                                                                                                                  obj, 
    2269                                                                                                                  ray.mPdf, 
    2270                                                                                                                  relContribution)) 
    2271                         { 
    2272                                 absContribution = 1.0f; 
    2273                         } 
    2274                 } 
    2275  
    2276                 // $$ clear the relative contribution as it is currently not correct anyway 
    2277                 relContribution = 0.0f; 
    2278                  
    2279                 if (absContribution == 1.0f)  
    2280                 { 
    2281                   ++ ray.mPvsContribution; 
    2282                   relContribution = 1.0f; 
    2283                    
    2284                    
     2264  // $$JB tmp commented to speedup up computations 
     2265#if 0 
     2266  if (!obj || !viewCell->GetValid()) 
     2267        return; 
     2268#endif 
     2269   
     2270   
     2271  // if ray not outside of view space 
     2272  float relContribution = 0.0f; 
     2273  float absContribution = 0.0f; 
     2274  bool hasAbsContribution; 
     2275   
     2276  // todo: maybe not correct for kd node pvs 
     2277  if (addRays) { 
     2278        hasAbsContribution = viewCell->GetPvs().AddSampleDirtyCheck(obj, 
     2279                                                                                                                                ray.mPdf); 
     2280  } 
     2281  else { 
     2282        hasAbsContribution = viewCell->GetPvs().GetSampleContribution( 
     2283                                                                                                                                  obj, 
     2284                                                                                                                                  ray.mPdf, 
     2285                                                                                                                                  relContribution); 
     2286  } 
     2287   
     2288  // $$ clear the relative contribution as it is currently not correct anyway 
     2289  //  relContribution = 0.0f; 
     2290   
     2291  if (hasAbsContribution)  { 
     2292        ++ ray.mPvsContribution; 
     2293        absContribution = relContribution = 1.0f; 
     2294        if (viewCell->GetPvs().RequiresResort())  
     2295          viewCell->GetPvs().SimpleSort(); 
     2296 
    22852297#if CONTRIBUTION_RELATIVE_TO_PVS_SIZE 
    2286                   relContribution /= viewcell->GetPvs().GetSize(); 
     2298        relContribution /= viewcell->GetPvs().GetSize(); 
    22872299#endif 
    2288                    
     2300         
    22892301#if DIST_WEIGHTED_CONTRIBUTION  
    2290                   // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
    2291                   // object-> a new contribution in the proximity of the viewcell has a larger weight! 
    2292                   relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
    2293                                                                                 ray.mTermination); 
    2294                    
     2302        // recalculate the contribution - weight the 1.0f contribution by the sqr distance to the 
     2303        // object-> a new contribution in the proximity of the viewcell has a larger weight! 
     2304        relContribution /= SqrDistance(GetViewCellBox(viewcell).Center(), 
     2305                                                                  ray.mTermination); 
     2306         
    22952307#endif 
    2296                 } 
    2297                  
     2308        } 
     2309   
    22982310#if SUM_RAY_CONTRIBUTIONS || AVG_RAY_CONTRIBUTIONS 
    2299                 ray.mRelativePvsContribution += relContribution; 
     2311  ray.mRelativePvsContribution += relContribution; 
    23002312#else 
    2301                 // recalculate relative contribution - use max of Rel Contribution 
    2302                 if (ray.mRelativePvsContribution < relContribution) 
    2303                   ray.mRelativePvsContribution = relContribution; 
     2313  // recalculate relative contribution - use max of Rel Contribution 
     2314  if (ray.mRelativePvsContribution < relContribution) 
     2315        ray.mRelativePvsContribution = relContribution; 
    23042316#endif 
    2305           } 
    2306          
    2307 } 
     2317} 
     2318 
     2319 
    23082320 
    23092321 
     
    23652377         
    23662378        if (!ray.mTerminationObject) 
    2367                 return 0.0f; 
    2368  
    2369         static ViewCellContainer viewCells; 
    2370  
    2371            
     2379          return 0.0f; 
     2380         
    23722381        static Ray hray; 
    23732382        hray.Init(ray); 
     
    23822391        Vector3 origin = hray.Extrap(tmin); 
    23832392        Vector3 termination = hray.Extrap(tmax); 
    2384  
     2393         
    23852394        ViewCell::NewMail(); 
    2386  
    2387         viewCells.clear(); 
    2388          
    2389         // traverse the view space subdivision 
    2390         CastLineSegment(origin, termination, viewCells); 
     2395         
     2396        viewCellCastTimer.Entry(); 
     2397 
     2398        static ViewCellContainer viewCells; 
     2399        static VssRay *lastVssRay = NULL; 
     2400         
     2401        if (lastVssRay == NULL || 
     2402                !(ray.mOrigin == lastVssRay->mTermination) || 
     2403                !(ray.mTermination == lastVssRay->mOrigin)) { 
     2404          viewCells.clear(); 
     2405          // traverse the view space subdivision 
     2406          CastLineSegment(origin, termination, viewCells); 
     2407          lastVssRay = &ray; 
     2408        } 
     2409         
     2410        viewCellCastTimer.Exit(); 
    23912411 
    23922412        mSamplesStat.mViewCells += (int)viewCells.size(); 
     
    23942414        if (storeViewCells) 
    23952415        {        
     2416          cerr<<"Store viewcells should not be used in the test!"<<endl; 
    23962417          // copy viewcells memory efficiently 
    23972418#if VSS_STORE_VIEWCELLS 
     
    24032424#endif 
    24042425        } 
    2405  
     2426         
    24062427        Intersectable *terminationObj; 
     2428         
     2429        objTimer.Entry(); 
    24072430 
    24082431        // obtain pvs entry (can be different from hit object) 
    24092432        if (!useHitObjects) 
    2410                 terminationObj = GetIntersectable(ray, true); 
     2433          terminationObj = GetIntersectable(ray, true); 
    24112434        else 
    2412                 terminationObj = ray.mTerminationObject; 
     2435          terminationObj = ray.mTerminationObject; 
     2436         
     2437        objTimer.Exit(); 
     2438         
     2439        pvsTimer.Entry(); 
    24132440 
    24142441        ViewCellContainer::const_iterator it = viewCells.begin(); 
     
    24222449                                                                        addRays); 
    24232450        } 
     2451 
     2452        pvsTimer.Exit(); 
    24242453 
    24252454        mSamplesStat.mPvsContributions += ray.mPvsContribution; 
Note: See TracChangeset for help on using the changeset viewer.