Changeset 154 for trunk/VUT/Ogre/src
- Timestamp:
- 07/04/05 17:57:51 (19 years ago)
- Location:
- trunk/VUT/Ogre/src
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
r153 r154 8 8 //----------------------------------------------------------------------- 9 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 10 PlatformQueryManager(hierarchyInterface, vp) , mWasInitialised(false)10 PlatformQueryManager(hierarchyInterface, vp) 11 11 { 12 12 } … … 23 23 bool relativeVisibility) 24 24 { 25 // initialise item buffer if necessary25 // initialise item buffer (if not already initialised) 26 26 InitItemBuffer(visibleNodes, visibleGeometry); 27 27 … … 45 45 sm->setOption("UseItemBuffer", &useItemBuffer); 46 46 47 // clear background with black 47 // clear background with black (i.e., not a valid item id) 48 48 ColourValue bg = mViewport->getBackgroundColour(); 49 49 mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0)); … … 70 70 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 71 71 72 72 73 // loop through frame buffer & collect visible pixels 73 74 for (int idx = 0; idx < dimy * dimx * 3; idx += 3) 74 75 { 76 // -- decode color code to receive id 75 77 int id = buf[idx] << 16; 76 78 id += buf[idx + 1] << 8; 77 79 id += buf[idx + 2]; 78 80 79 // if valid id <= add visibility 80 if ((id > =0) && (id < (int)visibleGeometry->size()))81 // if valid id <= add visibility (id values start at 1 82 if ((id > 0) && (id < (int)visibleGeometry->size())) 81 83 { 82 84 ((*visibleGeometry)[id]).AddVisibility(1, 1); 83 85 } 84 /* else 85 { 86 std::stringstream d; 87 d << "id: " << id << ", buf 1: " << (int)buf[idx] << ", buf 2: " << (int)buf[idx + 1] << ", buf 3: " << (int)buf[idx + 2]; 88 LogManager::getSingleton().logMessage(d.str()); 89 }*/ 86 /*else { std::stringstream d; 87 d << "adding pixel to geometry with id: " << id << ", buf 1: " << (int)buf[idx] << ", buf 2: " << (int)buf[idx + 1] << ", buf 3: " << (int)buf[idx + 2]; 88 LogManager::getSingleton().logMessage(d.str()); }*/ 90 89 } 91 90 … … 104 103 mWasInitialised = true; 105 104 106 SceneManager::EntityIterator it = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)-> 105 SceneManager::EntityIterator it = 106 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)-> 107 107 GetSceneManager()->getEntityIterator(); 108 108 109 109 // TODO: make this more efficient 110 110 visibleGeometry->clear(); 111 visibleNodes->clear(); 111 112 112 113 while (it.hasMoreElements()) … … 115 116 } 116 117 } 117 //-----------------------------------------------------------------------118 void ItemBufferQueryManager::ComputeFromPointVisibility(const Vector3 &point,119 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,120 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,121 bool relativeVisibility)122 {123 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>124 (mHierarchyInterface)->GetSceneManager();125 126 Camera *cam = sm->createCamera("PointQueryCam");127 128 //save old camera129 Camera *savedCam = mViewport->getCamera();130 131 // --- initialise new camera132 mViewport->setCamera(cam);133 cam->setPosition(point);134 135 cam->setNearClipDistance(savedCam->getNearClipDistance());136 cam->setFarClipDistance(savedCam->getFarClipDistance());137 138 // set frustum to 45 degrees so all the scene can be captured with 6 shots139 cam->setAspectRatio(1.0);140 cam->setFOVy(Radian(Math::HALF_PI));141 142 int sign = -1;143 144 // ---- capture visibility from all 6 directions145 for (int i=0; i < 6; i++)146 {147 sign *= -1;148 149 // Print camera details150 std::stringstream d;151 d << "Point query camera: " + StringConverter::toString(cam->getDerivedPosition()) +152 " " + "O: " + StringConverter::toString(cam->getDerivedOrientation());153 LogManager::getSingleton().logMessage(d.str());154 155 // prevent from initialising array again156 if (i > 0)157 mWasInitialised = true;158 159 // compute camera visibility for this direction160 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);161 162 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait"); // HACK: DISPLAY CAMERA VIEW163 164 // --- permute directions165 Vector3 dir(0,0,0);166 dir[i/2] = sign;167 168 cam->setDirection(dir);169 }170 171 // reset camera172 mViewport->setCamera(savedCam);173 }174 175 118 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
r139 r154 55 55 } 56 56 //----------------------------------------------------------------------- 57 void OctreeHierarchyInterface::SetNumOctreeNodes(unsigned int num)58 {59 mNumOctreeNodes = num;60 }61 //-----------------------------------------------------------------------62 57 float OctreeHierarchyInterface::GetSquaredDistance(GtpVisibility::HierarchyNode *node) const 63 58 { … … 173 168 SceneNodeHierarchyInterface::GetGeometry(*nodeIt, geometryList, includeChildren); 174 169 } 170 } 171 //----------------------------------------------------------------------- 172 void OctreeHierarchyInterface::SetNodeId(GtpVisibility::HierarchyNode *node, int id) 173 { 174 static_cast<Octree *>(node)->setId(id); 175 } 176 //----------------------------------------------------------------------- 177 int OctreeHierarchyInterface::GetNodeId(GtpVisibility::HierarchyNode *node) 178 { 179 return static_cast<Octree *>(node)->getId(); 175 180 } 176 181 //----------------------------------------------------------------------- -
trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
r153 r154 10 10 //----------------------------------------------------------------------- 11 11 PlatformQueryManager::PlatformQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 12 QueryManager(hierarchyInterface), mViewport(vp) 12 QueryManager(hierarchyInterface), mViewport(vp), mWasInitialised(false) 13 13 { 14 14 } … … 18 18 // run OGRE ray shooting query 19 19 return false; 20 }21 //-----------------------------------------------------------------------22 void PlatformQueryManager::ComputeCameraVisibility(const Camera &camera,23 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,24 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,25 bool relativeVisibility)26 {27 // we need access to the scene manager and the rendersystem28 PlatformHierarchyInterface *pfHierarchyInterface =29 dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface);30 31 //-- Render scene to get conservative visibility and fill depth buffer32 33 // const_cast allowed because camera is not changed in renderScene34 Camera *pCam = const_cast<Camera *>(&camera);35 36 // disable overlays, reset them later37 bool overlayEnabled = mViewport->getOverlaysEnabled();38 mViewport->setOverlaysEnabled(false);39 40 //-- render the scene once to update depth buffer41 pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);42 43 /*44 Two query lists for projected pixels and for visibile pixels:45 We test queries after a rendering pass46 to get exact visibility with regard to the current camera.47 We issue all queries at once to avoid starvation & stalls.48 */49 GtpVisibility::QueryList queryList[2];50 51 // get rendered hierarchy nodes52 GtpVisibility::HierarchyNodeList *nodeList = mHierarchyInterface->GetRenderedNodes();53 // vector for storing entities of meshes54 GtpVisibility::GeometryList geometryList;55 56 GtpVisibility::HierarchyNodeList::iterator nodeIt, nodeIt_end = nodeList->end();57 // geometry list has still do be built58 GtpVisibility::GeometryList::iterator geometryIt, geometryIt_end;59 60 // to obtain the correct number of projected pixels, depth write must be disabled61 bool enableDepthWrite = false;62 63 // this option must be provided by the scene manager64 pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);65 66 /* relative visiblity:67 1) get visible pixels count of objects68 2) clear frame buffer69 3) get projected visible pixels count:70 test all objects again without depth write (set as option in scene manager)71 4) calculate ratio between visible vs. projected pixels72 */73 // for relative visibility we need 2 rendering passes74 int n = relativeVisibility ? 2 : 1;75 76 for (int i=0; i<n; ++i)77 {78 //-- queries for hierarchy nodes79 for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)80 {81 // TODO: DELETE QUERIES FROM PREVIOUS RENDER82 queryList[i].push_back(mHierarchyInterface->IssueOcclusionQuery(*nodeIt, false));83 84 // store geometry of the hierarchy node in a geometry list (only once!)85 if (i == 0)86 {87 mHierarchyInterface->GetGeometry(*nodeIt, &geometryList, false);88 }89 }90 91 geometryIt_end = geometryList.end();92 93 //-- add queries for geometry94 for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)95 {96 queryList[i].push_back(mHierarchyInterface->IssueOcclusionQuery(*geometryIt));97 }98 99 100 pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_DEPTH);101 }102 103 enableDepthWrite = true;104 // this option must be provided by the scene manager105 pfHierarchyInterface->GetSceneManager()->setOption("DepthWrite", &enableDepthWrite);106 // reset old overlay status107 mViewport->setOverlaysEnabled(overlayEnabled);108 109 //---- collect results110 GtpVisibility::QueryList::iterator visQueryIt, projQueryIt;111 112 visQueryIt = queryList[0].begin();113 projQueryIt = queryList[1].begin();114 115 116 for (nodeIt = nodeList->begin(); nodeIt != nodeIt_end; ++nodeIt)117 {118 unsigned int visiblePixels = 0;119 (*visQueryIt)->GetQueryResult(visiblePixels, true);120 121 unsigned int projectedPixels = 0;122 123 if (relativeVisibility)124 {125 (*projQueryIt)->GetQueryResult(projectedPixels, true);126 127 ++projQueryIt;128 }129 130 ++visQueryIt;131 132 // node with visibilty 0 in queue (e.g., if node is intersected by near plane)133 if (visiblePixels > 0)134 {135 visibleNodes->push_back(GtpVisibility::NodeInfo(*nodeIt, visiblePixels, projectedPixels));136 }137 }138 139 //---- queries for geometry140 geometryIt_end = geometryList.end();141 142 for (geometryIt = geometryList.begin(); geometryIt != geometryIt_end; ++geometryIt)143 {144 unsigned int visiblePixels = 0;145 (*visQueryIt)->GetQueryResult(visiblePixels, true);146 147 unsigned int projectedPixels = 0;148 149 if (relativeVisibility)150 {151 (*projQueryIt)->GetQueryResult(projectedPixels, true);152 153 ++projQueryIt;154 }155 156 ++visQueryIt;157 158 // approximate depth ordering during rendering =>159 // geometry maybe occluded160 if (visiblePixels > 0)161 {162 visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt, visiblePixels,163 projectedPixels));164 }165 }166 167 }168 //-----------------------------------------------------------------------169 inline bool nodeinfo_eq(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2)170 {171 return info1.GetNode() == info2.GetNode();172 }173 //-----------------------------------------------------------------------174 inline bool meshinfo_eq(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2)175 {176 return info1.GetMesh() == info2.GetMesh();177 }178 //-----------------------------------------------------------------------179 inline bool nodeinfo_lower(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2)180 {181 return info1.GetNode() < info2.GetNode();182 }183 //-----------------------------------------------------------------------184 inline bool meshinfo_lower(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2)185 {186 return info1.GetMesh() < info2.GetMesh();187 20 } 188 21 //----------------------------------------------------------------------- … … 222 55 LogManager::getSingleton().logMessage(d.str()); 223 56 57 // prevent from initialising geometry / node array again 58 if (i > 0) 59 mWasInitialised = true; 60 224 61 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility); 225 62 … … 235 72 // reset camera 236 73 mViewport->setCamera(savedCam); 237 238 // --- remove duplicates (duplicates occur if an object is on the edge of the viewport)239 240 // before duplicates can be deleted we have to add up their visibility241 242 // --- visible nodes243 sort(visibleNodes->begin(), visibleNodes->end(), nodeinfo_lower);244 InfoContainer<GtpVisibility::NodeInfo>::iterator visibleNodesIt,245 visibleNodesIt_end = visibleNodes->end();246 247 GtpVisibility::NodeInfo *nodeInfo = NULL;248 249 for (visibleNodesIt = visibleNodes->begin(); visibleNodesIt != visibleNodesIt_end;250 ++visibleNodesIt)251 {252 if (!nodeInfo || (nodeInfo->GetNode() != (*visibleNodesIt).GetNode()))253 {254 nodeInfo = &(*visibleNodesIt);255 }256 else // add visibility257 {258 nodeInfo->AddVisibility(*visibleNodesIt);259 }260 261 }262 263 // physically delete duplicates264 visibleNodes->erase( std::unique(visibleNodes->begin(),265 visibleNodes->end(), nodeinfo_eq), visibleNodes->end());266 267 // --- visible geometry268 sort(visibleGeometry->begin(), visibleGeometry->end(), meshinfo_lower);269 InfoContainer<GtpVisibility::MeshInfo>::iterator visibleGeomIt,270 visibleGeomIt_end = visibleGeometry->end();271 272 GtpVisibility::MeshInfo *geomInfo = NULL;273 274 int i=0;275 for (visibleGeomIt = visibleGeometry->begin(); visibleGeomIt != visibleGeomIt_end;276 ++visibleGeomIt)277 {278 if (!geomInfo || (geomInfo->GetMesh() != (*visibleGeomIt).GetMesh()))279 {280 geomInfo = &(*visibleGeomIt);281 }282 else // info points to same mesh, just add visibility283 {284 geomInfo->AddVisibility(*visibleGeomIt);285 }286 }287 288 // physically delete duplicates289 visibleGeometry->erase(std::unique(visibleGeometry->begin(), visibleGeometry->end(),290 meshinfo_eq), visibleGeometry->end());291 292 74 } 293 75 //----------------------------------------------------------------------- -
trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
r139 r154 147 147 MovableObject *movable = objIt.getNext(); 148 148 149 // we are interested only in the entities, i.e., in tances of geometry149 // we are interested only in the entities, i.e., instances of geometry 150 150 if (movable->getMovableType() == "Entity") 151 151 { … … 156 156 } 157 157 } 158 //----------------------------------------------------------------------- 159 void SceneNodeHierarchyInterface::SetNodeId(GtpVisibility::HierarchyNode *node, int id) 160 { 161 static_cast<SceneNode *>(node)->setId(id); 162 } 163 //----------------------------------------------------------------------- 164 int SceneNodeHierarchyInterface::GetNodeId(GtpVisibility::HierarchyNode *node) 165 { 166 return static_cast<SceneNode *>(node)->getId(); 167 } 158 168 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
r139 r154 259 259 mHierarchyInterface->SetRenderSystem(mDestRenderSystem); 260 260 261 #ifdef GTP_VISIBILITY_MODIFIED_OGRE262 mHierarchyInterface->SetNumOctreeNodes(mNumOctreeNodes);263 #endif264 261 OctreeSceneManager::_updateSceneGraph(cam); 265 262 } -
trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
r153 r154 24 24 mUseDepthPass(false), 25 25 mRenderDepthPass(false), 26 //mUseItemBuffer(false),27 mUseItemBuffer(true),26 mUseItemBuffer(false), 27 //mUseItemBuffer(true), 28 28 mRenderItemBuffer(false), 29 mCurrentEntityId( 0),29 mCurrentEntityId(1), 30 30 mEnableDepthWrite(true), 31 31 mSkipTransparents(false), … … 327 327 328 328 // set the new render level index afterwards => new level in the next frame 329 int levelIdx = (TerrainRenderable::getCurrentRenderLevelIndex() + 1) % 10;329 int levelIdx = TerrainRenderable::getCurrentRenderLevelIndex() + 1; 330 330 TerrainRenderable::setCurrentRenderLevelIndex(levelIdx); 331 331 … … 343 343 mHierarchyInterface->SetRenderSystem(mDestRenderSystem); 344 344 345 #ifdef GTP_VISIBILITY_MODIFIED_OGRE346 mHierarchyInterface->SetNumOctreeNodes(mNumOctreeNodes);347 #endif348 345 TerrainSceneManager::_updateSceneGraph(cam); 349 346 } … … 567 564 int col[4]; 568 565 566 // -- create color code out of object id 569 567 col[0] = (rend->getId() >> 16) & 255; 570 568 col[1] = (rend->getId() >> 8) & 255; … … 599 597 600 598 Pass *usedPass = setPass(mItemBufferPass); 601 //Pass *usedPass = setPass(pass); 602 603 if (rend->getId() > 0) 599 600 /*if (rend->getId() > 0) 604 601 { 605 602 std::stringstream d; d << "item buffer id: " << rend->getId() << ", col: " << col[0] << 606 603 " " << col[1] << " " << col[2] << " " << col[3]; 607 604 LogManager::getSingleton().logMessage(d.str()); 608 } 605 }*/ 609 606 610 607 // Render a single object, this will set up auto params if required 611 608 renderSingleObject(rend, usedPass, false, &nullLightList); 612 613 // reset colour614 //mDestRenderSystem->setColour(255, 255, 255, 255);615 609 } 616 610 //----------------------------------------------------------------------- … … 630 624 } 631 625 626 // increase counter of entity id values 632 627 ++ mCurrentEntityId; 633 628
Note: See TracChangeset
for help on using the changeset viewer.