- Timestamp:
- 07/06/05 17:52:44 (19 years ago)
- Location:
- trunk/VUT
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibility/include/DummyQueryManager.h
r144 r159 25 25 InfoContainer<NodeInfo> *visibleNodes, 26 26 InfoContainer<MeshInfo> *visibleGeometry, 27 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 27 28 bool relativeVisibility = false ); 28 29 … … 34 35 InfoContainer<NodeInfo> *visibleNodes, 35 36 InfoContainer<MeshInfo> *visibleGeometry, 37 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 36 38 bool relativeVisibility = false 37 39 ); -
trunk/VUT/GtpVisibility/include/QueryManager.h
r144 r159 51 51 InfoContainer<NodeInfo> *visibleNodes, 52 52 InfoContainer<MeshInfo> *visibleGeometry, 53 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 53 54 bool relativeVisibility = false 54 55 ) = 0; … … 62 63 InfoContainer<NodeInfo> *visibleNodes, 63 64 InfoContainer<MeshInfo> *visibleGeometry, 65 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 64 66 bool relativeVisibility = false 65 67 ) = 0; -
trunk/VUT/GtpVisibility/include/VisibilityInfo.h
r150 r159 77 77 Mesh *mMesh; 78 78 }; 79 79 80 /** Class storing the visibility information of a patch, i.e., parts of meshes having the same material 81 properties. 82 */ 83 class PatchInfo: public VisibilityInfo 84 { 85 public: 86 PatchInfo(Patch *Patch, const int visiblePixels, const int projectedPixels); 87 88 Patch *GetPatch() const; 89 void SetPatch(Patch *patch); 90 91 protected: 92 93 /** Pointer to the patch. 94 */ 95 Patch *mPatch; 96 }; 97 80 98 //TODO: this define shall be replaced by template typedef 81 99 #define InfoContainer std::vector -
trunk/VUT/GtpVisibility/include/VisibilityMesh.h
r130 r159 7 7 namespace GtpVisibility { 8 8 typedef Ogre::Entity Mesh; 9 typedef Ogre::SubEntity Patch; 9 10 } 10 11 -
trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp
r155 r159 11 11 InfoContainer<NodeInfo> *visibleNodes, 12 12 InfoContainer<MeshInfo> *visibleGeometry, 13 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 13 14 bool relativeVisibility) 14 15 { … … 29 30 InfoContainer<NodeInfo> *visibleNodes, 30 31 InfoContainer<MeshInfo> *visibleGeometry, 32 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 31 33 bool relativeVisibility) 32 34 { -
trunk/VUT/GtpVisibility/src/VisibilityInfo.cpp
r153 r159 88 88 return mMesh; 89 89 } 90 91 /****************************************************/ 92 /* PatchInfo implementation */ 93 /****************************************************/ 94 //----------------------------------------------------------------------- 95 PatchInfo::PatchInfo(Patch *patch, const int visiblePixels, const int projectedPixels): 96 VisibilityInfo(visiblePixels, projectedPixels), mPatch(patch) 97 {} 98 //----------------------------------------------------------------------- 99 void PatchInfo::SetPatch(Patch *patch) 100 { 101 mPatch = patch; 102 } 103 //----------------------------------------------------------------------- 104 Patch *PatchInfo::GetPatch() const 105 { 106 return mPatch; 107 } 90 108 }// namespace GtpVisibility -
trunk/VUT/Ogre/include/OgreItemBufferQueryManager.h
r154 r159 7 7 8 8 /** 9 Class which implements the QueryManager for Ogre scene queries. 9 Class which implements the QueryManager for Ogre scene queries using an item buffer, 10 i.e., the objects are rendered with their id used as unique color code. After reading 11 back the frame buffer, the visibility information can be established for each object. 10 12 */ 11 13 class __declspec(dllexport) ItemBufferQueryManager: public PlatformQueryManager … … 13 15 public: 14 16 /** Constructor taking a hierarchy interface as an argument. This allows to operate 15 onm different hierarchy types, while reusing the implementation of the query methods. 17 on different hierarchy types, while reusing the implementation of the query methods. 18 @param renderPatches determines if the visibility of either patches or meshes is computed. 16 19 */ 17 ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp); 20 ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp, 21 const bool renderPatches); 18 22 19 23 void ComputeCameraVisibility(const Camera &camera, 20 24 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 21 25 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 26 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 22 27 bool relativeVisibility = false); 23 28 … … 25 30 26 31 protected: 27 void InitItemBuffer( InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 28 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry); 32 /** Helper function used to initialise item buffer. 33 */ 34 void InitItemBuffer( 35 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 36 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 37 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches); 29 38 39 /// if patches are used instead of meshes (only one at a time) 40 bool mRenderPatchesForItemBuffer; 30 41 }; 31 42 -
trunk/VUT/Ogre/include/OgreOcclusionQueriesQueryManager.h
r154 r159 7 7 8 8 /** 9 Class which implements the QueryManager for Ogre scene queries .9 Class which implements the QueryManager for Ogre scene queries using occlusion queries. 10 10 */ 11 11 class __declspec(dllexport) OcclusionQueriesQueryManager: public PlatformQueryManager … … 13 13 public: 14 14 /** Constructor taking a hierarchy interface as an argument. This allows to operate 15 onmdifferent hierarchy types, while reusing the implementation of the query methods.15 on different hierarchy types, while reusing the implementation of the query methods. 16 16 */ 17 17 OcclusionQueriesQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp); … … 20 20 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 21 21 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 22 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 22 23 bool relativeVisibility = false); 23 24 … … 29 30 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 30 31 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 32 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 31 33 bool relativeVisibility = false); 32 34 -
trunk/VUT/Ogre/include/OgrePlatformQueryManager.h
r154 r159 26 26 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 27 27 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 28 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 28 29 bool relativeVisibility = false); 29 30 -
trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
r139 r159 17 17 occlusion queries for visibility culling. 18 18 */ 19 class VisibilityOctreeSceneManager: public OctreeSceneManager19 class __declspec(dllexport) VisibilityOctreeSceneManager: public OctreeSceneManager 20 20 { 21 21 public: … … 59 59 void WriteLog(); 60 60 61 /** Override pass so we can do the z-fail pass */ 61 /** Override pass so we can do the z-fail pass. 62 */ 62 63 Pass* setPass(Pass* pass); 63 64 65 /** Override from SceneManager so we can skip all but first pass for depth pass. 66 */ 67 bool validatePassForRendering(Pass* pass); 68 69 void RenderItemBuffer(RenderPriorityGroup* pGroup); 70 void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass); 71 void renderQueueGroupObjects(RenderQueueGroup* pGroup); 72 73 /** Override from SceneManager so that sub entities can be assigned an id for item buffer. 74 */ 75 //Entity* createEntity(const String& entityName, const String& meshName); 76 77 /** Returns pointer to visibility manager. 78 */ 79 GtpVisibility::VisibilityManager *GetVisibilityManager(); 80 81 /** Returns hierarchy interface. 82 */ 83 OctreeHierarchyInterface *GetHierarchyInterface(); 84 85 64 86 protected: 65 /** Creates material for depth pass, e.g., a pass that only fills the depth buffer */ 87 88 /** Creates material for depth pass, e.g., a pass that only fills the depth buffer. 89 */ 66 90 void InitDepthPass(); 91 /** Creates material for item buffer. 92 */ 93 void InitItemBufferPass(); 94 /** Fills render queue so that a visualization can be rendered. 95 */ 96 void PrepareVisualization(Camera *cam); 97 /** Initialises necessary parameters for hierarchical visibility culling. 98 */ 99 void InitVisibilityCulling(Camera *cam); 67 100 68 /** Prepares visualization of hierarchical culling. */ 69 void PrepareVisualization(Camera *cam); 101 /// the interface to the scene hierarchy. 70 102 OctreeHierarchyInterface *mHierarchyInterface; 103 /// manages all visibility options 71 104 GtpVisibility::VisibilityManager *mVisibilityManager; 72 105 106 /// if a visualization of the hierarchical culling is shown 73 107 bool mShowVisualization; 74 bool mSkipTransparents; 108 109 /// if the culled nodes are indicated in the visualization 75 110 bool mVisualizeCulledNodes; 76 111 112 /// if symbols for the nodes are shown in the visualization 77 113 bool mRenderNodesForViz; 114 /// if content of the nodes is shown in the visualization 78 115 bool mRenderNodesContentForViz; 116 117 /// render transparents after the hierarchical traversal 79 118 bool mDelayRenderTransparents; 119 120 /// use a depth pass (i.e., fill only the depth buffer in the first pass) 80 121 bool mUseDepthPass; 122 /// flag indicating if we currently render the depth pass 81 123 bool mRenderDepthPass; 82 124 125 /// if we use an item buffer for rendering (i.e., object ids as color codes 126 bool mUseItemBuffer; 127 /// if we currently render the item buffer 128 bool mRenderItemBuffer; 129 130 /// if depth write should be enabled 131 bool mEnableDepthWrite; 132 /// if transparents are skipped during rendering 133 bool mSkipTransparents; 134 135 /// the depth pass (no lighting, just filling the depth buffer) 83 136 Pass *mDepthPass; 137 Pass *mItemBufferPass; 138 139 int mCurrentEntityId; 140 /// flag for passes which should not be deleted from queue during first traversal 141 int mLeavePassesInQueue; 142 ShadowTechnique mSavedShadowTechnique; 143 144 /// if transparent object are considered for item buffer visibility 145 bool mRenderTransparentsForItemBuffer; 146 /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer 147 bool mExecuteVertexProgramForAllPasses; 84 148 }; 85 149 -
trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
r158 r159 75 75 /** Override from SceneManager so that sub entities can be assigned an id for item buffer. 76 76 */ 77 Entity* createEntity(const String& entityName, const String& meshName);77 //Entity* createEntity(const String& entityName, const String& meshName); 78 78 79 79 /** Returns pointer to visibility manager. … … 84 84 */ 85 85 OctreeHierarchyInterface *GetHierarchyInterface(); 86 87 void endFrame(); 88 86 89 87 90 protected: … … 142 145 int mLeavePassesInQueue; 143 146 ShadowTechnique mSavedShadowTechnique; 147 148 /// if transparent object are considered for item buffer visibility 149 bool mRenderTransparentsForItemBuffer; 150 /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer 151 bool mExecuteVertexProgramForAllPasses; 144 152 }; 145 153 -
trunk/VUT/Ogre/resources/VisibilityDemo.overlay
r155 r159 452 452 caption [F] toggle filtering method (trilinear, anisotropic, bilinear) 453 453 } 454 element TextArea(Example/Visibility/Help/FromCameraQueryInfo): Example/Visibility/Templates/BasicText 455 { 456 left 5 457 top 285 458 width 180 459 height 30 460 caption [F5] From camera visible pixels (+ SHIFT: relative visibility) 461 } 462 element TextArea(Example/Visibility/Help/FromPointQueryInfo): Example/Visibility/Templates/BasicText 463 { 464 left 5 465 top 60 466 width 300 467 height 30 468 caption [F6] From camera visible pixels (+ SHIFT: relative visibility) 469 } 454 470 } 455 471 } … … 465 481 vert_align top 466 482 width 600 467 height 1 20483 height 145 468 484 left 200 469 485 top 300 … … 558 574 } 559 575 576 577 element TextArea(Example/Visibility/Query/VisiblePatches): Example/Visibility/Templates/BasicText 578 { 579 left 5 580 top 75 581 width 90 582 height 30 583 caption Visible patches 584 } 585 element TextArea(Example/Visibility/Query/VisiblePatchInfo): Example/Visibility/Templates/BasicText 586 { 587 left 180 588 top 75 589 width 90 590 height 30 591 caption : 592 } 593 560 594 element TextArea(Example/Visibility/Query/NodeVisibility): Example/Visibility/Templates/BasicText 561 595 { 562 596 left 5 563 top 75597 top 90 564 598 width 90 565 599 height 30 … … 570 604 { 571 605 left 180 572 top 75573 width 90 574 height 30 575 caption :606 top 90 607 width 90 608 height 30 609 caption : 576 610 } 577 611 … … 579 613 { 580 614 left 5 581 top 90615 top 105 582 616 width 90 583 617 height 30 … … 588 622 { 589 623 left 180 590 top 90 591 width 90 592 height 30 593 caption: 594 } 624 top 105 625 width 90 626 height 30 627 caption : 628 } 629 element TextArea(Example/Visibility/Query/PatchVisibility): Example/Visibility/Templates/BasicText 630 { 631 left 5 632 top 120 633 width 90 634 height 30 635 caption Avg. patch visibility 636 } 637 638 element TextArea(Example/Visibility/Query/PatchVisibilityInfo): Example/Visibility/Templates/BasicText 639 { 640 left 180 641 top 120 642 width 90 643 height 30 644 caption : 645 } 646 595 647 596 648 } -
trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
r158 r159 3 3 #include <OgreStringConverter.h> 4 4 #include <vector> 5 5 #include <OgreSubEntity.h> 6 6 7 7 namespace Ogre { 8 8 //----------------------------------------------------------------------- 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp): 10 PlatformQueryManager(hierarchyInterface, vp) 9 ItemBufferQueryManager::ItemBufferQueryManager(PlatformHierarchyInterface *hierarchyInterface, Viewport *vp, 10 const bool renderPatches): 11 PlatformQueryManager(hierarchyInterface, vp), mRenderPatchesForItemBuffer(renderPatches) 11 12 { 12 13 } … … 21 22 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 22 23 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 24 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 23 25 bool relativeVisibility) 24 26 { 25 27 // initialise item buffer (if not already initialised) 26 InitItemBuffer(visibleNodes, visibleGeometry );28 InitItemBuffer(visibleNodes, visibleGeometry, visiblePatches); 27 29 28 30 // we need access to the scene manager and the rendersystem … … 32 34 SceneManager *sm = pfHierarchyInterface->GetSceneManager(); 33 35 34 // --- -Render scene with item buffer (i.e., objects with their id as color codes)36 // --- Render scene with item buffer (i.e., objects with their id as color codes) 35 37 36 38 // const_cast allowed because camera is not changed in renderScene … … 61 63 uchar *buf = mViewport->getTarget()->getBufferContents(dimx, dimy); 62 64 65 int n = mRenderPatchesForItemBuffer ? (int)visiblePatches->size() : (int)visibleGeometry->size(); 63 66 64 67 // loop through frame buffer & collect visible pixels … … 71 74 72 75 // if valid id <= add visibility (id values start at 1 73 if ((id > 0) && (id < (int)visibleGeometry->size()))76 if ((id > 0) && (id < n)) 74 77 { 75 ((*visibleGeometry)[id]).AddVisibility(1, 1); 78 if (mRenderPatchesForItemBuffer) 79 { 80 ((*visiblePatches)[id]).AddVisibility(1, 1); 81 } 82 else 83 { 84 ((*visibleGeometry)[id]).AddVisibility(1, 1); 85 } 76 86 } 77 87 } … … 93 103 } 94 104 //----------------------------------------------------------------------- 95 void ItemBufferQueryManager::InitItemBuffer(InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 96 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry) 105 void ItemBufferQueryManager::InitItemBuffer( 106 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 107 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 108 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches) 97 109 { 98 110 if (mWasInitialised) … … 109 121 visibleGeometry->clear(); 110 122 visibleNodes->clear(); 123 visiblePatches->clear(); 111 124 125 int id = 0; 126 127 /* We can either use patches or meshes. If patches are used, an unique id must 128 be given each patch. Otherwise the same id must be given to all patches belonging 129 to the same mesh. 130 */ 112 131 while (it.hasMoreElements()) 113 132 { 114 visibleGeometry->push_back(GtpVisibility::MeshInfo(it.getNext(), 0, 0)); 133 Entity *ent = it.getNext(); 134 135 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 136 { 137 SubEntity *subEnt = ent->getSubEntity(i); 138 139 if (mRenderPatchesForItemBuffer) 140 { 141 ++ id; 142 visiblePatches->push_back(GtpVisibility::PatchInfo(subEnt, 0, 0)); 143 } 144 145 subEnt->setId(id); 146 } 147 148 if (!mRenderPatchesForItemBuffer) 149 { 150 visibleGeometry->push_back(GtpVisibility::MeshInfo(ent, 0, 0)); 151 ++ id; 152 } 115 153 } 116 154 } 117 155 156 /* 157 //----------------------------------------------------------------------- 158 Entity* VisibilityOctreeSceneManager::createEntity(const String& entityName, 159 const String& meshName) 160 { 161 Entity *ent = SceneManager::createEntity(entityName, meshName); 162 163 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 164 { 165 ent->getSubEntity(i)->setId(mCurrentEntityId); 166 } 167 168 // increase counter of entity id values 169 ++ mCurrentEntityId; 170 171 return ent; 172 } 173 */ 118 174 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp
r155 r159 21 21 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 22 22 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 23 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 23 24 bool relativeVisibility) 24 25 { … … 188 189 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 189 190 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 191 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 190 192 bool relativeVisibility) 191 193 { 192 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, visibleGeometry, relativeVisibility); 194 PlatformQueryManager::ComputeFromPointVisibility(point, visibleNodes, 195 visibleGeometry, visiblePatches, relativeVisibility); 193 196 194 197 // --- remove duplicates (duplicates occur if an object is on the edge of the viewport) -
trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
r158 r159 26 26 } 27 27 28 // if not all subtrees are empty 29 //if (octree->numNodes() > (int)octree->mNodes.size()) 28 //if (octree->numNodes() > (int)octree->mNodes.size()) // if not all subtrees are empty 30 29 if (!IsLeaf(node)) 31 30 { -
trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
r158 r159 200 200 } 201 201 //----------------------------------------------------------------------- 202 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(GtpVisibility::Mesh *mesh) 202 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery( 203 GtpVisibility::Mesh *mesh) 203 204 { 204 205 // get next available test id -
trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
r156 r159 23 23 InfoContainer<GtpVisibility::NodeInfo> *visibleNodes, 24 24 InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 25 InfoContainer<GtpVisibility::PatchInfo> *visiblePatches, 25 26 bool relativeVisibility) 26 27 { 27 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager(); 28 SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *> 29 (mHierarchyInterface)->GetSceneManager(); 30 31 // create a camera for the point query 28 32 Camera *cam = sm->createCamera("PointQueryCam"); 29 33 … … 61 65 } 62 66 63 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);67 ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, visiblePatches, relativeVisibility); 64 68 65 mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait");69 //mViewport->getTarget()->update(); for(int j=0; j<10000000; j++) printf("wait"); 66 70 67 71 // permute directions -
trunk/VUT/Ogre/src/OgreSceneContentGenerator.cpp
r130 r159 65 65 { 66 66 char name[25]; 67 67 68 sprintf(name, "%s Entity%d", objName.c_str(), GetObjectCount()); 68 69 -
trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
r156 r159 7 7 #include <OgreLogManager.h> 8 8 #include <OgreStringConverter.h> 9 #include <OgreEntity.h> 10 #include <OgreSubEntity.h> 9 11 10 12 … … 16 18 : 17 19 mVisibilityManager(visManager), 18 mRenderDepthPass(false),19 20 mShowVisualization(false), 20 21 mRenderNodesForViz(false), 21 22 mRenderNodesContentForViz(false), 22 23 mVisualizeCulledNodes(false), 24 mLeavePassesInQueue(0), 23 25 mDelayRenderTransparents(true), 24 mUseDepthPass(true), 25 mSkipTransparents(false) 26 mUseDepthPass(false), 27 mRenderDepthPass(false), 28 mUseItemBuffer(false), 29 //mUseItemBuffer(true), 30 mRenderItemBuffer(false), 31 mCurrentEntityId(1), 32 mEnableDepthWrite(true), 33 mSkipTransparents(false), 34 mSavedShadowTechnique(SHADOWTYPE_NONE), 35 mRenderTransparentsForItemBuffer(false), 36 mExecuteVertexProgramForAllPasses(false) 26 37 { 27 38 mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); … … 31 42 //mShowBoxes = true; 32 43 33 // TODO: find reasonable value for max depth44 // TODO: set maxdepth to reasonable value 34 45 mMaxDepth = 50; 35 46 } … … 65 76 } 66 77 //----------------------------------------------------------------------- 67 Pass *VisibilityOctreeSceneManager::setPass(Pass* pass) 68 { 69 // setting vertex program is not efficient 70 Pass *usedPass = ((mRenderDepthPass && pass->getDepthWriteEnabled() && 71 !pass->hasVertexProgram()) ? mDepthPass : pass); 72 73 /* 74 // set depth fill pass only if depth write enabled 75 Pass *usedPass = (mRenderDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass); 76 77 if (mRenderDepthPass && pass->hasVertexProgram()) 78 void VisibilityOctreeSceneManager::InitItemBufferPass() 79 { 80 MaterialPtr itemBufferMat = MaterialManager::getSingleton(). 81 getByName("Visibility/ItemBufferPass"); 82 83 if (itemBufferMat.isNull()) 78 84 { 79 // set vertex program of current pass to depth pass 80 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 81 82 if (mDepthPass->hasVertexProgram()) 83 { 84 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 85 // Load this program if not done already 86 if (!prg->isLoaded()) 87 prg->load(); 88 // Copy params 89 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 90 } 91 else if (mDepthPass->hasVertexProgram()) 92 { 93 mDepthPass->setVertexProgram(""); 94 } 95 }*/ 96 97 SceneManager::setPass(usedPass); 98 99 return usedPass; 85 // Init 86 itemBufferMat = MaterialManager::getSingleton().create("Visibility/ItemBufferPass", 87 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 88 89 mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 90 mItemBufferPass->setColourWriteEnabled(true); 91 mItemBufferPass->setDepthWriteEnabled(true); 92 mItemBufferPass->setLightingEnabled(true); 93 //mItemBufferPass->setLightingEnabled(false); 94 } 95 else 96 { 97 mItemBufferPass = itemBufferMat->getTechnique(0)->getPass(0); 98 } 99 //mItemBufferPass->setAmbient(1, 1, 0); 100 100 } 101 101 //----------------------------------------------------------------------- … … 131 131 if (mRenderNodesForViz) 132 132 { 133 getRenderQueue()->addRenderable(*it); 133 if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) 134 && (*it)->getAttachedObject(0)->getMovableType() == "Entity") 135 getRenderQueue()->addRenderable((*it)); 136 134 137 // addbounding boxes instead of node itself 135 138 //(*it)->_addBoundingBoxToQueue(getRenderQueue()); … … 141 144 } 142 145 } 143 146 } 147 //----------------------------------------------------------------------- 148 Pass *VisibilityOctreeSceneManager::setPass(Pass* pass) 149 { 150 // set depth fill pass if we currently do not make an aabb occlusion query 151 Pass *usedPass = (mRenderDepthPass && !mHierarchyInterface->IsBoundingBoxQuery() ? 152 mDepthPass : pass); 153 154 IlluminationRenderStage savedStage = mIlluminationStage; 155 156 // set illumination stage to NONE so no shadow material is used 157 // for depth pass or for occlusion query 158 if (mRenderDepthPass || mHierarchyInterface->IsBoundingBoxQuery()) 159 { 160 mIlluminationStage = IRS_NONE; 161 } 162 163 //-- set vertex program of current pass in order to set correct depth 164 if (mRenderDepthPass && mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 165 { 166 // add vertex program of current pass to depth pass 167 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 168 169 if (mDepthPass->hasVertexProgram()) 170 { 171 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 172 // Load this program if not done already 173 if (!prg->isLoaded()) 174 prg->load(); 175 // Copy params 176 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 177 } 178 } 179 else if (mDepthPass->hasVertexProgram()) 180 { 181 mDepthPass->setVertexProgram(""); 182 } 183 184 // store depth write flag to reset later 185 bool IsDepthWrite = usedPass->getDepthWriteEnabled(); 186 187 // global option which enables / disables depth writes 188 if (!mEnableDepthWrite) 189 { 190 usedPass->setDepthWriteEnabled(false); 191 } 192 //else if (mIsItemBufferPass) {usedPass = mItemBufferPass;} 193 194 Pass *result = SceneManager::setPass(usedPass); 195 196 // reset depth write 197 if (!mEnableDepthWrite) 198 { 199 usedPass->setDepthWriteEnabled(IsDepthWrite); 200 } 201 202 // reset illumination stage 203 mIlluminationStage = savedStage; 204 205 return result; 144 206 } 145 207 //----------------------------------------------------------------------- … … 153 215 else 154 216 { 155 mVisible.clear(); 156 mBoxes.clear(); 157 158 // if there is no depth pass => 159 // we interleave identification and rendering of objects 160 // in _renderVisibibleObjects 161 217 // for hierarchical culling, we interleave identification 218 // and rendering of objects in _renderVisibibleObjects 219 220 // for the shadow pass we use only standard rendering 221 // because of low occlusion 222 if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 223 mIlluminationStage == IRS_RENDER_TO_TEXTURE) 224 { 225 OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 226 } 162 227 // only shadow casters will be rendered in shadow texture pass 163 mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 164 } 228 // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 229 } 230 231 232 // -- delete lists stored for visualization 233 mVisible.clear(); 234 mBoxes.clear(); 165 235 } 166 236 //----------------------------------------------------------------------- 167 237 void VisibilityOctreeSceneManager::_renderVisibleObjects() 168 238 { 169 // create material for depth pass 170 InitDepthPass(); 171 172 // visualization: apply standard rendering 173 if (mShowVisualization) 239 // save ambient light to reset later 240 ColourValue savedAmbient = mAmbientLight; 241 242 //-- apply standard rendering for some modes (e.g., visualization, shadow pass) 243 244 if (mShowVisualization || 245 (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 246 mIlluminationStage == IRS_RENDER_TO_TEXTURE)) 247 { 248 IlluminationRenderStage savedStage = mIlluminationStage; 249 250 if (mShowVisualization) 251 { 252 // disable illumination stage to prevent rendering shadows 253 mIlluminationStage = IRS_NONE; 254 } 255 256 // standard rendering for shadow maps because of performance 257 OctreeSceneManager::_renderVisibleObjects(); 258 259 mIlluminationStage = savedStage; 260 } 261 else //-- the hierarchical culling algorithm 174 262 { 263 // don't render backgrounds for item buffer 264 if (mUseItemBuffer) 265 { 266 clearSpecialCaseRenderQueues(); 267 getRenderQueue()->clear(); 268 } 269 270 //-- hierarchical culling 271 // the objects of different layers (e.g., background, scene, 272 // overlay) must be identified and rendered one after another 273 274 //-- render all early skies 275 clearSpecialCaseRenderQueues(); 276 addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND); 277 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY); 278 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE); 279 175 280 OctreeSceneManager::_renderVisibleObjects(); 176 return;177 }178 179 //-- hierarchical culling180 // the objects of different layers (e.g., background, scene,181 // overlay) must be identified and rendered one after another182 183 bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass;184 185 // -- initialise interface for rendering traversal of the hierarchy186 mHierarchyInterface->SetHierarchyRoot(mOctree);187 188 // possible two cameras (one for culling, one for rendering)189 mHierarchyInterface->InitTraversal(mCameraInProgress,190 mCullCamera ? getCamera("CullCamera") : NULL,191 leaveTransparentsInQueue);192 193 194 // reset culling manager stats195 mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);196 197 mSkipTransparents = false;198 199 //-- render background, in case there is one200 clearSpecialCaseRenderQueues();201 addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);202 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);203 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);204 205 SceneManager::_renderVisibleObjects();206 281 207 282 208 283 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 209 _deleteRenderedQueueGroups(); 284 // delete previously rendered content 285 _deleteRenderedQueueGroups(); 210 286 #endif 211 287 212 //-- render visible objects (i.e., all but overlay) 213 clearSpecialCaseRenderQueues(); 214 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE); 215 addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 216 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 217 218 // transparents are skipped from hierarchical rendering 219 // => they need sorting, thus we render them afterwards 220 mSkipTransparents = mDelayRenderTransparents; 221 222 // set state for depth pass 223 mRenderDepthPass = mUseDepthPass; 224 225 /** 226 * the hierarchical culling algorithm 227 * for depth pass: will just find objects and update depth buffer 228 * for delayed rendering: will render all but transparents 229 **/ 230 231 mVisibilityManager->ApplyVisibilityCulling(); 232 233 //-- now we can savely render all remaining objects, e.g., transparents, overlay 234 mSkipTransparents = false; 235 236 clearSpecialCaseRenderQueues(); 237 SceneManager::_renderVisibleObjects(); 238 239 // for depth pass: add visible nodes found with the visibility culling 240 if (mUseDepthPass) 241 { 242 for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 243 { 244 (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 245 } 288 //-- prepare queue for visible objects (i.e., all but overlay and skies late) 289 clearSpecialCaseRenderQueues(); 290 addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE); 291 addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY); 292 setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE); 293 294 295 // set all necessary parameters for 296 // hierarchical visibility culling and rendering 297 InitVisibilityCulling(mCameraInProgress); 298 299 /** 300 * the hierarchical culling algorithm 301 * for depth pass: we just find objects and update depth buffer 302 * for "delayed" rendering: we render some passes afterwards 303 * e.g., transparents, because they need front-to-back sorting 304 **/ 305 306 mVisibilityManager->ApplyVisibilityCulling(); 307 308 // delete remaining renderables from queue (all not in mLeavePassesInQueue) 309 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 310 _deleteRenderedQueueGroups(mLeavePassesInQueue); 311 #endif 312 313 //-- reset parameters 246 314 mRenderDepthPass = false; 247 } 248 mSkipTransparents = false; 249 250 //-- now we can render all remaining queue objects 251 // for depth pass: all 252 // for delayed rendering: transparents, overlay 253 clearSpecialCaseRenderQueues(); 254 OctreeSceneManager::_renderVisibleObjects(); 255 256 WriteLog(); // write out stats 257 } 315 mRenderItemBuffer = false; 316 mSkipTransparents = false; 317 mLeavePassesInQueue = 0; 318 mShadowTechnique = mSavedShadowTechnique; 319 320 321 // add visible nodes found by the visibility culling algorithm 322 if (mUseDepthPass) 323 { 324 for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it) 325 { 326 (*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false); 327 } 328 } 329 330 //-- we render all remaining queue objects 331 // used for depth pass, transparents, overlay 332 clearSpecialCaseRenderQueues(); 333 OctreeSceneManager::_renderVisibleObjects(); 334 335 } // hierarchical culling 336 337 // reset ambient light 338 setAmbientLight(savedAmbient); 339 340 getRenderQueue()->clear(); // finally clear render queue 341 //WriteLog(); // write out stats 342 } 343 258 344 //----------------------------------------------------------------------- 259 345 void VisibilityOctreeSceneManager::_updateSceneGraph(Camera* cam) … … 312 398 return true; 313 399 } 400 401 if (key == "DepthWrite") 402 { 403 mEnableDepthWrite = (*static_cast<const bool *>(val)); 404 return true; 405 } 406 if (key == "UseItemBuffer") 407 { 408 mUseItemBuffer = (*static_cast<const bool *>(val)); 409 return true; 410 } 411 if (key == "ExecuteVertexProgramForAllPasses") 412 { 413 mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val)); 414 return true; 415 } 416 if (key == "RenderTransparentsForItemBuffer") 417 { 418 mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val)); 419 return true; 420 } 421 314 422 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 315 423 setOption(key, val) || OctreeSceneManager::setOption(key, val); … … 372 480 } 373 481 //----------------------------------------------------------------------- 374 void VisibilityOctreeSceneManager::renderObjects(const RenderPriorityGroup::TransparentRenderablePassList& objs, 482 void VisibilityOctreeSceneManager::renderObjects( 483 const RenderPriorityGroup::TransparentRenderablePassList& objs, 375 484 bool doLightIteration, const LightList* manualLightList) 376 485 { 486 // for correct rendering, transparents must be rendered after hierarchical culling 377 487 if (!mSkipTransparents) 378 488 { … … 380 490 } 381 491 } 382 492 //----------------------------------------------------------------------- 493 bool VisibilityOctreeSceneManager::validatePassForRendering(Pass* pass) 494 { 495 // skip all but first pass if we are doing the depth pass 496 if ((mRenderDepthPass || mRenderItemBuffer) && pass->getIndex() > 0) 497 { 498 return false; 499 } 500 return SceneManager::validatePassForRendering(pass); 501 } 502 //----------------------------------------------------------------------- 503 void VisibilityOctreeSceneManager::renderQueueGroupObjects(RenderQueueGroup* pGroup) 504 { 505 if (!mRenderItemBuffer) 506 { 507 OctreeSceneManager::renderQueueGroupObjects(pGroup); 508 return; 509 } 510 511 // --- item buffer 512 513 // Iterate through priorities 514 RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 515 516 while (groupIt.hasMoreElements()) 517 { 518 RenderItemBuffer(groupIt.getNext()); 519 } 520 } 521 //----------------------------------------------------------------------- 522 void VisibilityOctreeSceneManager::RenderItemBuffer(RenderPriorityGroup* pGroup) 523 { 524 // Do solids 525 RenderPriorityGroup::SolidRenderablePassMap solidObjs = pGroup->_getSolidPasses(); 526 527 // ----- SOLIDS LOOP ----- 528 RenderPriorityGroup::SolidRenderablePassMap::const_iterator ipass, ipassend; 529 ipassend = solidObjs.end(); 530 531 for (ipass = solidObjs.begin(); ipass != ipassend; ++ipass) 532 { 533 // Fast bypass if this group is now empty 534 if (ipass->second->empty()) 535 continue; 536 537 // Render only first pass 538 if (ipass->first->getIndex() > 0) 539 continue; 540 541 RenderPriorityGroup::RenderableList* rendList = ipass->second; 542 543 RenderPriorityGroup::RenderableList::const_iterator irend, irendend; 544 irendend = rendList->end(); 545 546 for (irend = rendList->begin(); irend != irendend; ++irend) 547 { 548 std::stringstream d; d << "itembuffer, pass name: " << 549 ipass->first->getParent()->getParent()->getName(); 550 551 LogManager::getSingleton().logMessage(d.str()); 552 553 RenderSingleObjectForItemBuffer(*irend, ipass->first); 554 } 555 } 556 557 // -- TRANSPARENT LOOP: must be handled differently 558 559 // transparents are treated either as solids or completely discarded 560 if (mRenderTransparentsForItemBuffer) 561 { 562 RenderPriorityGroup::TransparentRenderablePassList transpObjs = 563 pGroup->_getTransparentPasses(); 564 RenderPriorityGroup::TransparentRenderablePassList::const_iterator 565 itrans, itransend; 566 567 itransend = transpObjs.end(); 568 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 569 { 570 // like for solids, render only first pass 571 if (itrans->pass->getIndex() == 0) 572 { 573 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 574 } 575 } 576 } 577 } 578 //----------------------------------------------------------------------- 579 void VisibilityOctreeSceneManager::RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass) 580 { 581 static LightList nullLightList; 582 583 int col[4]; 584 585 // -- create color code out of object id 586 col[0] = (rend->getId() >> 16) & 255; 587 col[1] = (rend->getId() >> 8) & 255; 588 col[2] = rend->getId() & 255; 589 // col[3] = 255; 590 591 //mDestRenderSystem->setColour(col[0], col[1], col[2], col[3]); 592 593 mItemBufferPass->setAmbient(ColourValue(col[0] / 255.0f, 594 col[1] / 255.0f, 595 col[2] / 255.0f, 1)); 596 597 // set vertex program of current pass 598 if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 599 { 600 mItemBufferPass->setVertexProgram(pass->getVertexProgramName()); 601 602 if (mItemBufferPass->hasVertexProgram()) 603 { 604 const GpuProgramPtr& prg = mItemBufferPass->getVertexProgram(); 605 // Load this program if not done already 606 if (!prg->isLoaded()) 607 prg->load(); 608 // Copy params 609 mItemBufferPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 610 } 611 } 612 else if (mItemBufferPass->hasVertexProgram()) 613 { 614 mItemBufferPass->setVertexProgram(""); 615 } 616 617 Pass *usedPass = setPass(mItemBufferPass); 618 619 620 // Render a single object, this will set up auto params if required 621 renderSingleObject(rend, usedPass, false, &nullLightList); 622 } 623 //----------------------------------------------------------------------- 624 GtpVisibility::VisibilityManager *VisibilityOctreeSceneManager::GetVisibilityManager() 625 { 626 return mVisibilityManager; 627 } 628 //----------------------------------------------------------------------- 629 void VisibilityOctreeSceneManager::InitVisibilityCulling(Camera *cam) 630 { 631 InitDepthPass(); // create material for depth pass 632 InitItemBufferPass(); // create material for item buffer pass 633 634 // reset culling manager stats 635 mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes); 636 637 // save shadow technique. It will be reset after hierarchical culling 638 mSavedShadowTechnique = mShadowTechnique; 639 640 // render standard solids without shadows during hierarchical culling pass 641 if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) || 642 (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)) 643 { 644 mShadowTechnique = SHADOWTYPE_NONE; 645 } 646 647 // set depth pass flag before rendering 648 mRenderDepthPass = mUseDepthPass; 649 650 // item buffer needs full ambient lighting to use item colors as unique id 651 if (mUseItemBuffer) 652 { 653 mRenderItemBuffer = true; 654 setAmbientLight(ColourValue(1,1,1,1)); 655 } 656 657 658 // set passes which are stored in render queue 659 // for rendering AFTER hierarchical culling, i.e., passes which need 660 // a special rendering order 661 662 mLeavePassesInQueue = 0; 663 664 if (!mUseDepthPass || !mUseItemBuffer) 665 { 666 if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) 667 { 668 // TODO: remove this pass because it should be processed during hierarchical culling 669 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW; 670 671 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL; 672 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DIFFUSE_SPECULAR; 673 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 674 675 // just render ambient passes 676 mIlluminationStage = IRS_AMBIENT; 677 } 678 679 if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE) 680 { 681 mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW; 682 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 683 } 684 685 // transparents should be rendered after hierarchical culling to 686 // provide front-to-back ordering 687 if (mDelayRenderTransparents) 688 { 689 mLeavePassesInQueue |= RenderPriorityGroup::TRANSPARENT_PASSES; 690 } 691 } 692 693 // skip rendering transparents in the hierarchical culling 694 // (because they will be rendered afterwards) 695 mSkipTransparents = mUseDepthPass || 696 (mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES); 697 698 // -- initialise interface for rendering traversal of the hierarchy 699 mHierarchyInterface->SetHierarchyRoot(mOctree); 700 701 // possible two cameras (one for culling, one for rendering) 702 mHierarchyInterface->InitTraversal(mCameraInProgress, 703 mCullCamera ? getCamera("CullCamera") : NULL, 704 mLeavePassesInQueue); 705 706 //std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str()); 707 } 708 //----------------------------------------------------------------------- 709 OctreeHierarchyInterface *VisibilityOctreeSceneManager::GetHierarchyInterface() 710 { 711 return mHierarchyInterface; 712 } 713 //----------------------------------------------------------------------- 714 /*void VisibilityOctreeSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup) 715 { 716 // Basic render loop: Iterate through priorities 717 RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator(); 718 719 while (groupIt.hasMoreElements()) 720 { 721 RenderPriorityGroup* pPriorityGrp = groupIt.getNext(); 722 723 // Sort the queue first 724 pPriorityGrp->sort(mCameraInProgress); 725 726 // Do solids 727 // TODO: render other solid passes for shadows 728 renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true); 729 730 // do solid passes no shadows if addititive stencil shadows 731 if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) 732 renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true); 733 734 // Do transparents 735 renderObjects(pPriorityGrp->_getTransparentPasses(), true); 736 737 738 }// for each priority 739 } 740 */ 741 //----------------------------------------------------------------------- 742 /* 743 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 744 const String& meshName) 745 { 746 Entity *ent = SceneManager::createEntity(entityName, meshName); 747 748 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 749 { 750 ent->getSubEntity(i)->setId(mCurrentEntityId); 751 } 752 753 // increase counter of entity id values 754 ++ mCurrentEntityId; 755 756 return ent; 757 }*/ 383 758 } // namespace Ogre -
trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
r158 r159 31 31 mEnableDepthWrite(true), 32 32 mSkipTransparents(false), 33 mSavedShadowTechnique(SHADOWTYPE_NONE) 33 mSavedShadowTechnique(SHADOWTYPE_NONE), 34 mRenderTransparentsForItemBuffer(false), 35 mExecuteVertexProgramForAllPasses(false) 34 36 { 35 37 mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); … … 37 39 //mDisplayNodes = true; 38 40 //mShowBoundingBoxes = true; 41 //mShowBoxes = true; 42 //mShowBoxes = true; 39 43 40 44 // TODO: set maxdepth to reasonable value … … 48 52 if (depthMat.isNull()) 49 53 { 50 // Init51 54 depthMat = MaterialManager::getSingleton().create( 52 55 "Visibility/DepthPass", 53 56 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 57 54 58 mDepthPass = depthMat->getTechnique(0)->getPass(0); 55 59 mDepthPass->setColourWriteEnabled(false); … … 60 64 { 61 65 mDepthPass = depthMat->getTechnique(0)->getPass(0); 66 } 67 } 68 //----------------------------------------------------------------------- 69 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager() 70 { 71 if (mHierarchyInterface) 72 { 73 delete mHierarchyInterface; 74 mHierarchyInterface = NULL; 62 75 } 63 76 } … … 85 98 } 86 99 //mItemBufferPass->setAmbient(1, 1, 0); 87 }88 //-----------------------------------------------------------------------89 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()90 {91 if (mHierarchyInterface)92 {93 delete mHierarchyInterface;94 mHierarchyInterface = NULL;95 }96 100 } 97 101 //----------------------------------------------------------------------- … … 160 164 } 161 165 162 if (mRenderDepthPass) 163 { 164 // --- set vertex program of current pass so z-buffer is updated correctly 165 if (pass->hasVertexProgram()) 166 { 167 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 168 169 if (mDepthPass->hasVertexProgram()) 170 { 171 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 172 // Load this program if not done already 173 if (!prg->isLoaded()) 174 prg->load(); 175 // Copy params 176 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 177 } 178 } 179 else if (mDepthPass->hasVertexProgram()) 180 { 181 mDepthPass->setVertexProgram(""); 182 } 183 } 166 // --- set vertex program of current pass in order to set correct depth 167 if (mExecuteVertexProgramForAllPasses && mRenderDepthPass && pass->hasVertexProgram()) 168 { 169 // add vertex program of current pass to depth pass 170 mDepthPass->setVertexProgram(pass->getVertexProgramName()); 171 172 if (mDepthPass->hasVertexProgram()) 173 { 174 const GpuProgramPtr& prg = mDepthPass->getVertexProgram(); 175 // Load this program if not done already 176 if (!prg->isLoaded()) 177 prg->load(); 178 // Copy params 179 mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters()); 180 } 181 } 182 else if (mDepthPass->hasVertexProgram()) 183 { 184 mDepthPass->setVertexProgram(""); 185 } 186 184 187 185 188 bool IsDepthWrite = usedPass->getDepthWriteEnabled(); … … 228 231 // mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 229 232 } 230 //TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);233 231 234 232 235 // -- delete lists stored for visualization … … 240 243 ColourValue savedAmbient = mAmbientLight; 241 244 242 // --- apply standard rendering for some cases (e.g., visualization, shadow pass)245 //-- apply standard rendering for some modes (e.g., visualization, shadow pass) 243 246 244 247 if (mShowVisualization || … … 257 260 mIlluminationStage = savedStage; 258 261 } 259 else // 262 else //-- the hierarchical culling algorithm 260 263 { 261 264 // don't render backgrounds for item buffer … … 266 269 } 267 270 271 //-- hierarchical culling 268 272 // the objects of different layers (e.g., background, scene, 269 273 // overlay) must be identified and rendered one after another … … 279 283 280 284 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 281 // delete previously rendered conten bt285 // delete previously rendered content 282 286 _deleteRenderedQueueGroups(); 283 287 #endif … … 296 300 /** 297 301 * the hierarchical culling algorithm 298 * if we use a depth pass: will just find objects and update depth buffer 299 * for "delayed" rendering: will render some passes afterwards, e.g., transparents 302 * for depth pass: we just find objects and update depth buffer 303 * for "delayed" rendering: we render some passes afterwards 304 * e.g., transparents, because they need front-to-back sorting 300 305 **/ 301 306 … … 325 330 326 331 //-- now we can render all remaining queue objects 327 // for depth pass, transparents, overlay332 // used for depth pass, transparents, overlay 328 333 clearSpecialCaseRenderQueues(); 329 334 TerrainSceneManager::_renderVisibleObjects(); 330 335 } 331 336 332 // set the new render level index afterwards => new level in the next frame 333 int levelIdx = TerrainRenderable::getCurrentRenderLevelIndex() + 1; 334 TerrainRenderable::setCurrentRenderLevelIndex(levelIdx); 335 337 // set the new render level index 338 TerrainRenderable::NextRenderLevelIndex(); 339 336 340 // reset ambient light 337 341 setAmbientLight(savedAmbient); 338 342 339 getRenderQueue()->clear(); 343 getRenderQueue()->clear(); // finally clear render queue 340 344 //WriteLog(); // write out stats 341 345 } … … 397 401 return true; 398 402 } 399 // notifiy that frame has ended so terrain render level can be reset for correct 400 // terrain rendering 401 if (key == "TerrainLevelIdx") 402 { 403 TerrainRenderable::setCurrentRenderLevelIndex((*static_cast<const int *>(val))); 404 return true; 405 } 403 406 404 if (key == "DepthWrite") 407 405 { … … 414 412 return true; 415 413 } 416 414 if (key == "ExecuteVertexProgramForAllPasses") 415 { 416 mExecuteVertexProgramForAllPasses = (*static_cast<const bool *>(val)); 417 return true; 418 } 419 if (key == "RenderTransparentsForItemBuffer") 420 { 421 mRenderTransparentsForItemBuffer = (*static_cast<const bool *>(val)); 422 return true; 423 } 424 417 425 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 418 426 setOption(key, val) || TerrainSceneManager::setOption(key, val); … … 547 555 } 548 556 549 // ----- TRANSPARENT LOOP: must be handled differently 550 // TODO: HOW TO HANDLE OCCLUDED OBJECTS ???? 551 RenderPriorityGroup::TransparentRenderablePassList 552 transpObjs = pGroup->_getTransparentPasses(); 553 RenderPriorityGroup::TransparentRenderablePassList::const_iterator itrans, itransend; 554 555 itransend = transpObjs.end(); 556 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 557 { 558 // like for solids, render only first pass 559 if (itrans->pass->getIndex() == 0) 560 { 561 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 562 } 563 } 557 // -- TRANSPARENT LOOP: must be handled differently 558 559 // transparents are treated either as solids or completely discarded 560 if (mRenderTransparentsForItemBuffer) 561 { 562 RenderPriorityGroup::TransparentRenderablePassList transpObjs = 563 pGroup->_getTransparentPasses(); 564 RenderPriorityGroup::TransparentRenderablePassList::const_iterator 565 itrans, itransend; 566 567 itransend = transpObjs.end(); 568 for (itrans = transpObjs.begin(); itrans != itransend; ++itrans) 569 { 570 // like for solids, render only first pass 571 if (itrans->pass->getIndex() == 0) 572 { 573 RenderSingleObjectForItemBuffer(itrans->renderable, itrans->pass); 574 } 575 } 576 } 564 577 } 565 578 //----------------------------------------------------------------------- … … 583 596 584 597 // set vertex program of current pass 585 if ( pass->hasVertexProgram())598 if (mExecuteVertexProgramForAllPasses && pass->hasVertexProgram()) 586 599 { 587 600 mItemBufferPass->setVertexProgram(pass->getVertexProgramName()); … … 614 627 } 615 628 //----------------------------------------------------------------------- 616 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName,617 const String& meshName)618 {619 Entity *ent = SceneManager::createEntity(entityName, meshName);620 621 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i)622 {623 ent->getSubEntity(i)->setId(mCurrentEntityId);624 }625 626 // increase counter of entity id values627 ++ mCurrentEntityId;628 629 return ent;630 }631 //-----------------------------------------------------------------------632 629 void VisibilityTerrainSceneManager::InitVisibilityCulling(Camera *cam) 633 630 { … … 644 641 if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) || 645 642 (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)) 646 { 647 643 { 648 644 mShadowTechnique = SHADOWTYPE_NONE; 649 645 } … … 660 656 661 657 662 // set passes which should be stored in render queue658 // set passes which are stored in render queue 663 659 // for rendering AFTER hierarchical culling, i.e., passes which need 664 660 // a special rendering order … … 715 711 } 716 712 //----------------------------------------------------------------------- 713 void VisibilityTerrainSceneManager::endFrame() 714 { 715 TerrainRenderable::ResetRenderLevelIndex(); 716 } 717 //----------------------------------------------------------------------- 717 718 /*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup) 718 719 { … … 742 743 } 743 744 */ 745 //----------------------------------------------------------------------- 746 /* 747 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 748 const String& meshName) 749 { 750 Entity *ent = SceneManager::createEntity(entityName, meshName); 751 752 for (int i = 0; i < (int)ent->getNumSubEntities(); ++i) 753 { 754 ent->getSubEntity(i)->setId(mCurrentEntityId); 755 } 756 757 // increase counter of entity id values 758 ++ mCurrentEntityId; 759 760 return ent; 761 } 762 */ 744 763 } // namespace Ogre -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
r158 r159 103 103 mVisibilityManager(NULL), 104 104 mDelayedQueriesIssued(0.0), 105 mDelayedTraversedNodes(0.0) 105 mDelayedTraversedNodes(0.0), 106 mUseItemBuffer(false), 107 mRenderPatchesForItemBuffer(false) 106 108 { 107 109 //mInputDevice = PlatformManager::getSingleton().createInputReader(); … … 162 164 //-- visibility query stats overlay 163 165 mQueryTypeInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/QueryTypeInfo"); 166 164 167 mQueryVisibleNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleNodesInfo"); 165 168 mQueryVisibleGeometryInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleGeometryInfo"); 169 mQueryVisiblePatchInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisiblePatchInfo"); 170 166 171 mQueryNodeVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/NodeVisibilityInfo"); 167 172 mQueryGeometryVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/GeometryVisibilityInfo"); 173 mQueryPatchVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/PatchVisibilityInfo"); 168 174 169 175 // show stats overlays … … 294 300 295 301 //-- IMPORTANT: must be set, otherwise terrain is not rendered correctly 296 int terrainLevelIdx = 0; 297 mSceneMgr->setOption("TerrainLevelIdx", &terrainLevelIdx); 302 mSceneMgr->endFrame(); 298 303 299 304 //-- setup what is needed for immediate mouse/key movement … … 392 397 { 393 398 mQueryManager = new ItemBufferQueryManager(sm->GetHierarchyInterface(), 394 mWindow->getViewport(0) );399 mWindow->getViewport(0), mRenderPatchesForItemBuffer); 395 400 } 396 401 else … … 404 409 InfoContainer<GtpVisibility::NodeInfo> visibleNodes; 405 410 InfoContainer<GtpVisibility::MeshInfo> visibleGeometry; 411 InfoContainer<GtpVisibility::PatchInfo> visiblePatches; 406 412 407 413 if (fromPoint) … … 409 415 mQueryManager-> 410 416 ComputeFromPointVisibility(mCamNode->getPosition(), &visibleNodes, 411 &visibleGeometry, relativeVisibility);417 &visibleGeometry, &visiblePatches, relativeVisibility); 412 418 } 413 419 else 414 420 { 415 421 mQueryManager->ComputeCameraVisibility(*mCamera, 416 &visibleNodes, &visibleGeometry, relativeVisibility); 417 } 418 419 float averageNodeVis = 0; 420 float averageGeometryVis = 0; 421 int geomSize = 0; 422 int nodesSize = 0; 422 &visibleNodes, &visibleGeometry, &visiblePatches, relativeVisibility); 423 } 424 425 float averageNodeVis = 0, averageGeometryVis = 0, averagePatchVis = 0; 426 int geomSize = 0, nodesSize = 0, patchSize = 0; 423 427 424 428 InfoContainer<GtpVisibility::MeshInfo>::iterator geomIt, geomIt_end = visibleGeometry.end(); … … 458 462 } 459 463 464 InfoContainer<GtpVisibility::PatchInfo>::iterator patchIt, patchIt_end = visiblePatches.end(); 465 466 for (patchIt = visiblePatches.begin(); patchIt != patchIt_end; ++patchIt) 467 { 468 // add if not 0 469 if ((*patchIt).GetVisiblePixels()) 470 { 471 float vis = relativeVisibility ? 472 (*patchIt).ComputeRelativeVisibility() : (float)(*patchIt).GetVisiblePixels(); 473 474 averagePatchVis += vis; 475 ++patchSize; 476 477 std::stringstream d; d << "Patch visibility: " << vis; 478 LogManager::getSingleton().logMessage(d.str()); 479 } 480 } 481 460 482 if (nodesSize) 461 483 averageNodeVis /= (float)nodesSize; 462 484 if (geomSize) 463 485 averageGeometryVis /= (float)geomSize; 486 if (patchSize) 487 averagePatchVis /= (float)patchSize; 464 488 465 489 //-- update visibility queries stats … … 481 505 mQueryVisibleGeometryInfo->setCaption(str); 482 506 507 sprintf(str,": %d", (int)patchSize); 508 mQueryVisiblePatchInfo->setCaption(str); 509 483 510 sprintf(str,": %3.3f", averageNodeVis); 484 511 mQueryNodeVisibilityInfo->setCaption(str); … … 486 513 sprintf(str,": %3.3f", averageGeometryVis); 487 514 mQueryGeometryVisibilityInfo->setCaption(str); 515 516 sprintf(str,": %3.3f", averagePatchVis); 517 mQueryPatchVisibilityInfo->setCaption(str); 488 518 } 489 519 catch (...) … … 909 939 break; 910 940 911 941 case KC_F: 912 942 nextFilter(); 913 943 break; … … 929 959 case KC_S: 930 960 toggleShowShadows(); 961 break; 962 963 case KC_I: 964 mUseItemBuffer = !mUseItemBuffer; 965 break; 966 967 case KC_C: 968 mRenderPatchesForItemBuffer = !mRenderPatchesForItemBuffer; 931 969 break; 932 970 … … 959 997 break; 960 998 case KC_F5: 961 ApplyVisibilityQuery(false, mShiftPressed, false);999 ApplyVisibilityQuery(false, mShiftPressed, mUseItemBuffer); 962 1000 break; 963 1001 case KC_F6: 964 ApplyVisibilityQuery(true, mShiftPressed, false); 965 break; 966 case KC_F7: 967 ApplyVisibilityQuery(false, mShiftPressed, true); 968 break; 969 case KC_F8: 970 ApplyVisibilityQuery(true, mShiftPressed, true); 971 break; 1002 ApplyVisibilityQuery(true, mShiftPressed, mUseItemBuffer); 1003 break; 1004 972 1005 case KC_F11: 973 1006 takeScreenShot(); -
trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
r155 r159 169 169 OverlayElement *mQueryTypeInfo; 170 170 OverlayElement *mQueryVisibleNodesInfo; 171 OverlayElement *mQueryVisibleGeometryInfo; 171 OverlayElement *mQueryVisibleGeometryInfo; 172 OverlayElement *mQueryVisiblePatchInfo; 173 172 174 OverlayElement *mQueryVisiblityInfo; 173 175 OverlayElement *mQueryNodeVisibilityInfo; 174 176 OverlayElement *mQueryGeometryVisibilityInfo; 177 OverlayElement *mQueryPatchVisibilityInfo; 175 178 176 179 RayQueryExecutor *mRayQueryExecutor; … … 190 193 bool mShutdownRequested; 191 194 bool mDisplayCameraDetails; 192 195 bool mUseItemBuffer; 196 193 197 Real mVizCameraHeight; 194 198 … … 236 240 unsigned long mAvgFps; 237 241 unsigned long mFrameCount; 242 238 243 //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn; 239 244 PlatformQueryManager *mQueryManager; … … 241 246 float mDelayedQueriesIssued; 242 247 float mDelayedTraversedNodes; 248 249 bool mRenderPatchesForItemBuffer; 243 250 }; 244 251 -
trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
r156 r159 127 127 setupGui(); 128 128 129 // Floor plane130 /* 129 130 /* // occluder plane to test visibility 131 131 Plane plane; 132 132 plane.normal = Vector3::UNIT_Y; … … 138 138 pPlaneEnt->setMaterialName("Examples/Rockwall"); 139 139 pPlaneEnt->setCastShadows(true); 140 mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); 141 */ 140 mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); */ 141 142 142 mSceneMgr->setShadowTextureSettings(1024, 2); 143 143 mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5)); 144 //mSceneMgr->setShowDebugShadows(true); 145 144 146 145 147 146 //-- terrain content setup -
trunk/VUT/work/ogre_changes/OgreMain/include/OgreSceneManager.h
r139 r159 156 156 157 157 /** Renders an Ogre MovableObject. 158 @param mov the movable object to be rendered 159 @param leavePassesInQueue flag determining the passes which are left 160 in render queue after rendering 158 161 */ 159 162 void _renderMovableObject(MovableObject *mov, const int leavePassesInQueue); 160 163 164 /** Tells the scene manager that the frame ends (i.e., 165 one frame in the main loop. 166 */ 167 virtual void endFrame() {}; 161 168 #endif // GTP_VISIBILITY_MODIFIED_OGRE 162 169 -
trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/include/OgreTerrainRenderable.h
r154 r159 299 299 300 300 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 301 // index of renderlevel used for current pass302 static int getCurrentRenderLevelIndex();303 // returnsindex of renderlevel304 static void setCurrentRenderLevelIndex(int index);301 // resets index of renderlevel used for current pass 302 static void ResetRenderLevelIndex(); 303 // next index of renderlevel 304 static void NextRenderLevelIndex(); 305 305 #endif // GTP_VISIBILITY_MODIFIED_OGRE 306 306 -
trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreTerrainRenderable.cpp
r154 r159 1501 1501 #ifdef GTP_VISIBILITY_MODIFIED_OGRE 1502 1502 //----------------------------------------------------------------------- 1503 int TerrainRenderable::getCurrentRenderLevelIndex()1503 void TerrainRenderable::ResetRenderLevelIndex() 1504 1504 { 1505 return msCurrentRenderLevelIndex;1505 msCurrentRenderLevelIndex = 0; 1506 1506 } 1507 1507 //----------------------------------------------------------------------- 1508 void TerrainRenderable:: setCurrentRenderLevelIndex(int index)1508 void TerrainRenderable::NextRenderLevelIndex() 1509 1509 { 1510 if (index > MAX_RENDERLEVEL_INDEX) 1511 index = 0; 1512 1513 msCurrentRenderLevelIndex = index; 1510 if ((++ msCurrentRenderLevelIndex) > MAX_RENDERLEVEL_INDEX) 1511 msCurrentRenderLevelIndex = 0; 1514 1512 } 1515 1513 #endif // GTP_VISIBILITY_MODIFIED_OGRE
Note: See TracChangeset
for help on using the changeset viewer.