Changeset 374

Show
Ignore:
Timestamp:
11/01/06 11:36:11 (2 years ago)
Author:
dshipton
Message:

Screen LOD now takes into account triangle degradation and works too!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGScreenLOD.inl

    r372 r374  
    104104            // cbb is the percent of the screen real estate this would cover 
    105105            Real32 cbb = (max[0] - min[0]) * (max[1] - min[1]) / 4.f; 
    106             //Real32 pix = cbb * vp->getPixelWidth() * vp->getPixelHeight(); 
    107106 
    108 #if 1  
    109             //THIS IS WHAT I WANT TO DO....but the calls to validate never return 
    110             //commitChanges(); 
     107            //Get max LOD number of triangles 
    111108            NodePtr pmax = action->getNode(0); 
    112109            GeoStatsAttachmentPtr st_max = GeoStatsAttachment::get(pmax); 
     110            if(st_max == NullFC) 
     111            { 
     112               GeoStatsAttachment::addTo(pmax); 
     113               st_max = GeoStatsAttachment::get(pmax); 
     114            } 
    113115            st_max->validate(); 
    114116 
     117            //Get min LOD number of triangles 
    115118            NodePtr pmin = action->getNode(numLevels-1); 
    116119            GeoStatsAttachmentPtr st_min = GeoStatsAttachment::get(pmin); 
     120            if(st_min == NullFC) 
     121            { 
     122               GeoStatsAttachment::addTo(pmin); 
     123               st_min = GeoStatsAttachment::get(pmin); 
     124            } 
    117125            st_min->validate(); 
    118126 
    119             Real32 deg_percent = (st_min->getTriangles() / st_max->getTriangles()) * numLevels; 
     127            // Find out what the average degradation of triangles is each level 
     128            Real32 deg_percent = (st_min->getTriangles() / st_max->getTriangles()) * (numLevels-1); 
    120129            if(deg_percent >= 1.0) 
    121130            { 
    122                 std::cout << "LOD's not in decreasing complexity!" << std::endl; 
    123                 deg_percent = 0.5; 
     131                deg_percent = 0.9; 
    124132            } 
    125133 
    126             Real32 base_percent = 0.1; //Above this renders at full res! this should be tweakable 
     134            Real32 base_percent = ra->getScreenLODCoverageThreshold(); //Above this renders at full res! 
    127135 
     136            // While the screen percentage of the object is less that the percent allowed for the current LOD 
     137            // move down a LOD and find out the new allowed percentage 
    128138            while(cbb < base_percent) 
    129139            { 
     
    133143                    break; 
    134144            } 
    135 #else 
    136             Real32 degradation_base = ra->getScreenLODCoverageThreshold(); 
    137             while(cbb < degradation_base) 
    138             { 
    139                 degradation_base*=0.3; 
    140                 index++; 
    141                 if (index >= numLevels) 
    142                 { 
    143                     index=numLevels-1; 
    144                     break; 
    145                 } 
    146             } 
    147 #endif 
    148145        } 
    149146    }