History

latest occlusion culling with support for checking map without adding to coverage map for checking parent nodes

ZappoMan committed 13 years ago

Commit 620a4a81 parent 7fb4ed25 files · +122 −47Browse files

Showing the changes to interface/src/VoxelSystem.cpp (1 of 5 files). Show all

Unified · Split

interface/src/VoxelSystem.cpp+101−33
@@ -1158,70 +1158,138 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 1157 unmodified lines
11581158 }
11591159
11601160 struct FalseColorizeOccludedArgs {
1161− VoxelProjectedShadow occluder;
11621161 ViewFrustum* viewFrustum;
11631162 CoverageMap* map;
1163+ VoxelTree* tree;
1164+ long totalVoxels;
1165+ long coloredVoxels;
1166+ long occludedVoxels;
1167+ long notOccludedVoxels;
1168+ long outOfView;
1169+ long subtreeVoxelsSkipped;
1170+ long nonLeaves;
1171+ long nonLeavesOutOfView;
1172+ long nonLeavesOccluded;
1173+ long stagedForDeletion;
11641174 };
11651175
1166−bool VoxelSystem::falseColorizeTestOccludedOperation(VoxelNode* node, void* extraData) {
1176+struct FalseColorizeSubTreeOperationArgs {
1177+ unsigned char color[NUMBER_OF_COLORS];
1178+ long voxelsTouched;
1179+};
1180+
1181+bool VoxelSystem::falseColorizeSubTreeOperation(VoxelNode* node, void* extraData) {
1182+ FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData;
1183+ node->setFalseColor(args->color[0], args->color[1], args->color[2]);
1184+ args->voxelsTouched++;
1185+ return true;
1186+}
1187+
1188+bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) {
1189+
11671190 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1168− if (node->isColored()) {
1191+ args->totalVoxels++;
1192+
1193+ // if this node is staged for deletion, then just return
1194+ if (node->isStagedForDeletion()) {
1195+ args->stagedForDeletion++;
1196+ return true;
1197+ }
1198+
1199+ // If we are a parent, let's see if we're completely occluded.
1200+ if (!node->isLeaf()) {
1201+ args->nonLeaves++;
1202+
11691203 AABox voxelBox = node->getAABox();
11701204 voxelBox.scale(TREE_SCALE);
1171− VoxelProjectedShadow voxelShadow = args->viewFrustum->getProjectedShadow(voxelBox);
1172− if (args->occluder.occludes(voxelShadow)) {
1173− node->setFalseColor(255, 0, 0);
1205+ VoxelProjectedShadow* voxelShadow = new VoxelProjectedShadow(args->viewFrustum->getProjectedShadow(voxelBox));
1206+
1207+ // If we're not all in view, then ignore it, and just return. But keep searching...
1208+ if (!voxelShadow->getAllInView()) {
1209+ args->nonLeavesOutOfView++;
1210+ delete voxelShadow;
1211+ return true;
11741212 }
1175− }
1176− return true; // keep going!
1177−}
11781213
1179−void VoxelSystem::falseColorizeTestOccluded() {
1180− FalseColorizeOccludedArgs args;
1181− args.viewFrustum = Application::getInstance()->getViewFrustum();
1182−
1183− AABox box(glm::vec3(0.0125,0,0.025), 0.0125);
1184− box.scale(TREE_SCALE);
1185− args.occluder = args.viewFrustum->getProjectedShadow(box);
1214+ CoverageMap::StorageResult result = args->map->checkMap(voxelShadow, false);
1215+ if (result == CoverageMap::OCCLUDED) {
1216+ args->nonLeavesOccluded++;
1217+ delete voxelShadow;
1218+
1219+ FalseColorizeSubTreeOperationArgs subArgs;
1220+ subArgs.color[0] = 0;
1221+ subArgs.color[1] = 255;
1222+ subArgs.color[2] = 0;
1223+ subArgs.voxelsTouched = 0;
1224+
1225+ args->tree->recurseNodeWithOperation(node, falseColorizeSubTreeOperation, &subArgs );
1226+
1227+ args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1);
1228+ args->totalVoxels += (subArgs.voxelsTouched - 1);
1229+
1230+ return false;
1231+ }
11861232
1187− _tree->recurseTreeWithOperation(falseColorizeTestOccludedOperation,(void*)&args);
1188− setupNewVoxelsForDrawing();
1189−}
1233+ delete voxelShadow;
1234+ return true; // keep looking...
1235+ }
1236+
1237+ if (node->isLeaf() && node->isColored() && node->getShouldRender()) {
1238+ args->coloredVoxels++;
11901239
1191−bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) {
1192−//node->printDebugDetails(">>>>>>>>>>>>>>> falseColorizeOccludedOperation() BEGIN >>>>>>>>>>>>>>");
1193− FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1194− if (node->isColored() && node->isLeaf() && !node->isStagedForDeletion() && node->getShouldRender()) {
1195−//printLog("***** falseColorizeOccludedOperation() NODE is colored, etc, so consider it *****\n");
11961240 AABox voxelBox = node->getAABox();
11971241 voxelBox.scale(TREE_SCALE);
11981242 VoxelProjectedShadow* voxelShadow = new VoxelProjectedShadow(args->viewFrustum->getProjectedShadow(voxelBox));
1199− CoverageMap::StorageResult result = args->map->storeInMap(voxelShadow);
1243+
1244+ // If we're not all in view, then ignore it, and just return. But keep searching...
1245+ if (!voxelShadow->getAllInView()) {
1246+ args->outOfView++;
1247+ delete voxelShadow;
1248+ return true;
1249+ }
1250+
1251+ CoverageMap::StorageResult result = args->map->checkMap(voxelShadow, true);
12001252 if (result == CoverageMap::OCCLUDED) {
1201−//printLog("***** falseColorizeOccludedOperation() NODE is OCCLUDED *****\n");
12021253 node->setFalseColor(255, 0, 0);
1254+ args->occludedVoxels++;
12031255 } else if (result == CoverageMap::STORED) {
1204−//printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n");
1256+ args->notOccludedVoxels++;
1257+ //printLog("***** falseColorizeOccludedOperation() NODE is STORED *****\n");
12051258 } else if (result == CoverageMap::DOESNT_FIT) {
1206−//printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n");
1259+ //printLog("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n");
12071260 }
12081261 }
1209−//printLog("<<<<<<<<<<<<<<<<< falseColorizeOccludedOperation() END <<<<<<<<<<<<<<<<<\n");
12101262 return true; // keep going!
12111263 }
1212−
12131264 void VoxelSystem::falseColorizeOccluded() {
1265+ PerformanceWarning warn(true, "falseColorizeOccluded()",true);
12141266 CoverageMap map(BoundingBox(glm::vec2(-2.f,-2.f), glm::vec2(4.f,4.f)), true);
12151267 FalseColorizeOccludedArgs args;
12161268 args.viewFrustum = Application::getInstance()->getViewFrustum();
12171269 args.map = &map;
1270+ args.totalVoxels = 0;
1271+ args.coloredVoxels = 0;
1272+ args.occludedVoxels = 0;
1273+ args.notOccludedVoxels = 0;
1274+ args.outOfView = 0;
1275+ args.subtreeVoxelsSkipped = 0;
1276+ args.nonLeaves = 0;
1277+ args.stagedForDeletion = 0;
1278+ args.nonLeavesOutOfView = 0;
1279+ args.nonLeavesOccluded = 0;
1280+ args.tree = _tree;
12181281
1219− AABox box(glm::vec3(0.0125,0,0.025), 0.0125);
1220− box.scale(TREE_SCALE);
1221− args.occluder = args.viewFrustum->getProjectedShadow(box);
12221282 glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE);
12231283
12241284 _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args);
1285+
1286+ printLog("falseColorizeOccluded()\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n stagedForDeletion=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n",
1287+ args.totalVoxels, args.coloredVoxels, args.occludedVoxels,
1288+ args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped,
1289+ args.stagedForDeletion,
1290+ args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded);
1291+
1292+
12251293 setupNewVoxelsForDrawing();
12261294 }
12271295

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t