Index: trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 115)
+++ trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 119)
@@ -8,5 +8,4 @@
 {
 	//InitFrame();
-	//Ogre::LogManager::getSingleton().logMessage("chc culling");
 	QueryQueue queryQueue;
 	unsigned int visiblePixels = 0;
Index: trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 118)
+++ trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 119)
@@ -64,5 +64,5 @@
 protected:
 	/** Creates material for depth pass, e.g., a pass that only fills the depth buffer */
-	void CreateDepthPass();
+	void InitDepthPass();
 	void ShowVisualization(Camera *cam);
 	OctreeHierarchyInterface *mHierarchyInterface;
Index: trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 118)
+++ trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 119)
@@ -64,5 +64,5 @@
 protected:
 	/** Creates material for depth pass, e.g., a pass that only fills the depth buffer */
-	void CreateDepthPass();
+	void InitDepthPass();
 	void ShowVisualization(Camera *cam);
 	OctreeHierarchyInterface *mHierarchyInterface;
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 118)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 119)
@@ -32,9 +32,7 @@
 	// TODO: set maxdepth to reasonable value
 	mMaxDepth = 50;
-	// create material for depth pass
-	CreateDepthPass();
-}
-//-----------------------------------------------------------------------
-void VisibilityTerrainSceneManager::CreateDepthPass()
+}
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::InitDepthPass()
 {
 	MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
@@ -64,12 +62,13 @@
 Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
 {
-	// setting vertex program is not efficient
-	//Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);		
-	Pass *usedPass = (mIsDepthPass ? mDepthPass : pass);	
+	// 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())
+        if (pass->hasVertexProgram() && (pass->getVertexProgramName() != mDepthPass->getVertexProgramName()))
 		{
 			mDepthPass->setVertexProgram(pass->getVertexProgramName());
@@ -79,6 +78,5 @@
 				const GpuProgramPtr& prg = mDepthPass->getVertexProgram();
 				// Load this program if not done already
-				if (!prg->isLoaded())
-					prg->load();
+				if (!prg->isLoaded()) prg->load();
 				// Copy params
 				mDepthPass->setVertexProgramParameters(pass->getVertexProgramParameters());
@@ -163,4 +161,7 @@
 void VisibilityTerrainSceneManager::_renderVisibleObjects()
 {
+	// create material for depth pass
+	InitDepthPass();
+
 	// visualization: apply standard rendering
 	if (mShowVisualization)
@@ -225,8 +226,8 @@
 	if (mUseDepthPass)
 	{
-		for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
+		/*for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
 		{
 			(*it)->_addToRenderQueue(mCameraInProgress, getRenderQueue(), false);
-		}
+		}*/
 		mIsDepthPass = false;
 	}
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 118)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 119)
@@ -34,9 +34,7 @@
 	// TODO: find reasonable value for max depth
 	mMaxDepth = 50;
-
-	CreateDepthPass();
-}
-//-----------------------------------------------------------------------
-void VisibilityOctreeSceneManager::CreateDepthPass()
+}
+//-----------------------------------------------------------------------
+void VisibilityOctreeSceneManager::InitDepthPass()
 {
 	MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
@@ -69,5 +67,6 @@
 	// setting vertex program is not efficient
 	//Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);		
-	Pass *usedPass = (mIsDepthPass ? mDepthPass : pass);	
+	// set depth fill pass only if depth write enabled
+	Pass *usedPass = (mIsDepthPass && pass->getDepthWriteEnabled() ? mDepthPass : pass);
 
 	if (mIsDepthPass)
@@ -166,4 +165,7 @@
 void VisibilityOctreeSceneManager::_renderVisibleObjects()
 {
+	// create material for depth pass
+	InitDepthPass();
+
 	// visualization: apply standard rendering
 	if (mShowVisualization)
