Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj	(revision 2228)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj	(revision 2254)
@@ -96,6 +96,5 @@
 				Name="VCMIDLTool"/>
 			<Tool
-				Name="VCPostBuildEventTool"
-				CommandLine="copy $(OutDir)\$(TargetFileName) &quot;$(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)&quot;"/>
+				Name="VCPostBuildEventTool"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg	(revision 2177)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg	(revision 2254)
@@ -9,8 +9,16 @@
 
 #
-# Should depth first pass be used?
+# Should depth first pass be used? depth pass renders depth first, then rerenders geometry with all parameters
 #
 
-DepthPass=1
+DepthPass=0
+
+#
+# render queue is flushed after some frames
+#
+
+FlushQueue=1
+
+
 
 ######################################################################
@@ -29,22 +37,11 @@
 #Scene=../../../../../resources/media/city1.iv;../../../../../resources/media/roofs_1500.iv;../../../../../resources/media/CityRoads60.iv;../../../../../resources/media/CityPlane60.iv
 
+#Scene=vienna_cropped.obj
+
 #
-# The view cells
+# Visibility solution
 #
 
 #ViewCells=../../../../../../../GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna-visibility.xml.gz
-
-
-#
-# render queue is flushed after some frames
-#
-
-FlushQueue=1
-
-#
-# depth pass must be used together with illumination model
-#
-
-UseDepthPass=0
 
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2184)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2254)
@@ -187,5 +187,5 @@
 	void loadConfig(DataStreamPtr& stream);
 
-	void RenderDepthPass(const bool fillRenderQueue = true);
+	void RenderHierarchicalCulling(const bool fillRenderQueue = true);
 
 	void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays);
@@ -196,6 +196,8 @@
 								const bool nodeVisibility);	
 
-	void AddVisibleMeshGeometryToQueue(const GtpVisibility::MeshInfoContainer &visibleGeometry, Camera *cam);
-	void AddVisibleNodeGeometryToQueue(const GtpVisibility::NodeInfoContainer &visibleNodes, Camera *cam);
+	void AddVisibleMeshGeometryToQueue(const GtpVisibility::MeshInfoContainer &visibleGeometry, 
+									   Camera *cam);
+	void AddVisibleNodeGeometryToQueue(const GtpVisibility::NodeInfoContainer &visibleNodes, 
+									   Camera *cam);
 
 	//////////////////////////////////////////
@@ -299,5 +301,11 @@
 	ObjReader *mObjReader;
 
-	Camera *mDummyCamera;
+	bool mUseVisibilityQueries;
+
+	bool mUseFromPointQueries;
+
+	bool mUseExactQueries;
+	
+	bool mUseDepthPassForQueries;
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2253)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2254)
@@ -53,5 +53,5 @@
 				Name="VCPostBuildEventTool"
 				CommandLine="copy $(OutDir)\$(TargetFileName) $(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)
-copy $(OutDir)\$(TargetFileName) D:\svn\gametools\GTP\trunk\App\Demos\Illum\Ogre\bin\$(ConfigurationName)
+copy $(OutDir)\$(TargetFileName) E:\svn\gametools\GTP\trunk\App\Demos\Illum\Ogre\bin\$(ConfigurationName)
 "/>
 			<Tool
@@ -89,5 +89,5 @@
 				OmitFramePointers="TRUE"
 				EnableFiberSafeOptimizations="TRUE"
-				OptimizeForProcessor="3"
+				OptimizeForProcessor="0"
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include;..\..\..\Preprocessing\src\Timer;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\include"
@@ -124,5 +124,7 @@
 			<Tool
 				Name="VCPostBuildEventTool"
-				CommandLine="copy $(OutDir)\$(TargetFileName) $(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)"/>
+				CommandLine="copy $(OutDir)\$(TargetFileName) $(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)
+copy $(OutDir)\$(TargetFileName) E:\svn\gametools\GTP\trunk\App\Demos\Illum\Ogre\bin\$(ConfigurationName)
+"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
@@ -299,5 +301,5 @@
 				OptimizeForProcessor="3"
 				OptimizeForWindowsApplication="TRUE"
-				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\include;Timer"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\include"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE;PLUGIN_KD_TERRAIN_EXPORTS"
 				StringPooling="TRUE"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2253)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2254)
@@ -59,5 +59,5 @@
 mElementaryViewCell(NULL),
 mDeleteQueueAfterRendering(true),
-mNormalExecution(true),
+mNormalExecution(false),
 mShowViewCells(false),
 mViewCellsGeometryLoaded(false),
@@ -66,5 +66,9 @@
 mFilename("terrain"),
 mFlushRate(10),
-mCurrentFrame(0)
+mCurrentFrame(0),
+mUseVisibilityQueries(false),
+mUseFromPointQueries(false),
+mUseExactQueries(false),
+mUseDepthPassForQueries(false)
 {
 	Ogre::LogManager::getSingleton().
@@ -80,5 +84,5 @@
 	}
 
-	// TODO: set maxdepth to reasonable value
+	// set maxdepth to reasonable value
 	mMaxDepth = 50;
 
@@ -110,6 +114,7 @@
 OcclusionCullingSceneManager::~OcclusionCullingSceneManager()
 {
+	CLEAR_CONTAINER(mObjects);
+
 	OGRE_DELETE(mHierarchyInterface);
-	CLEAR_CONTAINER(mObjects);
 	OGRE_DELETE(mCurrentViewCell);
 
@@ -195,36 +200,80 @@
 	ConfigFile config;
 	String val;
-
-	LogManager::getSingleton().
-		logMessage("****** OcclusionCullingSceneManager Options ********");
+	
 	config.load(stream);
-
-	std::stringstream d; 
-		
+	
+	LogManager::getSingleton().logMessage("****** OcclusionCullingSceneManager Options ********");
+
 	val = config.getSetting("DepthPass");
 
     if (!val.empty())
 	{
-		mUseDepthPass = atoi(val.c_str());
-	}
-
-	if (mUseDepthPass)
-		LogManager::getSingleton().logMessage("using depth");
-	else
-		LogManager::getSingleton().logMessage("not using depth");
-	
+		if ( val == "yes" )
+			mUseDepthPass = true;
+		else
+			mUseDepthPass = false;
+	}
+
+	val = config.getSetting("ExecuteVertexProgramForDepth");
+
+	if (!val.empty())
+	{
+		if ( val == "yes" )
+			mExecuteVertexProgramForAllPasses = true;
+		else
+			mExecuteVertexProgramForAllPasses = false;
+	}
+
+	val = config.getSetting("UseVisibilityQueries");
+
+	if (!val.empty())
+	{
+		if ( val == "yes" )
+			mUseVisibilityQueries = true;
+		else
+			mUseVisibilityQueries = false;
+	}
+
+	val = config.getSetting("UseFromPointQueries");
+	
+	if (!val.empty())
+	{
+		if (val == "yes")
+			mUseFromPointQueries = true;
+		else 
+			mUseFromPointQueries = false;
+	}
+
+	val = config.getSetting("UseExactQueries");
+
+	if (!val.empty())
+	{
+		if (val == "yes")
+			mUseExactQueries = true;
+		else
+			mUseExactQueries = false;
+	}
+
+	val = config.getSetting("UseDepthPassForQueries");
+
+	if (!val.empty())
+	{
+		if (val == "yes")
+			mUseDepthPassForQueries = true;
+		else
+			mUseDepthPassForQueries = false;
+	}
+
 	val = config.getSetting("FlushQueue");
 	
 	if (!val.empty())
 	{
-		mDeleteQueueAfterRendering = atoi(val.c_str());
-	}
-
-	if (mDeleteQueueAfterRendering)
-		LogManager::getSingleton().logMessage("flushing queue");
-	else
-		LogManager::getSingleton().logMessage("not flushing queue");
-	
-   	val = config.getSetting("Scene");
+		if ( val == "yes" )
+			mDeleteQueueAfterRendering = true;
+		else
+			mDeleteQueueAfterRendering = false;
+	}
+
+	val = config.getSetting("Scene");
 
     if (!val.empty())
@@ -286,4 +335,5 @@
 		 mVisibilityManager->SetCullingManager(algorithm);
 
+		 stringstream d;
 		 d << "setting algorithm to: " << algorithm;
 		 LogManager::getSingleton().logMessage(d.str());
@@ -399,5 +449,40 @@
 	selectPageSource(pageSourceName, optlist);
 
-	LogManager::getSingleton().logMessage("****** Finished OcclusionCullingSceneManager Options ********");
+	if (mUseDepthPass)
+		LogManager::getSingleton().logMessage("using depth");
+	else
+		LogManager::getSingleton().logMessage("not using depth");
+	
+	if (mExecuteVertexProgramForAllPasses)
+		LogManager::getSingleton().logMessage("executing vertex program for passes");
+	else
+		LogManager::getSingleton().logMessage("not executing vertex program for passes");
+
+	if (mUseVisibilityQueries)
+		LogManager::getSingleton().logMessage("using visibility queries");
+	else
+		LogManager::getSingleton().logMessage("not using visibility queries");
+
+	if (mUseFromPointQueries)
+		LogManager::getSingleton().logMessage("using from point queries");
+	else
+		LogManager::getSingleton().logMessage("not using from point queries");
+
+	if (mUseExactQueries)
+		LogManager::getSingleton().logMessage("using exact queries");
+	else
+		LogManager::getSingleton().logMessage("not using exact queries");
+
+	if (mUseDepthPassForQueries)
+		LogManager::getSingleton().logMessage("using depth pass for queries");
+	else
+		LogManager::getSingleton().logMessage("not using depth pass for queries");
+
+	if (mDeleteQueueAfterRendering)
+		LogManager::getSingleton().logMessage("flushing queue after rendering");
+	else
+		LogManager::getSingleton().logMessage("not flushing queue after rendering");
+
+	LogManager::getSingleton().logMessage("****** OcclusionCullingSceneManager Options Finished ********");
 }
 //-----------------------------------------------------------------------
@@ -588,6 +673,5 @@
 
 				// add bounding boxes instead of node itself
-				if (0)
-					(*it)->_addBoundingBoxToQueue(getRenderQueue());
+				if (0) (*it)->_addBoundingBoxToQueue(getRenderQueue());
 			}
 
@@ -606,8 +690,8 @@
 	if (mNormalExecution)
 	{
-		return TerrainSceneManager::_setPass(pass);
-	}
-
-	// TODO: setting vertex program is not efficient
+		return TerrainSceneManager::_setPass(pass, evenIfSuppressed);
+	}
+
+	// problem: setting vertex program is not efficient
 	//Pass *usedPass = ((mIsDepthPassPhase && !pass->hasVertexProgram()) ? mDepthPass : pass); 
 	
@@ -627,5 +711,6 @@
 		}
 	
-		//--- set vertex program of current pass in order to set correct depth
+		//////////////////
+		//-- set vertex program of current pass in order to set correct depth
 		if (mExecuteVertexProgramForAllPasses && 
 			mIsDepthPassPhase && 
@@ -651,26 +736,27 @@
 	}
 
+	// using depth pass instead
 	const Pass *usedPass = useDepthPass ? mDepthPass : pass;
 
+#if 0 // tmp matt: pass is now const
 	// save old depth write: needed for item buffer
-	const bool IsDepthWrite = usedPass->getDepthWriteEnabled();
+	const bool isDepthWrite = usedPass->getDepthWriteEnabled();
 
 	// global option which enables / disables depth writes
 	if (!mEnableDepthWrite)
-	{
-		//usedPass->setDepthWriteEnabled(false);
-	}
-	//else if (mIsItemBufferPass) {usedPass = mItemBufferPass;}
-
+		usedPass->setDepthWriteEnabled(false);
+#endif
+
+	///////////////
 	//-- set actual pass here
-	const Pass *result = SceneManager::_setPass(usedPass);
+
+	const Pass *result = SceneManager::_setPass(usedPass, evenIfSuppressed);
 
 
 	// reset depth write
+#if 0 // tmp matt: this is now a const function
 	if (!mEnableDepthWrite)
-	{
-		//usedPass->setDepthWriteEnabled(IsDepthWrite);
-	}
-
+		usedPass->setDepthWriteEnabled(isDepthWrite);
+#endif
 	// reset illumination stage
 	mIlluminationStage = savedStage;
@@ -682,4 +768,12 @@
 														bool onlyShadowCasters)
 {
+	// clear render queue
+	// fully reset it after some frames
+	const bool flushQueue = 
+		mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
+	getRenderQueue()->clear(flushQueue);
+
+	++ mCurrentFrame;
+
 	if (mShowVisualization)
     {
@@ -689,5 +783,5 @@
 		PrepareVisualization(cam);
 		
-		// lists only used for visualization
+			// lists only used for visualization
 		mVisible.clear();
 		mBoxes.clear();
@@ -696,5 +790,5 @@
 	}
 	
-	// lists only used for visualization
+
 	mVisible.clear();
 	mBoxes.clear();
@@ -719,5 +813,6 @@
 	else if (mUseDepthPass)
 	{
-		RenderDepthPass();
+		// render scene once in order to fill depth buffer
+		RenderHierarchicalCulling();
 	}
 	
@@ -736,7 +831,6 @@
 	}
 
-	const bool flushQueue = 
-		mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
-	++ mCurrentFrame;
+	//const bool flushQueue = mDeleteQueueAfterRendering && ((mCurrentFrame % mFlushRate) == 0);
+	//++ mCurrentFrame;
 
 	// create material for item buffer pass
@@ -750,5 +844,7 @@
 	//-- (e.g., the visualization mode, the shadow pass)
 
-	if (//!mFindVisibleObjects || 
+	// also go here if find visible object is disabled 
+	// (then the render queue is already filled)
+	if (!mFindVisibleObjects || 
 		mUseDepthPass || mShowVisualization ||
 	    (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
@@ -758,9 +854,7 @@
 	
 		if (mShowVisualization) 
-		{
 			// disable illumination stage to prevent rendering shadows
 			mIlluminationStage = IRS_NONE;
-		}
-
+		
 		// standard rendering for shadow maps because of performance
 		TerrainSceneManager::_renderVisibleObjects();
@@ -811,5 +905,5 @@
 		// set all necessary parameters for 
 		// hierarchical visibility culling and rendering
-		InitVisibilityCulling(mDummyCamera);
+		InitVisibilityCulling(mCameraInProgress);
 
 
@@ -854,6 +948,8 @@
 	setAmbientLight(savedAmbient);
 
-	// almost same effect as below
+	// remove rest from queue
+#if 0
 	getRenderQueue()->clear(flushQueue);
+#endif
 	
 	if (0) WriteLog(); // write out stats
@@ -1018,7 +1114,30 @@
 		return true;
 	}
-	if (key == "ViewCellsLoaded")
+	if (key == "UseVisibilityQueries")
+	{
+		mUseVisibilityQueries = *static_cast<const bool *>(val);
+
+		return true;
+	}
+	if (key == "UseFromPointQueries")
+	{
+		mUseFromPointQueries = *static_cast<const bool *>(val);
+
+		return true;
+	}
+	if (key == "UseExactQueries")
+	{
+		mUseExactQueries = *static_cast<const bool *>(val);
+
+		return true;
+	}
+	if (key == "UseDepthPassForQueries")
+	{
+		mUseDepthPassForQueries = *static_cast<const bool *>(val);
+	}
+	if (key == "UseFromPointQueries")
 	{ 
-		return mViewCellsLoaded;
+		mUseFromPointQueries = *static_cast<const bool *>(val);
+		return true;
 	}
 
@@ -1142,4 +1261,5 @@
 		return TerrainSceneManager::renderBasicQueueGroupObjects(pGroup, om);
 	}
+
     // Basic render loop
     // Iterate through priorities
@@ -1159,5 +1279,5 @@
 		// after hierarchical culling => don't render them now
 
-        if (mNormalExecution || !mSkipTransparents)
+        if (!mSkipTransparents)
 		{
 			// Do transparents (always descending)
@@ -1167,5 +1287,4 @@
     } // for each priority
 }
-
 //-----------------------------------------------------------------------
 bool OcclusionCullingSceneManager::validatePassForRendering(Pass* pass)
@@ -1177,5 +1296,6 @@
 
 	// skip all but first pass if we are doing the depth pass
-	if ((mIsDepthPassPhase || mIsItemBufferPhase) && (pass->getIndex() > 0))
+	if ((mIsDepthPassPhase || mIsItemBufferPhase) && 
+		(pass->getIndex() > 0))
 	{
 		return false;
@@ -1198,7 +1318,9 @@
 		return;
 	}
+
 #ifdef  ITEM_BUFFER
-	//-- item buffer
-	//-- render objects using false colors
+
+	///////////////////
+	//-- item buffer: render objects using false colors
 
     // Iterate through priorities
@@ -1350,5 +1472,5 @@
 
 	// if we have the depth pass or use an item buffer, we leave no passes in the queue
-	if (1 && !mUseDepthPass && !mUseItemBuffer)
+	if (!mUseDepthPass && !mUseItemBuffer)
 	{
 		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
@@ -1425,40 +1547,40 @@
 	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
+	if (mNormalExecution || !mIsHierarchicalCulling) 
+	{
+		// render the rest of the passes
+		TerrainSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
+		return;
+	}
+	
 	// only render solid passes during hierarchical culling
-	if (mNormalExecution || mIsHierarchicalCulling)
-	{
-		RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-	    LightList lightList;
-
-		while (groupIt.hasMoreElements())
-		{
-			RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-			// Sort the queue first
-			pPriorityGrp->sort(mCameraInProgress);
-
-			// Clear light list
-			lightList.clear();
-
-			// Render all the ambient passes first, no light iteration, no lights
-			/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
-			// mIlluminationStage = IRS_AMBIENT;
-
-			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
-			// Also render any objects which have receive shadows disabled
-			OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
+	RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
+	LightList lightList;
+
+	while (groupIt.hasMoreElements())
+	{
+		RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
+
+		// Sort the queue first
+		pPriorityGrp->sort(mCameraInProgress);
+
+		// Clear light list
+		lightList.clear();
+
+		// Render all the ambient passes first, no light iteration, no lights
+		/*** msz: no more IRS_AMBIENT, see OgreSceneManager.h ***/
+		// mIlluminationStage = IRS_AMBIENT;
+
+		OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, false, &lightList);
+		// Also render any objects which have receive shadows disabled
+		OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsNoShadowReceive(), om, true);
 #if 0		
-			std::stringstream d; 
-			d << " solid size: " << (int)pPriorityGrp->_getSolidPasses().size()
-				<< " solid no shadow size: " << (int)pPriorityGrp->_getSolidPassesNoShadow().size()
-				<< "difspec size: " << (int)pPriorityGrp->_getSolidPassesDiffuseSpecular().size()
-				<< " decal size: " << (int)pPriorityGrp->_getSolidPassesDecal().size();
-			LogManager::getSingleton().logMessage(d.str());
+		std::stringstream d; 
+		d << " solid size: " << (int)pPriorityGrp->_getSolidPasses().size()
+			<< " solid no shadow size: " << (int)pPriorityGrp->_getSolidPassesNoShadow().size()
+			<< "difspec size: " << (int)pPriorityGrp->_getSolidPassesDiffuseSpecular().size()
+			<< " decal size: " << (int)pPriorityGrp->_getSolidPassesDecal().size();
+		LogManager::getSingleton().logMessage(d.str());
 #endif
-		}
-	}
-	else // render the rest of the passes
-	{
-		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup, om);
 	}
 }
@@ -1467,22 +1589,21 @@
 	RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om)
 {
-   if (mNormalExecution || mIsHierarchicalCulling)
-   {
-	   // Iterate through priorities
-	   RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-
-	   while (groupIt.hasMoreElements())
-	   {
-		   RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-		   // Sort the queue first
-		   pPriorityGrp->sort(mCameraInProgress);
-		   // Do (shadowable) solids
-		   OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
-	   }
-   }
-   else
+   if (mNormalExecution || !mIsHierarchicalCulling)
    {
 	   TerrainSceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup, om);
+	   return;
+   }
+
+   // Iterate through priorities
+   RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
+
+   while (groupIt.hasMoreElements())
+   {
+	   RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
+
+	   // Sort the queue first
+	   pPriorityGrp->sort(mCameraInProgress);
+	   // Do (shadowable) solids
+	   OctreeSceneManager::renderObjects(pPriorityGrp->getSolidsBasic(), om, true);
    }
 }
@@ -1827,12 +1948,6 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::RenderDepthPass(const bool fillRenderQueue)
-{
-	if (mNormalExecution)
-	{
-		// problems using this function in the normal workflow
-		return;
-	}
-
+void OcclusionCullingSceneManager::RenderHierarchicalCulling(const bool fillRenderQueue)
+{
 	// create material for depth pass
 	InitDepthPass();
@@ -1907,5 +2022,5 @@
 												bool includeOverlays)
 {
-	if (0 && mNormalExecution)
+	if (mNormalExecution)
 	{
 		TerrainSceneManager::_renderScene(camera, vp, includeOverlays);
@@ -2040,5 +2155,5 @@
 
 	// Prepare render queue for receiving new objects
-	prepareRenderQueue();
+	//prepareRenderQueue();
 
 	mDestRenderSystem->_beginGeometryCount();
@@ -2053,9 +2168,16 @@
 	mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true));
 
+	// Prepare render queue for receiving new objects
+#ifdef GAMETOOLS_ILLUMINATION_MODULE 
+	if (mFindVisibleObjects)
+		prepareRenderQueue();
+#else
+		prepareRenderQueue();
+#endif
 
     if (mFindVisibleObjects)
     {
         // Parse the scene and tag visibles
-        _findVisibleObjects(camera, 
+        myFindVisibleObjects(camera, 
             mIlluminationStage == IRS_RENDER_TO_TEXTURE? true : false);
     }
@@ -2071,5 +2193,4 @@
     }
 
- mDummyCamera = camera;
     // Render scene content 
     _renderVisibleObjects();
@@ -2271,14 +2392,12 @@
 	mDestRenderSystem->_setViewMatrix(mCameraInProgress->getViewMatrix(true));
 
-	// // Render scene content in order fill depth buffer
-	bool savedUseDepthPass = mUseDepthPass;
-	if (1) mUseDepthPass = true;
-
-	// don't need shading, render only depth pass
+	//////////////
+	//-- Render scene in order fill depth buffer
+
+	// don't have to fill queue, just render depth
 	const bool fillQueue = false;
-	RenderDepthPass(fillQueue);
+
+	RenderHierarchicalCulling(fillQueue);
 	// _renderVisibleObjects();
-    
-	mUseDepthPass = savedUseDepthPass;
    
     // End frame
@@ -2310,6 +2429,7 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::AddVisibleMeshGeometryToQueue(const GtpVisibility::MeshInfoContainer &visibleGeometry,
-																 Camera *cam)
+void OcclusionCullingSceneManager::AddVisibleMeshGeometryToQueue(
+						const GtpVisibility::MeshInfoContainer &visibleGeometry,
+						Camera *cam)
 {
 	GtpVisibility::MeshInfoContainer::const_iterator geomIt, geomIt_end = visibleGeometry.end();
@@ -2332,6 +2452,7 @@
 }
 //-----------------------------------------------------------------------
-void OcclusionCullingSceneManager::AddVisibleNodeGeometryToQueue(const GtpVisibility::NodeInfoContainer &visibleNodes,
-																 Camera *cam)
+void OcclusionCullingSceneManager::AddVisibleNodeGeometryToQueue(
+						const GtpVisibility::NodeInfoContainer &visibleNodes,
+						Camera *cam)
 {
 	////////////////
@@ -2359,5 +2480,5 @@
 													   bool onlyShadowCasters)										 
 {
-	if (mNormalExecution)
+	if (mNormalExecution || (!mUseVisibilityQueries == 0))
 	{
 		TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -2365,11 +2486,14 @@
 	}
 
+	// don't need shading, render only depth
+	// note:have to disable deph write for nodes!
+    bool savedUseDepthPass = mUseDepthPass;
+	if (mUseDepthPassForQueries) mUseDepthPass = true;
+
 	// lists only used for visualization
+	getRenderQueue()->clear();
 	mVisible.clear();
 	mBoxes.clear();
 
-	const bool fromPoint = false;
-	const bool nodeVisibility = false;
-
 	const int itemBufferMode = 0;
 	const bool relativeVisibility = false;
@@ -2377,12 +2501,14 @@
 	int queryModes = 0;
 
-	if (nodeVisibility)
+	if (mUseExactQueries)
+		queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
+	else
 		queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
-	else
-		queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
+			
 
 	OcclusionQueriesQueryManager *queryManager = 
 		new OcclusionQueriesQueryManager(mHierarchyInterface,
-		cam->getViewport(),//mCurrentViewport,
+										 cam->getViewport(),
+										 //mCurrentViewport,
 										 queryModes, 
 										 itemBufferMode);
@@ -2394,5 +2520,5 @@
 	GtpVisibility::PatchInfoContainer visiblePatches;
 
-	if (fromPoint)
+	if (mUseFromPointQueries)
 	{
 		queryManager->ComputeFromPointVisibility(cam->getDerivedPosition(), 
@@ -2423,13 +2549,10 @@
 	///////////////////////
 	//-- put items in render queue
-	//////////
-
-	//getRenderQueue()->clear();
-
-	//////////////////////
-	//-- apply queries on geometry level
-
-	if (!nodeVisibility)
-	{
+	
+	if (mUseExactQueries)
+	{
+		////////////
+		//-- apply queries on geometry level
+
 		AddVisibleMeshGeometryToQueue(visibleGeometry, cam);
 	}
@@ -2438,5 +2561,8 @@
 		AddVisibleNodeGeometryToQueue(visibleNodes, cam);
 	}
-		
+
+	// reset depth pass
+	mUseDepthPass = savedUseDepthPass;
+
 	delete queryManager;
 }
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 2184)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 2254)
@@ -229,5 +229,5 @@
 //-----------------------------------------------------------------------
 GtpVisibility::OcclusionQuery *PlatformHierarchyInterface::IssueMeshOcclusionQuery(
-	GtpVisibility::Mesh *mesh)
+														GtpVisibility::Mesh *mesh)
 {
 	// get next available test id
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2183)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2254)
@@ -94,5 +94,5 @@
 
 	
-	/*	Two query lists for projected pixels and for visibile pixels:
+	/**	Two query lists for projected pixels and for visibile pixels:
 		We test queries after a rendering pass 
 		to get exact visibility with regard to the current camera.
@@ -191,6 +191,8 @@
 		}
 
-		////////////////////////////
-		//-- queries for geometry: if item buffer, capture only projected visibility
+		///////////////
+		//-- queries for geometry
+		
+		// note: for item buffer we can capture only projected visibility
 
 		if ((mItemBufferMode != GEOMETRY_VISIBILITY) || (i == 1))
@@ -202,6 +204,6 @@
 		}
 		
-		////////////////////////
-		//-- queries for patches: if item buffer, capture only projected visibility
+		///////////////
+		//-- queries for patches
 
 		if ((mItemBufferMode != PATCH_VISIBILITY) || (i == 1))
@@ -421,5 +423,5 @@
 
 		// WARNING: approximate depth ordering during rendering => 
-		// geometry maybe occluded
+		// visibility approximate
 		if (visiblePixels > 0)
 		{			 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2199)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2254)
@@ -96,6 +96,5 @@
 				Name="VCMIDLTool"/>
 			<Tool
-				Name="VCPostBuildEventTool"
-				CommandLine="copy $(OutDir)\$(TargetFileName) &quot;$(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)&quot;"/>
+				Name="VCPostBuildEventTool"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
