Index: trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 164)
+++ trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 202)
@@ -89,4 +89,6 @@
 	void endFrame();
 
+	void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
+	void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup);
 
 protected:
@@ -146,5 +148,4 @@
 	/// flag for passes which should not be deleted from queue during first traversal
 	int mLeavePassesInQueue;
-	ShadowTechnique mSavedShadowTechnique;
 
 	/// if transparent object are considered for item buffer visibility
@@ -152,4 +153,6 @@
 	/// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
 	bool mExecuteVertexProgramForAllPasses;
+
+	bool mIsHierarchicalCulling;
 };
 
Index: trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 187)
+++ trunk/VUT/Ogre/include/OgreVisibilityOctreeSceneManager.h	(revision 202)
@@ -142,5 +142,5 @@
 	/// flag for passes which should not be deleted from queue during first traversal
 	int mLeavePassesInQueue;
-	ShadowTechnique mSavedShadowTechnique;
+	
 
 	/// if transparent object are considered for item buffer visibility
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 192)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 202)
@@ -31,7 +31,7 @@
 mEnableDepthWrite(true),
 mSkipTransparents(false),
-mSavedShadowTechnique(SHADOWTYPE_NONE),
 mRenderTransparentsForItemBuffer(true),
-mExecuteVertexProgramForAllPasses(true)
+mExecuteVertexProgramForAllPasses(true),
+mIsHierarchicalCulling(false)
 {
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
@@ -319,5 +319,4 @@
 		mSkipTransparents = false;
 		mLeavePassesInQueue = 0;
-		mShadowTechnique = mSavedShadowTechnique;
 		
 
@@ -640,14 +639,4 @@
 	mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
 
-	// save shadow technique. It will be reset after hierarchical culling
-	mSavedShadowTechnique = mShadowTechnique;
-
-	// render standard solids without shadows during hierarchical culling pass
-	if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) ||
-	    (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE))
-	{	
-		mShadowTechnique = SHADOWTYPE_NONE;
-	}
-
 	// set depth pass flag before rendering
 	mRenderDepthPass = mUseDepthPass;
@@ -666,11 +655,10 @@
 	mLeavePassesInQueue = 0;
 
-	if (!mUseDepthPass || !mUseItemBuffer)
-	{
-		if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
+	if (!mUseDepthPass && !mUseItemBuffer)
+	{
+		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
 		{
 			// TODO: remove this pass because it should be processed during hierarchical culling
-			//mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES;
-			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
+			//mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
 
 			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_DECAL;
@@ -682,5 +670,5 @@
 		}
 	
-		if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
+		if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
 		{
 			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
@@ -722,32 +710,4 @@
 }
 //-----------------------------------------------------------------------
-/*void VisibilityTerrainSceneManager::renderBasicQueueGroupObjects(RenderQueueGroup* pGroup)
-{
-    // Basic render loop: Iterate through priorities
-    RenderQueueGroup::PriorityMapIterator groupIt = pGroup->getIterator();
-
-    while (groupIt.hasMoreElements())
-    {
-        RenderPriorityGroup* pPriorityGrp = groupIt.getNext();
-
-        // Sort the queue first
-        pPriorityGrp->sort(mCameraInProgress);
-
-		// Do solids
-		// TODO: render other solid passes for shadows
-        renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
-
-		// do solid passes no shadows if addititive stencil shadows
-		if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
-			renderObjects(pPriorityGrp->_getSolidPassesNoShadows(), true);
-		
-        // Do transparents
-        renderObjects(pPriorityGrp->_getTransparentPasses(), true);
-
-
-    }// for each priority
-}
-*/
-//-----------------------------------------------------------------------
 Entity* VisibilityTerrainSceneManager::createEntity(const String& entityName, 
 													const String& meshName)
@@ -765,3 +725,59 @@
 	return ent;
 }
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
+{
+	// only render solid passes during hierarchical culling
+	if (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
+			mIlluminationStage = IRS_AMBIENT;
+
+			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPasses(), false, &lightList);
+			// Also render any objects which have receive shadows disabled
+			OctreeSceneManager::renderObjects(pPriorityGrp->_getSolidPassesNoShadow(), true);
+		}
+	}
+	else
+	{
+		OctreeSceneManager::renderAdditiveStencilShadowedQueueGroupObjects(pGroup);
+	}
+}
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup)
+{
+   if (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->_getSolidPasses(), true);
+	   }
+   }
+   else
+   {
+	   SceneManager::renderModulativeStencilShadowedQueueGroupObjects(pGroup);
+   }
+}
 } // namespace Ogre
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 192)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 202)
@@ -32,5 +32,4 @@
 mEnableDepthWrite(true),
 mSkipTransparents(false),
-mSavedShadowTechnique(SHADOWTYPE_NONE),
 mRenderTransparentsForItemBuffer(true),
 mExecuteVertexProgramForAllPasses(true),
@@ -318,6 +317,4 @@
 
 		mLeavePassesInQueue = 0;
-		mShadowTechnique = mSavedShadowTechnique;
-
 
 		// add visible nodes found by the visibility culling algorithm
@@ -639,14 +636,4 @@
 	mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
 
-	// save shadow technique. It will be reset after hierarchical culling
-	mSavedShadowTechnique = mShadowTechnique;
-
-	// render standard solids without shadows during hierarchical culling pass
-	/*if ((mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE) ||
-	    (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE))
-	{	
-		mShadowTechnique = SHADOWTYPE_NONE;
-	}*/
-
 	// set depth pass flag before rendering
 	mRenderDepthPass = mUseDepthPass;
@@ -670,5 +657,5 @@
 	if (!mUseDepthPass && !mUseItemBuffer)
 	{
-		if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
+		if (mShadowTechnique == SHADOWTYPE_STENCIL_ADDITIVE)
 		{
 			// TODO: remove this pass because it should be processed during hierarchical culling
@@ -684,5 +671,5 @@
 		}
 	
-		if (mSavedShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
+		if (mShadowTechnique == SHADOWTYPE_STENCIL_MODULATIVE)
 		{
 			mLeavePassesInQueue |= RenderPriorityGroup::SOLID_PASSES_NOSHADOW;
