Index: /trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj
===================================================================
--- /trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 74)
+++ /trunk/VUT/GtpVisibility/scripts/GtpVisibility.vcproj	(revision 120)
@@ -107,4 +107,7 @@
 			</File>
 			<File
+				RelativePath="..\include\DistanceQueue.h">
+			</File>
+			<File
 				RelativePath="..\src\DummyPreprocessingManager.cpp">
 			</File>
@@ -145,7 +148,4 @@
 			</File>
 			<File
-				RelativePath="..\include\DistanceQueue.h">
-			</File>
-			<File
 				RelativePath="..\include\FrustumCullingManager.h">
 			</File>
Index: /trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp
===================================================================
--- /trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 112)
+++ /trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 120)
@@ -8,5 +8,5 @@
 HierarchyInterface::HierarchyInterface(): 
 mFrameId(0), mNumTraversedNodes(0), mNumRenderedNodes(0), 
-mSceneRoot(0), mPreviousNode(0), mCurrentTestIdx(0), mUseOptimization(true)
+mSceneRoot(0), mPreviousNode(0), mCurrentTestIdx(0), mUseOptimization(false)
 //, mIsShadowPass(false)
 {	
Index: /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 115)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.h	(revision 120)
@@ -71,23 +71,9 @@
    //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
 
-   void nextAlgorithm();
-   void changeThreshold(int incr);
-   void updateStats();
-
-   void toggleUseOptimization();
-   void toggleShowOctree();
-   void toggleUseDepthPass();
-   void toggleShowViz();
-   void nextNodeVizMode();
-   void toggleRecord();
-
-   void zoomVizCamera(int zoom);
+  void zoomVizCamera(int zoom);
 	
    void addFrameInfo(SceneNode *camNode, Real timeElapsed);
    void setCurrentFrameInfo(Real timeElapsed);
 
-   void setAppState(int state);
-   void nextAppState();
-
    void setAlgorithm(int algorithm);
 
@@ -97,5 +83,4 @@
    void loadFrames();
 
-   void toggleUseShadows();
   
 
@@ -106,5 +91,26 @@
     bool processUnbufferedMouseInput(const FrameEvent& evt);
 
-    void showDebugOverlay(bool show);
+    void showStats(bool show);
+
+	void updateStats();
+
+	void toggleShowHelp();
+	void toggleShowStats();
+
+	void toggleUseShadows();
+	void toggleDisplayCameraDetails();
+	void takeScreenShot();
+	void nextSceneDetailLevel();
+	void nextFilter();
+	void nextAlgorithm();
+	void nextNodeVizMode();
+	void nextAppState();
+    void changeThreshold(int incr);
+	
+	void toggleUseOptimization();
+	void toggleShowOctree();
+	void toggleUseDepthPass();
+	void toggleShowViz();
+	void toggleRecord();
 
 protected:
@@ -114,13 +120,21 @@
 	void Clamp2Terrain();
 	
-    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
-    SceneManager *mSceneMgr;           // A pointer to the scene manager
+	SceneManager *mSceneMgr;           // A pointer to the scene manager
     
 	CEGUI::Renderer *mGUIRenderer;     // cegui renderer
 	
-	bool mShutdownRequested;
 	int mCurrentAlgorithm;
 	int mVisibilityThreshold;
-	
+	// the current frame number
+	int mCurrentFrame;
+	// the current application state
+	int mAppState;
+	// The number of objects on the screen
+	int mObjectCount;            
+	// visualization mode
+	int mNodeVizMode;
+
+	SceneNode *mCurrentObject;    // the newly created object
+
 	OverlayElement *mAlgorithmInfo;
 	OverlayElement *mThresholdInfo;
@@ -135,7 +149,4 @@
 	OverlayElement *mQueriesIssuedInfo;
 
-	SceneNode *mCurrentObject;    // the newly created object
-	int mObjectCount;             // The number of objects on the screen
-
 	RayQueryExecutor *mRayQueryExecutor;
 	TerrainContentGenerator *mTerrainContentGenerator;
@@ -145,6 +156,13 @@
 	bool mUseDepthPass;
 	bool mShowVisualization;
-	int mNodeVizMode;
 	bool mCullCamera;
+	bool mRecord;
+	bool mUseShadows;
+	bool mVisualizeCulledNodes;
+	bool mShowHelp;
+	bool mStatsOn;
+	bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
+	bool mShutdownRequested;
+	bool mDisplayCameraDetails;
 
 	Real mVizCameraHeight;
@@ -156,14 +174,5 @@
 	std::vector<frame_info> mFrameInfo;
 		
-	int mCurrentFrame;
-	// the current application state
-	int mAppState;
-	bool mRecord;
 	Real mTimeElapsed;
-	bool mUseShadows;
-
-	bool mVisualizeCulledNodes;
-
-
 	//EventProcessor* mEventProcessor;
     InputReader* mInputDevice;
@@ -172,19 +181,23 @@
     Vector3 mTranslateVector;
     RenderWindow* mWindow;
-    bool mStatsOn;
-    bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
+   
+    //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
 	unsigned int mNumScreenShots;
-    float mMoveScale;
+    int mSceneDetailIndex;
+	int mAniso;
+
+	float mMoveScale;
     Degree mRotScale;
     // just to stop toggles flipping too fast
-    Real mTimeUntilNextToggle;
+    Real mTimeDelay;
     Radian mRotX, mRotY;
     TextureFilterOptions mFiltering;
-    int mAniso;
-
-	int mSceneDetailIndex;
-    Real mMoveSpeed;
+  
+	Real mMoveSpeed;
     Degree mRotateSpeed;
-    Overlay* mDebugOverlay;
+    
+	Overlay* mDebugOverlay;
+	Overlay* mHelpOverlay;
+	Overlay* mCullStatsOverlay;
 };
 
Index: /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 115)
+++ /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 120)
@@ -163,7 +163,7 @@
 
 		// the objects are generated on the whole terrain
+		mTerrainContentGenerator->GenerateScene(1500, "robot");
 		//mTerrainContentGenerator->GenerateScene(1500, "athene");
-		mTerrainContentGenerator->GenerateScene(1500, "robot");
-		//	mTerrainContentGenerator->GenerateScene(500, "ninja");
+		//mTerrainContentGenerator->GenerateScene(500, "ninja");
 	}
 
@@ -192,5 +192,5 @@
 	mTerrainFrameListener = new TerrainMouseQueryListener(mWindow, mCamera, mSceneMgr, 
 		mGUIRenderer, mTerrainContentGenerator, mVizCamera, mCamNode);
-	mTerrainFrameListener->showDebugOverlay(true);
+	
 	mRoot->addFrameListener(mTerrainFrameListener);
 }
Index: /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 115)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainMouseQueryListener.cpp	(revision 120)
@@ -13,10 +13,9 @@
 
 
-Real timeDelay = 0;
-#define KEY_PRESSED(_key,_timeDelay, _macro) \
+#define KEY_PRESSED(_key, _timeDelay, _macro) \
 { \
-    if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \
+    if (mInputDevice->isKeyDown(_key) && mTimeDelay <= 0) \
 { \
-    timeDelay = _timeDelay; \
+    mTimeDelay = _timeDelay; \
     _macro ; \
 } \
@@ -41,7 +40,6 @@
 mCamera(cam),
 mWindow(win),
-mStatsOn(true),
 mNumScreenShots(0),
-mTimeUntilNextToggle(0),
+mTimeDelay(0),
 mSceneDetailIndex(0),
 mMoveScale(0.0f),
@@ -51,7 +49,4 @@
 mFiltering(TFO_BILINEAR), 
 mGUIRenderer(renderer), 
-mShutdownRequested(false), 
-mLMouseDown(false),
-mRMouseDown(false),
 mSceneMgr(sceneManager),
 mCurrentObject(NULL),
@@ -60,31 +55,33 @@
 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING),
 //mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING),
+mNodeVizMode(NODEVIZ_NONE),
+mVizCameraHeight(Real(2500.0)),
+mCamNode(camNode),
+mAppState(WALKTHROUGH),
+mCurrentFrame(0),
+mTimeElapsed(0),
+mRotateSpeed(72),
+mMoveSpeed(50),
+mVizCamera(vizCamera),
+mStatsOn(true),
+mShutdownRequested(false), 
+mLMouseDown(false),
+mRMouseDown(false),
 mShowOctree(false),
 mUseDepthPass(false),
 mUseOptimization(true),
-mVizCamera(vizCamera),
 mShowVisualization(false),
-mNodeVizMode(NODEVIZ_NONE),
-mVizCameraHeight(Real(2500.0)),
-mCamNode(camNode),
 mCullCamera(false),
-mAppState(WALKTHROUGH),
-mCurrentFrame(0),
 mRecord(false),
-mTimeElapsed(0),
 mUseShadows(false),
-mVisualizeCulledNodes(false),
-mRotateSpeed(72),
-mMoveSpeed(50)
-{
-	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
-	
-    mInputDevice = PlatformManager::getSingleton().createInputReader();
+mShowHelp(false),
+mDisplayCameraDetails(false),
+mVisualizeCulledNodes(false)
+{
+	mInputDevice = PlatformManager::getSingleton().createInputReader();
 	mInputDevice->initialise(win, true, true);
 
-    showDebugOverlay(true);
-    
-	// Register this so that we get mouse events.
-	/*mEventProcessor->addMouseListener(this);
+	/*
+	mEventProcessor->addMouseListener(this);
 	mEventProcessor->addMouseMotionListener(this);
 	mEventProcessor->addKeyListener(this);
@@ -94,7 +91,11 @@
 	mRayQueryExecutor = new RayQueryExecutor(mSceneMgr);
 	
-	//-- show visibility overlay
-	Overlay* pOver = OverlayManager::getSingleton().getByName("Example/VisibilityDemoOverlay"); 
-
+	mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 
+	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
+
+
+	//-- visibility culling stats overlay
+	mCullStatsOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/DemoOverlay"); 
+	
 	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo");
 	mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo");
@@ -121,17 +122,22 @@
 	mUseDepthPassInfo->setCaption(": false");
 	mQueriesIssuedInfo->setCaption(": 0");
-	
-	pOver->show();
-
+
+	// show stats overlays
+	showStats(true);
+	//mHelpOverlay->show();
 
 	// set culling algorithm type
 	setAlgorithm(mCurrentAlgorithm);
 
-
 	// set scene manager options
 	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
-	bool delayedRendering = !mUseOptimization;
-	mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering);
+
+	// apply delayed rendering (i.e., transparents after hierarchical culling pass)
+	// only if optimization is not used 
+	bool delayRenderTransparents = !mUseOptimization;
+
+	mSceneMgr->setOption("DelayRenderTransparents", &delayRenderTransparents);
 	mSceneMgr->setOption("UseDepthPass", &mUseDepthPass);
+	
 	mSceneMgr->setOption("ShowOctree", &mShowOctree);
 	mSceneMgr->setOption("CullCamera", &mCullCamera);
@@ -229,6 +235,6 @@
 		 
 	 //-- setup what is needed for immediate mouse/key movement
-	 if (mTimeUntilNextToggle >= 0) 
-		 mTimeUntilNextToggle -= evt.timeSinceLastFrame;
+	 if (mTimeDelay >= 0) 
+		 mTimeDelay -= evt.timeSinceLastFrame;
 
 	 // If this is the first frame, pick a speed
@@ -329,29 +335,5 @@
 		return false;
 
-    if (timeDelay >= 0) 
-        timeDelay -= evt.timeSinceLastFrame;
-
-	KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
-
-	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
-	KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
-	KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass());
-	KEY_PRESSED(KC_1, 0.3, toggleShowViz());
-	KEY_PRESSED(KC_2, 0.3, nextNodeVizMode());
-	
-	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
-	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
-	
-	KEY_PRESSED(KC_4, 0, zoomVizCamera(50));
-	KEY_PRESSED(KC_5, 0, zoomVizCamera(-50));
-
-	KEY_PRESSED(KC_F1, 0.3, nextAppState());
-	KEY_PRESSED(KC_F2, 0.3, toggleRecord());
-	KEY_PRESSED(KC_F3, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename));
-	KEY_PRESSED(KC_F4, 0.3, toggleUseShadows());
-	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
-	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
-
-	updateStats();
+    updateStats();
 
 	return true;
@@ -408,9 +390,4 @@
 	}
 	ifstr.close();
-}
-//-----------------------------------------------------------------------
-void TerrainMouseQueryListener::setAppState(int state)
-{
-	mAppState = state;
 }
 //-----------------------------------------------------------------------
@@ -608,7 +585,11 @@
 	
 	if (mUseDepthPass)
+	{
 		mUseDepthPassInfo->setCaption(": true");
+	}
 	else
+	{
 		mUseDepthPassInfo->setCaption(": false");
+	}
 }
 //-----------------------------------------------------------------------
@@ -673,5 +654,6 @@
 	mNodeVizMode = (mNodeVizMode + 1) % NODEVIZ_MODES_NUM;
 
-	bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
+	bool renderNodesForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES) || 
+		(mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
 	bool renderNodesContentForViz = (mNodeVizMode == NODEVIZ_RENDER_NODES_AND_CONTENT);
 	//bool renderNodesContentForViz = mNodeVizMode == NODEVIZ_RENDER_GEOMETRY;
@@ -752,38 +734,19 @@
 bool TerrainMouseQueryListener::processUnbufferedKeyInput(const FrameEvent& evt)
 {
-    if (mInputDevice->isKeyDown(KC_A))
+	if (mInputDevice->isKeyDown(KC_ESCAPE))
+    {            
+        return false;
+    }
+
+	/* Move camera forward by keypress. */
+    if (mInputDevice->isKeyDown(KC_UP))
+	{
+		mTranslateVector.z = -mMoveScale;
+	}
+
+    /* Move camera backward by keypress. */
+    if (mInputDevice->isKeyDown(KC_DOWN))
     {
-        // Move camera left
-        mTranslateVector.x = -mMoveScale;
-    }
-
-    if (mInputDevice->isKeyDown(KC_D))
-    {
-        // Move camera RIGHT
-        mTranslateVector.x = mMoveScale;
-    }
-
-    /* Move camera forward by keypress. */
-    if (mInputDevice->isKeyDown(KC_UP) || mInputDevice->isKeyDown(KC_W) )
-    {
-        mTranslateVector.z = -mMoveScale;
-    }
-
-    /* Move camera backward by keypress. */
-    if (mInputDevice->isKeyDown(KC_DOWN) || mInputDevice->isKeyDown(KC_S) )
-    {
-        mTranslateVector.z = mMoveScale;
-    }
-
-    if (mInputDevice->isKeyDown(KC_PGUP))
-    {
-        // Move camera up
-        mTranslateVector.y = mMoveScale;
-    }
-
-    if (mInputDevice->isKeyDown(KC_PGDOWN))
-    {
-        // Move camera down
-        mTranslateVector.y = -mMoveScale;
+		mTranslateVector.z = mMoveScale;
     }
 
@@ -798,73 +761,34 @@
     }
 
-    if( mInputDevice->isKeyDown( KC_ESCAPE) )
-    {            
-        return false;
-    }
-	
-	if (mInputDevice->isKeyDown(KC_F) && mTimeUntilNextToggle <= 0)
-    {
-        mStatsOn = !mStatsOn;
-        showDebugOverlay(mStatsOn);
-
-        mTimeUntilNextToggle = 1;
-    }
-    if (mInputDevice->isKeyDown(KC_T) && mTimeUntilNextToggle <= 0)
-    {
-        switch(mFiltering)
-        {
-        case TFO_BILINEAR:
-            mFiltering = TFO_TRILINEAR;
-            mAniso = 1;
-            break;
-        case TFO_TRILINEAR:
-            mFiltering = TFO_ANISOTROPIC;
-            mAniso = 8;
-            break;
-        case TFO_ANISOTROPIC:
-            mFiltering = TFO_BILINEAR;
-            mAniso = 1;
-            break;
-        default:
-            break;
-        }
-        MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
-        MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
-
-
-        showDebugOverlay(mStatsOn);
-
-        mTimeUntilNextToggle = 1;
-    }
-
-    if (mInputDevice->isKeyDown(KC_SYSRQ) && mTimeUntilNextToggle <= 0)
-    {
-		char tmp[20];
-		sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
-        mWindow->writeContentsToFile(tmp);
-        mTimeUntilNextToggle = 0.5;
-		mWindow->setDebugText(String("Wrote ") + tmp);
-    }
-	
-	if (mInputDevice->isKeyDown(KC_R) && mTimeUntilNextToggle <=0)
-	{
-		mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
-		switch(mSceneDetailIndex) {
-			case 0 : mCamera->setDetailLevel(SDL_SOLID) ; break ;
-			case 1 : mCamera->setDetailLevel(SDL_WIREFRAME) ; break ;
-			case 2 : mCamera->setDetailLevel(SDL_POINTS) ; break ;
-		}
-		mTimeUntilNextToggle = 0.5;
-	}
-
-    static bool displayCameraDetails = false;
-    if (mInputDevice->isKeyDown(KC_P) && mTimeUntilNextToggle <= 0)
-    {
-        displayCameraDetails = !displayCameraDetails;
-        mTimeUntilNextToggle = 0.5;
-        if (!displayCameraDetails)
-            mWindow->setDebugText("");
-    }
-    if (displayCameraDetails)
+	KEY_PRESSED(KC_SPACE, 0.3, nextAlgorithm());
+	KEY_PRESSED(KC_F, 0.3, nextFilter());
+	KEY_PRESSED(KC_R, 0.3, nextSceneDetailLevel());
+
+	KEY_PRESSED(KC_P, 0.3, toggleDisplayCameraDetails());
+	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
+	KEY_PRESSED(KC_T, 0.3, toggleShowOctree());
+	KEY_PRESSED(KC_X, 0.3, toggleUseDepthPass());
+	KEY_PRESSED(KC_S, 0.3, toggleUseShadows());
+
+	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
+	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
+	
+	//-- visualization
+	KEY_PRESSED(KC_1, 0.3, toggleShowViz());
+	KEY_PRESSED(KC_2, 0.3, nextNodeVizMode());
+	KEY_PRESSED(KC_3, 0, zoomVizCamera(50));
+	KEY_PRESSED(KC_4, 0, zoomVizCamera(-50));
+
+	KEY_PRESSED(KC_F1, 0.3, toggleShowHelp());
+	KEY_PRESSED(KC_F2, 0.3, toggleShowStats());
+	KEY_PRESSED(KC_F3, 0.3, nextAppState());
+	
+	KEY_PRESSED(KC_F10, 0.3, toggleRecord());
+	KEY_PRESSED(KC_F11, 0.3, takeScreenShot());
+	KEY_PRESSED(KC_F12, 0.3, mTerrainContentGenerator->WriteObjects(objects_out_filename));
+	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
+	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
+
+	if (mDisplayCameraDetails)
     {
         // Print camera details
@@ -877,4 +801,57 @@
 }
 //-----------------------------------------------------------------------
+void TerrainMouseQueryListener::nextFilter()
+{
+	switch(mFiltering)
+	{
+	case TFO_BILINEAR:
+		mFiltering = TFO_TRILINEAR;
+		mAniso = 1;
+		break;
+	case TFO_TRILINEAR:
+		mFiltering = TFO_ANISOTROPIC;
+		mAniso = 8;
+		break;
+	case TFO_ANISOTROPIC:
+		mFiltering = TFO_BILINEAR;
+		mAniso = 1;
+		break;
+	default:
+		break;
+	}
+
+    MaterialManager::getSingleton().setDefaultTextureFiltering(mFiltering);
+    MaterialManager::getSingleton().setDefaultAnisotropy(mAniso);
+
+    showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::nextSceneDetailLevel()
+{
+	mSceneDetailIndex = (mSceneDetailIndex+1)%3 ;
+	switch(mSceneDetailIndex) 
+	{
+		case 0 : mCamera->setDetailLevel(SDL_SOLID) ; break ;
+		case 1 : mCamera->setDetailLevel(SDL_WIREFRAME) ; break ;
+		case 2 : mCamera->setDetailLevel(SDL_POINTS) ; break ;
+	}
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::takeScreenShot()
+{
+	char tmp[20];
+	sprintf(tmp, "screenshot_%d.png", ++mNumScreenShots);
+    mWindow->writeContentsToFile(tmp);
+    mWindow->setDebugText(String("Wrote ") + tmp);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleDisplayCameraDetails()
+{
+	mDisplayCameraDetails = !mDisplayCameraDetails;
+        
+    if (!mDisplayCameraDetails)
+		mWindow->setDebugText("");
+}
+//-----------------------------------------------------------------------
 bool TerrainMouseQueryListener::processUnbufferedMouseInput(const FrameEvent& evt)
 {
@@ -897,21 +874,42 @@
 	return true;
 }
-
-void TerrainMouseQueryListener::showDebugOverlay(bool show)
-{
-	if (mDebugOverlay)
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::showStats(bool show)
+{
+	if (mDebugOverlay && mCullStatsOverlay)
 	{
 		if (show)
 		{
 			mDebugOverlay->show();
+			mCullStatsOverlay->show();
 		}
 		else
 		{
 			mDebugOverlay->hide();
+			mCullStatsOverlay->hide();
 		}
 	}
 }
-
-
-	
-	
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleShowStats()
+{
+	mStatsOn = !mStatsOn;
+
+	showStats(mStatsOn);
+}
+//-----------------------------------------------------------------------
+void TerrainMouseQueryListener::toggleShowHelp()
+{
+	mShowHelp = !mShowHelp;
+
+	if (mShowHelp)
+	{
+		mHelpOverlay->show();
+	}
+	else
+	{
+		mHelpOverlay->hide();
+	}
+}
+
+	
Index: /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h
===================================================================
--- /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 115)
+++ /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 120)
@@ -84,11 +84,8 @@
 	/** see set */
 	bool GetOnlyShadowCasters();
+	/** see set */
+	bool GetUseOptimization();
 
 protected:
-	/** true if query should test using geomery whenever it is possible, false if 
-		bounding boxes are always used.
-	*/
-	bool UseOptimization() const;
-
 	/** materials for visualizing frustum and query culled nodes */
 	void CreateNodeVizMaterials();
Index: /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 119)
+++ /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 120)
@@ -15,5 +15,4 @@
 	GtpVisibility::VisibilityManager *visManager): 
 mVisibilityManager(visManager), 
-mUseDepthPass(false),
 mIsDepthPass(false),
 mShowVisualization(false),
@@ -22,10 +21,10 @@
 mVisualizeCulledNodes(false),
 mSkipTransparents(false),
-mDelayRenderTransparents(true)
-{
-	mHierarchyInterface = 
-		new OctreeHierarchyInterface(this, mDestRenderSystem);
-
-    //mDisplayNodes = true;
+mDelayRenderTransparents(true),
+mUseDepthPass(false)
+{
+	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
+
+	//mDisplayNodes = true;
 	//mShowBoundingBoxes = true;
 
@@ -57,40 +56,160 @@
 VisibilityTerrainSceneManager::~VisibilityTerrainSceneManager()
 {
-	delete mHierarchyInterface;
-}
-//-----------------------------------------------------------------------
-Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
-{
+	if (mHierarchyInterface)
+	{
+		delete mHierarchyInterface;
+		mHierarchyInterface = NULL;
+	}
+}
+//-----------------------------------------------------------------------
+/*Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
+{
+	static bool myLastUsedVertexProgram = false;
+    static bool myLastUsedFragmentProgram = false;
+
 	// set depth fill pass only if depth write enabled
-	Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass);
-
-	if (mIsDepthPass)
-	{
-		//if (pass->isTransparent())	return pass;
-
-		// set vertex program of current pass
-        if (pass->hasVertexProgram() && (pass->getVertexProgramName() != mDepthPass->getVertexProgramName()))
-		{
-			mDepthPass->setVertexProgram(pass->getVertexProgramName());
-
-			if (mDepthPass->hasVertexProgram())
-			{
-				const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
-				// Load this program if not done already
-				if (!prg->isLoaded()) prg->load();
-				// Copy params
-				mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
-			}
-		}
-		else if (mDepthPass->hasVertexProgram())
-		{
-			mDepthPass->setVertexProgram("");
-		}
-	}
-
-	TerrainSceneManager::setPass(usedPass);
+	Pass *usedPass = pass;
+
+	if (mIsDepthPass && pass->getDepthWriteEnabled())
+	{
+		usedPass = mDepthPass;		
+	}
+
+    if (mIlluminationStage == IRS_RENDER_TO_TEXTURE)
+    {
+        // Derive a special shadow caster pass from this one
+        usedPass = deriveShadowCasterPass(usedPass);
+    }
+    else if (mIlluminationStage == IRS_RENDER_MODULATIVE_PASS)
+    {
+        usedPass = deriveShadowReceiverPass(usedPass);
+    }
+
+	bool passSurfaceAndLightParams = true;
+
+	// take original pass here
+    if (usedPass->hasVertexProgram())
+    {
+        mDestRenderSystem->bindGpuProgram(usedPass->getVertexProgram()->_getBindingDelegate());
+        // bind parameters later since they can be per-object
+        myLastUsedVertexProgram = true;
+        // does the vertex program want surface and light params passed to rendersystem?
+        passSurfaceAndLightParams = usedPass->getVertexProgram()->getPassSurfaceAndLightStates();
+    }
+    else
+    {
+        // Unbind program?
+        if (myLastUsedVertexProgram)
+        {
+            mDestRenderSystem->unbindGpuProgram(GPT_VERTEX_PROGRAM);
+            myLastUsedVertexProgram = false;
+        }
+        // Set fixed-function vertex parameters
+    }
+
+    if (passSurfaceAndLightParams)
+    {
+        // Set surface reflectance properties, only valid if lighting is enabled
+        if (usedPass->getLightingEnabled())
+        {
+            mDestRenderSystem->_setSurfaceParams( 
+                usedPass->getAmbient(), 
+                usedPass->getDiffuse(), 
+                usedPass->getSpecular(), 
+                usedPass->getSelfIllumination(), 
+                usedPass->getShininess(),
+				usedPass->getVertexColourTracking() );
+        }
+
+        // Dynamic lighting enabled?
+        mDestRenderSystem->setLightingEnabled(usedPass->getLightingEnabled());
+    }
+
+    // Using a fragment program?
+    if (usedPass->hasFragmentProgram())
+    {
+        mDestRenderSystem->bindGpuProgram(
+            usedPass->getFragmentProgram()->_getBindingDelegate());
+        // bind parameters later since they can be per-object
+        myLastUsedFragmentProgram = true;
+    }
+    else
+    {
+        // Unbind program?
+        if (myLastUsedFragmentProgram)
+        {
+            mDestRenderSystem->unbindGpuProgram(GPT_FRAGMENT_PROGRAM);
+            myLastUsedFragmentProgram = false;
+        }
+
+        // Set fixed-function fragment settings
+
+        // Fog (assumes we want pixel fog which is the usual)
+        // New fog params can either be from scene or from material
+        FogMode newFogMode;
+        ColourValue newFogColour;
+        Real newFogStart, newFogEnd, newFogDensity;
+        if (usedPass->getFogOverride())
+        {
+            // New fog params from material
+            newFogMode = usedPass->getFogMode();
+            newFogColour = usedPass->getFogColour();
+            newFogStart = usedPass->getFogStart();
+            newFogEnd = usedPass->getFogEnd();
+            newFogDensity = usedPass->getFogDensity();
+        }
+        else
+        {
+            // New fog params from scene
+            newFogMode = mFogMode;
+            newFogColour = mFogColour;
+            newFogStart = mFogStart;
+            newFogEnd = mFogEnd;
+            newFogDensity = mFogDensity;
+        }
+        mDestRenderSystem->_setFog(newFogMode, newFogColour, newFogDensity, newFogStart, newFogEnd);
+
+	}
+
+    // The rest of the settings are the same no matter whether we use programs or not
+
+    // Set scene blending
+    mDestRenderSystem->_setSceneBlending(
+        usedPass->getSourceBlendFactor(), usedPass->getDestBlendFactor());
+
+
+    // Texture unit settings
+
+    Pass::TextureUnitStateIterator texIter =  usedPass->getTextureUnitStateIterator();
+    size_t unit = 0;
+    while(texIter.hasMoreElements())
+    {
+        TextureUnitState* pTex = texIter.getNext();
+        mDestRenderSystem->_setTextureUnitSettings(unit, *pTex);
+        ++unit;
+    }
+    // Disable remaining texture units
+    mDestRenderSystem->_disableTextureUnitsFrom(usedPass->getNumTextureUnitStates());
+
+    // Set up non-texture related material settings
+    // Depth buffer settings
+    mDestRenderSystem->_setDepthBufferFunction(usedPass->getDepthFunction());
+    mDestRenderSystem->_setDepthBufferCheckEnabled(usedPass->getDepthCheckEnabled());
+    mDestRenderSystem->_setDepthBufferWriteEnabled(usedPass->getDepthWriteEnabled());
+    mDestRenderSystem->_setDepthBias(usedPass->getDepthBias());
+	// Alpha-reject settings
+	mDestRenderSystem->_setAlphaRejectSettings(
+		usedPass->getAlphaRejectFunction(), usedPass->getAlphaRejectValue());
+    // Set colour write mode
+    // Right now we only use on/off, not per-channel
+    bool colWrite = usedPass->getColourWriteEnabled();
+    mDestRenderSystem->_setColourBufferWriteEnabled(colWrite, colWrite, colWrite, colWrite);
+    // Culling mode
+    mDestRenderSystem->_setCullingMode(usedPass->getCullingMode());
+    // Shading
+    mDestRenderSystem->setShadingType(usedPass->getShadingMode());
 
 	return usedPass;
-}
+}*/
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam)
@@ -138,4 +257,42 @@
 }
 //-----------------------------------------------------------------------
+Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
+{
+	// setting vertex program is not efficient
+	//Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);		
+	// set depth fill pass only if depth write enabled
+	Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass);
+	
+	if (mIsDepthPass)
+	{
+		// set vertex program of current pass
+        if (pass->hasVertexProgram())
+		{
+			mDepthPass->setVertexProgram(pass->getVertexProgramName());
+
+			if (mDepthPass->hasVertexProgram())
+			{
+				const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
+				// Load this program if not done already
+				if (!prg->isLoaded())
+					prg->load();
+				// Copy params
+				mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
+			}
+		}
+		else if (mDepthPass->hasVertexProgram())
+		{
+			mDepthPass->setVertexProgram("");
+		}
+	}
+	/*else if (mIsItemBufferPass)
+	{
+		usedPass = mItemBufferPass;
+	}*/
+	SceneManager::setPass(usedPass);
+
+	return usedPass;
+}
+//-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
 {
@@ -232,4 +389,5 @@
 		mIsDepthPass = false;
 	}
+
 	mSkipTransparents = false;
 
@@ -342,5 +500,8 @@
 	std::stringstream d;
 
-	d << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
+	d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
+	  << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
+	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", "
+	  << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
 	  << "Hierarchy nodes: " << mNumOctreeNodes << ", " 
 	  << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
Index: /trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 115)
+++ /trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 120)
@@ -48,5 +48,5 @@
 extern "C" void dllStartPlugin(void)
 {
-	//visEnv = new GtpVisibility::VisibilityEnvironment();
+	visEnv = new GtpVisibility::VisibilityEnvironment();
 	visManager = new GtpVisibility::VisibilityManager(visEnv);
 
@@ -64,6 +64,4 @@
 	Root::getSingleton().setSceneManager(ST_EXTERIOR_CLOSE, visibilityTerrainPlugin);
 	//Root::getSingleton().setSceneManager(ST_GENERIC, occlusionDotPlugin);
-
-	LogManager::getSingleton().logMessage("registered akira plugins");
 }
 //-----------------------------------------------------------------------
@@ -77,5 +75,5 @@
 
 	delete visManager;
-	//delete visEnv;
+	delete visEnv;
 }
 
Index: /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 119)
+++ /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 120)
@@ -16,5 +16,4 @@
 : 
 mVisibilityManager(visManager), 
-mUseDepthPass(false),
 mIsDepthPass(false),
 mShowVisualization(false),
@@ -23,8 +22,8 @@
 mVisualizeCulledNodes(false),
 mSkipTransparents(false),
-mDelayRenderTransparents(true)
-{
-	mHierarchyInterface = 
-		new OctreeHierarchyInterface(this, mDestRenderSystem);
+mDelayRenderTransparents(true),
+mUseDepthPass(true)
+{
+	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
 		
 	//mDisplayNodes = true;
@@ -60,5 +59,9 @@
 VisibilityOctreeSceneManager::~VisibilityOctreeSceneManager()
 {
-	delete mHierarchyInterface;
+	if (mHierarchyInterface)
+	{
+		delete mHierarchyInterface;
+		mHierarchyInterface = NULL;
+	}
 }
 //-----------------------------------------------------------------------
@@ -66,24 +69,23 @@
 {
 	// setting vertex program is not efficient
-	//Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);		
+	Pass *usedPass = ((mIsDepthPass && pass->getDepthWriteEnabled() && !pass->hasVertexProgram()) ? mDepthPass : pass);		
+
+	/*
 	// set depth fill pass only if depth write enabled
 	Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass);
 
-	if (mIsDepthPass)
-	{
-		// set vertex program of current pass
-        if (pass->hasVertexProgram())
+    if (mIsDepthPass && pass->hasVertexProgram())
+    {
+		// set vertex program of current pass to depth pass
+		mDepthPass->setVertexProgram(pass->getVertexProgramName());
+
+		if (mDepthPass->hasVertexProgram())
 		{
-			mDepthPass->setVertexProgram(pass->getVertexProgramName());
-
-			if (mDepthPass->hasVertexProgram())
-			{
-				const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
-				// Load this program if not done already
-				if (!prg->isLoaded())
-					prg->load();
-				// Copy params
-				mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
-			}
+			const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
+			// Load this program if not done already
+			if (!prg->isLoaded())
+				prg->load();
+			// Copy params
+			mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
 		}
 		else if (mDepthPass->hasVertexProgram())
@@ -91,7 +93,7 @@
 			mDepthPass->setVertexProgram("");
 		}
-	}
-
-	OctreeSceneManager::setPass(usedPass);
+	}*/
+
+	SceneManager::setPass(usedPass);
 
 	return usedPass;
@@ -234,11 +236,11 @@
 	// for depth pass: add visible nodes found with the visibility culling
 	if (mUseDepthPass)
-{
+	{
 		for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
-	{
+		{
 			(*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
-	}
+		}
 		mIsDepthPass = false;
-        }
+    }
 	mSkipTransparents = false;
 		
@@ -249,5 +251,5 @@
 	SceneManager::_renderVisibleObjects();
 	
-	//WriteLog(); // write out stats
+	WriteLog(); // write out stats
 }
 //-----------------------------------------------------------------------
@@ -351,5 +353,8 @@
 	std::stringstream d;
 
-	d << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
+	d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
+	  << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
+	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", "
+	  << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << "\n"
 	  << "Hierarchy nodes: " << mNumOctreeNodes << ", " 
 	  << "Traversed nodes: " << mHierarchyInterface->GetNumTraversedNodes() << ", "
@@ -358,4 +363,9 @@
 	  << "Frustum culled nodes: " << mVisibilityManager->GetCullingManager()->GetNumFrustumCulledNodes() << ", "
       << "Queries issued: " << mVisibilityManager->GetCullingManager()->GetNumQueriesIssued() << "\n";
+	  /*<< "avg. FPS: " << mCurrentViewport->getTarget()->getAverageFPS() << ", "
+	  << "best FPS: " << mCurrentViewport->getTarget()->getBestFPS() << ", "
+	  << "worst FPS: " << mCurrentViewport->getTarget()->getWorstFPS() << ", "
+	  << "best frame time: " <<	mCurrentViewport->getTarget()->getBestFrameTime() << ", "
+	  << "worst frame time: " << mCurrentViewport->getTarget()->getWorstFrameTime() << "\n";*/
 
 	LogManager::getSingleton().logMessage(d.str());
Index: /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 118)
+++ /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 120)
@@ -86,6 +86,6 @@
 	
 	// set no depth write, no color, no lighting material
-	mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
-	//SetOcclusionPass();
+	//mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
+	SetOcclusionPass();
 
 	solidBox->SetupBoundingBoxVertices(*box);
@@ -166,13 +166,4 @@
 }
 //-----------------------------------------------------------------------
-bool PlatformHierarchyInterface::UseOptimization() const
-{
-	/* If camera for culling is different from camera for rendering or only solids
-	   will be rendereded => cannot optimize
-    */
-	return mUseOptimization && (mCamera == mCullCamera);
-}
-
-//-----------------------------------------------------------------------
 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueOcclusionQuery(
 	GtpVisibility::HierarchyNode *node, const bool wasVisible) 
@@ -186,5 +177,7 @@
 	// if node is leaf and was visible => will be rendered anyway.
 	// In this case we can also test with the real geometry.
-	if (UseOptimization() && wasVisible && IsLeaf(node) ) 
+	// If camera for culling is different from camera for rendering or only solids 
+	// will be rendereded => cannot optimize
+	if (mUseOptimization && (mCamera == mCullCamera) && wasVisible && IsLeaf(node) ) 
 	{
 		//LogManager::getSingleton().logMessage("render node\n");
@@ -240,3 +233,8 @@
 	return mOnlyShadowCasters;
 }
+//-----------------------------------------------------------------------
+bool PlatformHierarchyInterface::GetUseOptimization()
+{
+	return mUseOptimization;
+}
 } // namespace Ogre
Index: /trunk/VUT/Ogre/resources/VisibilityDemo.overlay
===================================================================
--- /trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 115)
+++ /trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 120)
@@ -1,3 +1,16 @@
-Example/VisibilityDemoOverlay
+template element TextArea(Example/Visibility/Templates/BasicText)
+{
+	metrics_mode pixels
+	left 5
+	top 5
+	width 180
+	height 30
+	font_name TrebuchetMSBold
+	char_height 16
+	colour_top 0.5 0.7 0.5
+	colour_bottom 0.3 0.5 0.3
+}
+
+Example/Visibility/DemoOverlay
 {
 	zorder 500
@@ -24,108 +37,67 @@
 
 
-		element TextArea(Example/Visibility/Algorithm)
-		{
-			metrics_mode pixels
+		element TextArea(Example/Visibility/Algorithm): Example/Visibility/Templates/BasicText
+		{
 			left 5
 			top 5
 			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
 			caption [SPACE] Algorithm
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/AlgorithmInfo)
-		{
-			metrics_mode pixels
+		}
+		element TextArea(Example/Visibility/AlgorithmInfo): Example/Visibility/Templates/BasicText
+		{
 			left 155
 			top 5
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-
-		element TextArea(Example/Visibility/Threshold)
-		{
-			metrics_mode pixels
+			caption :
+		}
+
+		element TextArea(Example/Visibility/Threshold): Example/Visibility/Templates/BasicText
+		{
 			left 5
 			top 20
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
 			caption [-][+] Threshold
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/ThresholdInfo)
-		{
-			metrics_mode pixels
+		}
+		element TextArea(Example/Visibility/ThresholdInfo): Example/Visibility/Templates/BasicText
+		{
 			left 155
 			top 20
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/UseOptimization)
-		{
-			metrics_mode pixels
+			caption :
+		}
+		element TextArea(Example/Visibility/UseOptimization): Example/Visibility/Templates/BasicText
+		{
 			left 5
 			top 35
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
 			caption [O] Optimization
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/UseOptimizationInfo)
-		{
-			metrics_mode pixels
+		}
+		element TextArea(Example/Visibility/UseOptimizationInfo): Example/Visibility/Templates/BasicText
+		{
 			left 155
 			top 35
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/UseDepthPass)
-		{
-			metrics_mode pixels
+			caption :
+		}
+		element TextArea(Example/Visibility/UseDepthPass): Example/Visibility/Templates/BasicText
+		{
 			left 5
 			top 50
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
 			caption [X] Depth pass
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/UseDepthPassInfo)
-		{
-			metrics_mode pixels
+		}
+		element TextArea(Example/Visibility/UseDepthPassInfo): Example/Visibility/Templates/BasicText
+		{
 			left 155
 			top 50
 			width 90
 			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
+			caption :
 		}
 
@@ -153,186 +125,282 @@
 	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
 
-		element TextArea(Example/Visibility/FrustumCulledNodes)
-		{
-			metrics_mode pixels
+		element TextArea(Example/Visibility/FrustumCulledNodes): Example/Visibility/Templates/BasicText
+		{
 			left 5
 			top 5
 			width 180
 			height 30
+			caption Frustum Culled Nodes
+		}
+		element TextArea(Example/Visibility/FrustumCulledNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 5
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/QueryCulledNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 20
+			width 180
+			height 30
+			caption Query Culled Nodes
+		}	
+		element TextArea(Example/Visibility/QueryCulledNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 20
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/TraversedNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 35
+			width 180
+			height 30
+			caption Traversed Nodes
+		}	
+		element TextArea(Example/Visibility/TraversedNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 35
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/HierarchyNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 50
+			width 180
+			height 30
+			caption Hierarchy Nodes
+		}	
+		element TextArea(Example/Visibility/HierarchyNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 50
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/RenderedNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 65
+			width 180
+			height 30
+			caption Rendered Nodes
+		}	
+		element TextArea(Example/Visibility/RenderedNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 65
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/Objects): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 80
+			width 180
+			height 30
+			caption Number of objects
+		}	
+		element TextArea(Example/Visibility/ObjectsInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 80
+			width 90
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/QueriesIssued): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 95
+			width 180
+			height 30
+			caption Queries issued
+		}	
+		element TextArea(Example/Visibility/QueriesIssuedInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 95
+			width 90
 			font_name TrebuchetMSBold
-			char_height 16
-			caption Frustum Culled Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/FrustumCulledNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 5
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/QueryCulledNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 20
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Query Culled Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/QueryCulledNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 20
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/TraversedNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 35
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Traversed Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/TraversedNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 35
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/HierarchyNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 50
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Hierarchy Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/HierarchyNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 50
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/RenderedNodes)
-		{
-			metrics_mode pixels
-			left 5
-			top 65
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Rendered Nodes
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/RenderedNodesInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 65
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/Objects)
-		{
-			metrics_mode pixels
-			left 5
-			top 80
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Number of objects
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/ObjectsInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 80
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}
-		element TextArea(Example/Visibility/QueriesIssued)
-		{
-			metrics_mode pixels
-			left 5
-			top 95
-			width 180
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption Queries issued
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
-		}	
-		element TextArea(Example/Visibility/QueriesIssuedInfo)
-		{
-			metrics_mode pixels
-			left 180
-			top 95
-			width 90
-			height 30
-			font_name TrebuchetMSBold
-			char_height 16
-			caption :
-			colour_top 0.5 0.7 0.5
-			colour_bottom 0.3 0.5 0.3
+			caption :			
 		}			
 	}
 }
+
+Example/Visibility/HelpOverlay
+{
+	zorder 600
+	// Stats block
+	container BorderPanel(Example/Visibility/HelpPanel)
+	{
+		metrics_mode pixels
+		horz_align left
+		vert_align top
+		width 600
+		height 315
+		left 200
+		top 200
+		material Core/StatsBlockCenter
+		//material Example/Visibility/Helpscreen
+        	border_size 1 1 1 1
+        	border_material Core/StatsBlockBorder
+        	border_topleft_uv     0.0000 1.0000 0.0039 0.9961
+	    	border_top_uv         0.0039 1.0000 0.9961 0.9961
+	    	border_topright_uv    0.9961 1.0000 1.0000 0.9961
+	    	border_left_uv        0.0000 0.9961 0.0039 0.0039
+	    	border_right_uv       0.9961 0.9961 1.0000 0.0039
+	    	border_bottomleft_uv  0.0000 0.0039 0.0039 0.0000
+        	border_bottom_uv      0.0039 0.0039 0.9961 0.0000
+	    	border_bottomright_uv 0.9961 0.0039 1.0000 0.0000
+
+		container Panel(Example/Visibility/Help/BreakPanel)
+		{
+			metrics_mode pixels
+			left 5 
+			top 22
+			width 590
+			height 1
+			material Core/StatsBreak
+		}
+
+		element TextArea(Example/Visibility/Help/Help)
+		{
+			metrics_mode pixels
+			left 5
+			top 5
+			width 90
+			height 30
+			font_name TrebuchetMSBold
+			char_height 19
+			caption Additional Options
+			colour_top 1 1 0.7
+			colour_bottom 1 1 0.7
+		}
+
+		element TextArea(Example/Visibility/Help/ShowHelpInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 40
+			width 180
+			height 30
+			caption [F1] Show / Hide this screen
+		}
+		element TextArea(Example/Visibility/Help/StatsInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 55
+			width 180
+			height 30
+			caption [F2] Show / Hide stats
+		}
+		element TextArea(Example/Visibility/Help/RecordedInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 70
+			width 180
+			height 30
+			caption [F3] Start / End frame recording
+		}
+		element TextArea(Example/Visibility/Help/AppStateInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 85
+			width 180
+			height 30
+			caption [F4] Toggle between interactive / recorded walkthrough
+		}
+		element TextArea(Example/Visibility/Help/ScreenshotsInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 115
+			width 180
+			height 30
+			caption [F11] Screenshot
+		}
+		element TextArea(Example/Visibility/Help/WriteOutInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 130
+			width 180
+			height 30
+			caption [F12] Write screen objects to file
+		}
+		//-- visualization
+		element TextArea(Example/Visibility/Help/VizInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 160
+			width 180
+			height 30
+			caption [1] Show / hide visualization
+		}
+		element TextArea(Example/Visibility/Help/NextVizModeInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 175
+			width 175
+			height 30
+			caption [2] Toggle visualization mode
+		}
+		element TextArea(Example/Visibility/Help/ZoomVizInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 190
+			width 190
+			height 30
+			caption [3][4] Zoom in / out of visualization
+		}
+		element TextArea(Example/Visibility/Help/SceneDetailInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 220
+			width 180
+			height 30
+			caption [R] Toggle between solid / wireframe / point based rendering
+		}
+		element TextArea(Example/Visibility/Help/DisplayCameraDetailsInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 235
+			width 180
+			height 30
+			caption [P] Show / hide camera details 
+		}
+		element TextArea(Example/Visibility/Help/DisplayOctreeInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 250
+			width 180
+			height 30
+			caption [T] Show / hide octree 
+		}
+		element TextArea(Example/Visibility/Help/UseShadowsInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 265
+			width 180
+			height 30
+			caption [S] Show / hide shadows
+		}
+		element TextArea(Example/Visibility/Help/FilterInfo): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 280
+			width 180
+			height 30
+			caption [F] toggle filtering method (trilinear, anisotropic, bilinear)
+		}
+	}
+}
