History

latest cut at occlusion culling

ZappoMan committed 13 years ago

Commit e2d22a81 parent b3ef9869 files · +114 −7Browse files

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

Unified · Split

interface/src/VoxelSystem.cpp+33−2
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include "Application.h"
2323 #include "Log.h"
2424 #include "VoxelConstants.h"
25+#include "CoverageMap.h"
2526 #include "InterfaceConfig.h"
2627 #include "renderer/ProgramObject.h"
2728
@@ -1159,9 +1160,10 @@ void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* dest · 1131 unmodified lines
11591160 struct FalseColorizeOccludedArgs {
11601161 VoxelProjectedShadow occluder;
11611162 ViewFrustum* viewFrustum;
1163+ CoverageMap* map;
11621164 };
11631165
1164−bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) {
1166+bool VoxelSystem::falseColorizeTestOccludedOperation(VoxelNode* node, void* extraData) {
11651167 FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
11661168 if (node->isColored()) {
11671169 AABox voxelBox = node->getAABox();
@@ -1174,15 +1176,44 @@ bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraDat · 6 unmodified lines
11741176 return true; // keep going!
11751177 }
11761178
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);
1186+
1187+ _tree->recurseTreeWithOperation(falseColorizeTestOccludedOperation,(void*)&args);
1188+ setupNewVoxelsForDrawing();
1189+}
1190+
1191+bool VoxelSystem::falseColorizeOccludedOperation(VoxelNode* node, void* extraData) {
1192+ FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData;
1193+ if (node->isColored() && node->isLeaf()) {
1194+ AABox voxelBox = node->getAABox();
1195+ voxelBox.scale(TREE_SCALE);
1196+ VoxelProjectedShadow* voxelShadow = new VoxelProjectedShadow(args->viewFrustum->getProjectedShadow(voxelBox));
1197+ CoverageMap::StorageResult result = args->map->storeInMap(voxelShadow);
1198+ if (result == CoverageMap::OCCLUDED) {
1199+ node->setFalseColor(255, 0, 0);
1200+ }
1201+ }
1202+ return true; // keep going!
1203+}
1204+
11771205 void VoxelSystem::falseColorizeOccluded() {
1206+ CoverageMap map(BoundingBox(glm::vec2(-1.f,-1.f), glm::vec2(2.f,2.f)), true);
11781207 FalseColorizeOccludedArgs args;
11791208 args.viewFrustum = Application::getInstance()->getViewFrustum();
1209+ args.map = ↦
11801210
11811211 AABox box(glm::vec3(0.0125,0,0.025), 0.0125);
11821212 box.scale(TREE_SCALE);
11831213 args.occluder = args.viewFrustum->getProjectedShadow(box);
11841214
1185− _tree->recurseTreeWithOperation(falseColorizeOccludedOperation,(void*)&args);
1215+ _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation,
1216+ args.viewFrustum->getPosition(), (void*)&args);
11861217 setupNewVoxelsForDrawing();
11871218 }
11881219

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