Changeset 364
- Timestamp:
- 10/23/06 18:25:26 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/OSGScreenLOD.inl
r363 r364 47 47 48 48 UInt32 numLevels = action->getNNodes(); 49 //UInt32 numRanges = getMFRange()->size();50 51 //UInt32 limit = osgMin(numLevels, 0);52 53 49 Int32 index = 0; 54 50 55 if(numLevels > 1 || ra->getScreenLODCoverageThreshold() == 0.f)51 if(numLevels > 1) 56 52 { 57 Matrixr worldToScreen; 53 if(ra->getScreenLODCoverageThreshold() > 0.f) 54 { 55 Matrixr worldToScreen; 58 56 #if 1 59 DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); 60 Camera* cam = ra->getCamera(); 61 Viewport* vp = ra->getViewport(); 62 cam->getWorldToScreen(worldToScreen, *vp); 57 DrawActionBase *da = dynamic_cast<DrawActionBase *>(action); 58 Camera* cam = ra->getCamera(); 59 Viewport* vp = ra->getViewport(); 60 cam->getWorldToScreen(worldToScreen, *vp); 61 #else 62 worldToScreen = da->getDrawEnv()->getWorldToScreen(); 63 63 #endif 64 #if 0 65 worldToScreen = da->getDrawEnv()->getWorldToScreen(); 66 #endif 67 68 DynamicVolume volume = ra->getActNode()->getVolume(); 69 Pnt3r min,max; 70 volume.getBounds(min, max); 71 Pnt3r p[8]; 72 p[0].setValues(min[0],min[1],min[2]); 73 p[1].setValues(max[0],min[1],min[2]); 74 p[2].setValues(min[0],max[1],min[2]); 75 p[3].setValues(min[0],min[1],max[2]); 76 p[4].setValues(max[0],max[1],min[2]); 77 p[5].setValues(max[0],min[1],max[2]); 78 p[6].setValues(min[0],max[1],max[2]); 79 p[7].setValues(max[0],max[1],max[2]); 80 81 for(UInt32 i = 0; i<8;i++) 82 { 83 ra->topMatrix().mult(p[i]); 84 worldToScreen.multFullMatrixPnt(p[i]); 85 } 86 min=p[0]; 87 max=p[0]; 88 for(UInt32 i = 0; i<8; i++) 89 { 90 for(UInt32 j=0; j<2; j++) 91 { 92 if(p[i][j] < min[j]) 93 { 94 min[j] = p[i][j]; 95 } 96 if(p[i][j] > max[j]) 97 { 98 max[j] = p[i][j]; 99 } 100 } 101 } 102 max[0] = osgClamp(-1.f, max[0], 1.f); 103 max[1] = osgClamp(-1.f, max[1], 1.f); 104 min[0] = osgClamp(-1.f, min[0], 1.f); 105 min[1] = osgClamp(-1.f, min[1], 1.f); 106 107 // cbb is the percent of the screen real estate this would cover 108 Real32 cbb = (max[0] - min[0]) * (max[1] - min[1]) / 4.f; 109 //Real32 pix = cbb * vp->getPixelWidth() * vp->getPixelHeight(); 64 65 DynamicVolume volume = ra->getActNode()->getVolume(); 66 Pnt3r min,max; 67 volume.getBounds(min, max); 68 Pnt3r p[8]; 69 p[0].setValues(min[0],min[1],min[2]); 70 p[1].setValues(max[0],min[1],min[2]); 71 p[2].setValues(min[0],max[1],min[2]); 72 p[3].setValues(min[0],min[1],max[2]); 73 p[4].setValues(max[0],max[1],min[2]); 74 p[5].setValues(max[0],min[1],max[2]); 75 p[6].setValues(min[0],max[1],max[2]); 76 p[7].setValues(max[0],max[1],max[2]); 77 78 for(UInt32 i = 0; i<8;i++) 79 { 80 ra->topMatrix().mult(p[i]); 81 worldToScreen.multFullMatrixPnt(p[i]); 82 } 83 min=p[0]; 84 max=p[0]; 85 for(UInt32 i = 0; i<8; i++) 86 { 87 for(UInt32 j=0; j<2; j++) 88 { 89 if(p[i][j] < min[j]) 90 { 91 min[j] = p[i][j]; 92 } 93 if(p[i][j] > max[j]) 94 { 95 max[j] = p[i][j]; 96 } 97 } 98 } 99 max[0] = osgClamp(-1.f, max[0], 1.f); 100 max[1] = osgClamp(-1.f, max[1], 1.f); 101 min[0] = osgClamp(-1.f, min[0], 1.f); 102 min[1] = osgClamp(-1.f, min[1], 1.f); 103 104 // cbb is the percent of the screen real estate this would cover 105 Real32 cbb = (max[0] - min[0]) * (max[1] - min[1]) / 4.f; 106 //Real32 pix = cbb * vp->getPixelWidth() * vp->getPixelHeight(); 110 107 111 108 #if 0 112 //THIS IS WHAT I WANT TO DO....but the calls to validate never return113 Geometry* pmin = dynamic_cast<Geometry *>(getCPtr(action->getNode(0)));114 Geometry* pmax = dynamic_cast<Geometry *>(getCPtr(action->getNode(numLevels-1)));115 GeoStatsAttachmentPtr st_max = GeoStatsAttachment::get(pmin);116 st_max->validate();109 //THIS IS WHAT I WANT TO DO....but the calls to validate never return 110 Geometry* pmin = dynamic_cast<Geometry *>(getCPtr(action->getNode(0))); 111 Geometry* pmax = dynamic_cast<Geometry *>(getCPtr(action->getNode(numLevels-1))); 112 GeoStatsAttachmentPtr st_max = GeoStatsAttachment::get(pmin); 113 st_max->validate(); 117 114 118 GeoStatsAttachmentPtr st_min = GeoStatsAttachment::get(pmax);119 st_min->validate();115 GeoStatsAttachmentPtr st_min = GeoStatsAttachment::get(pmax); 116 st_min->validate(); 120 117 121 Real32 deg_percent = (st_min->getTriangles() / st_max->getTriangles()) * numLevels; 122 if(deg_percent >= 1.0) 123 { 124 std::cout << "LOD's not in decreasing complexity!" << std::endl; 125 deg_percent = 0.5; 118 Real32 deg_percent = (st_min->getTriangles() / st_max->getTriangles()) * numLevels; 119 if(deg_percent >= 1.0) 120 { 121 std::cout << "LOD's not in decreasing complexity!" << std::endl; 122 deg_percent = 0.5; 123 } 124 125 Real32 base_percent = 0.1; //Above this renders at full res! this should be tweakable 126 127 while(cbb < base_percent) 128 { 129 base_percent*=deg_percent; 130 index++; 131 if(index >= numLevels) 132 break; 133 } 134 #else 135 Real32 degradation_base = ra->getScreenLODCoverageThreshold(); 136 while(cbb < degradation_base) 137 { 138 degradation_base*=0.3; 139 index++; 140 if (index >= numLevels) 141 { 142 index=numLevels-1; 143 break; 144 } 145 } 146 #endif 126 147 } 127 128 Real32 base_percent = 0.1; //Above this renders at full res! this should be tweakable129 130 while(cbb < base_percent)131 {132 base_percent*=deg_percent;133 index++;134 if(index >= numLevels)135 break;136 }137 #endif138 #if 1139 Real32 degradation_base = ra->getScreenLODCoverageThreshold();140 while(cbb < degradation_base)141 {142 degradation_base*=0.3;143 index++;144 if (index >= numLevels)145 {146 index=numLevels-1;147 break;148 }149 }150 #endif151 148 } 152 149 branches/Dirk_RenderTraversalWork/Source/System/Action/RenderTraversal/testOcclusionCulling.cpp
r363 r364 498 498 { 499 499 Real32 cover = tact->getScreenLODCoverageThreshold(); 500 cover+=0.00 02;500 cover+=0.002; 501 501 tact->setScreenLODCoverageThreshold(cover); 502 502 std::cout << "ScreenLOD Coverage Threshold now: " << cover << std::endl; … … 507 507 { 508 508 Real32 covera = tact->getScreenLODCoverageThreshold(); 509 covera-=0.00 02;509 covera-=0.002; 510 510 tact->setScreenLODCoverageThreshold(covera); 511 511 std::cout << "ScreenLOD Coverage Threshold now: " << covera << std::endl; 512 } 513 break; 514 515 case 'N': 516 { 517 Real32 coverb = tact->getScreenLODCoverageThreshold(); 518 coverb=0.0; 519 tact->setScreenLODCoverageThreshold(coverb); 520 std::cout << "ScreenLOD Coverage Threshold now: " << coverb << std::endl; 512 521 } 513 522 break;
