Index: trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 112)
+++ trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 115)
@@ -42,5 +42,5 @@
 		mNumRenderedNodes ++;
 
-		mSceneManager->_renderSceneNode(mCamera, sceneNode);
+		mSceneManager->_renderSceneNode(mCamera, sceneNode, mLeaveTransparentsInQueue);
 	}
 #endif
Index: trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 114)
+++ trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 115)
@@ -9,5 +9,4 @@
 #include <OgreStringConverter.h>
 
-#include <windows.h>
 
 namespace Ogre {
@@ -15,12 +14,14 @@
 //-----------------------------------------------------------------------
 VisibilityTerrainSceneManager::VisibilityTerrainSceneManager(
-	GtpVisibility::VisibilityManager *visManager)
-: mVisibilityManager(visManager), 
-mUseVisibilityCulling(true),
+	GtpVisibility::VisibilityManager *visManager): 
+mVisibilityManager(visManager), 
+mUseDepthPass(false),
+mIsDepthPass(false),
 mShowVisualization(false),
 mRenderNodesForViz(false),
 mRenderNodesContentForViz(false),
 mVisualizeCulledNodes(false),
-mRenderTransparentObjects(false)
+mSkipTransparents(false),
+mDelayRenderTransparents(true)
 {
 	mHierarchyInterface = 
@@ -32,4 +33,27 @@
 	// TODO: set maxdepth to reasonable value
 	mMaxDepth = 50;
+	// create material for depth pass
+	CreateDepthPass();
+}
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::CreateDepthPass()
+{
+	MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
+
+	if (depthMat.isNull())
+    {
+		// Init
+		depthMat = MaterialManager::getSingleton().create(
+                "Visibility/DepthPass",
+                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+        mDepthPass = depthMat->getTechnique(0)->getPass(0);
+		mDepthPass->setColourWriteEnabled(false);
+		mDepthPass->setDepthWriteEnabled(true);
+		mDepthPass->setLightingEnabled(false);
+	}
+	else
+	{
+		mDepthPass = depthMat->getTechnique(0)->getPass(0);
+	}
 }
 //-----------------------------------------------------------------------
@@ -39,117 +63,171 @@
 }
 //-----------------------------------------------------------------------
+Pass *VisibilityTerrainSceneManager::setPass(Pass* pass)
+{
+	// setting vertex program is not efficient
+	//Pass *usedPass = ((mIsDepthPass && !pass->hasVertexProgram()) ? mDepthPass : pass);		
+	Pass *usedPass = (mIsDepthPass ? 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("");
+		}
+	}
+
+	TerrainSceneManager::setPass(usedPass);
+
+	return usedPass;
+}
+//-----------------------------------------------------------------------
+void VisibilityTerrainSceneManager::ShowVisualization(Camera *cam)
+{
+	// add player camera for visualization purpose
+	try {
+		Camera *c;
+		if ((c = getCamera("PlayerCam")) != NULL)
+		{
+			getRenderQueue()->addRenderable(c);
+		}   
+    }
+    catch(...)
+    {
+        // ignore
+    }
+	
+	if (mRenderNodesForViz || mRenderNodesContentForViz)
+	{
+		for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
+		{
+			if (mRenderNodesForViz)
+			{
+				//getRenderQueue()->addRenderable(*it);
+				// addbounding boxes instead of node itself
+				(*it)->_addBoundingBoxToQueue(getRenderQueue());
+			}
+			if (mRenderNodesContentForViz) 
+			{
+				(*it)->_addToRenderQueue(cam, getRenderQueue(), false);
+			}
+		}
+	}
+	for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
+	{
+		getRenderQueue()->addRenderable(*it);
+	}
+}
+//-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters)
 {
-	// only shadow casters will be rendered in shadow texture pass
-	mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
-
-	// does nothing if hierarchical culling is used =>
-	// we interleave identification and rendering of objects 
-	// in _renderVisibibleObjects
-	if (!mUseVisibilityCulling)
-	{
-		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
-		return;	
-	}
-
-	//-- show visibile scene nodes and octree bounding boxes from last frame
+	//-- show visible scene nodes and octree bounding boxes from last frame
 	if (mShowVisualization)
     {
-		// add player camera for visualization purpose
-		try {
-			Camera *c;
-			if ((c = getCamera("PlayerCam")) != NULL)
-			{
-				getRenderQueue()->addRenderable(c);
-			}   
-        }
-        catch(...)
-        {
-            // ignore
-        }
+		ShowVisualization(cam);
+	}
+	else 
+	{
+		mVisible.clear();
+	    mBoxes.clear();
 		
-		if (mRenderNodesForViz || mRenderNodesContentForViz)
-		{
-			// change node material so it is better suited for visualization
-			/*MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
-			nodeMat->setAmbient(1, 1, 0);
-			nodeMat->setLightingEnabled(true);
-			nodeMat->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();*/
-
-			for (NodeList::iterator it = mVisible.begin(); it != mVisible.end(); ++it)
-			{
-				if (mRenderNodesForViz)
-				{
-					getRenderQueue()->addRenderable(*it);
-				}
-				if (mRenderNodesContentForViz) 
-				{
-					(*it)->_addToRenderQueue(cam, getRenderQueue(), false);
-				}
-			}
-		}
-		for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it)
-		{
-			getRenderQueue()->addRenderable(*it);
-		}
-	}
-	
-	mVisible.clear();
-    mBoxes.clear();
+		// if there is no depth pass =>
+		// we interleave identification and rendering of objects 
+		// in _renderVisibibleObjects
+
+		// only shadow casters will be rendered in shadow texture pass
+		mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
+	}
 }
 //-----------------------------------------------------------------------
 void VisibilityTerrainSceneManager::_renderVisibleObjects()
 {
-	if (!mShowVisualization)
-	{
-		// two cameras (one for culling, one for rendering)
-		mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
-								mCullCamera ? getCamera("CullCamera") : NULL);
-
-		// call initframe to reset culling manager stats
-		mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
-	}
-	
-	// standard terrain scenemanager rendering without hierarchical culling
-	if (!mUseVisibilityCulling || mShowVisualization)
+	// visualization: apply standard rendering
+	if (mShowVisualization)
 	{	
 		TerrainSceneManager::_renderVisibleObjects();
-	
 		return;
-	} 
-	
+	}
+
+
 	//-- hierarchical culling
 	// the objects of different layers (e.g., background, scene, 
 	// overlay) must be identified and rendered one after another
 
-	//-- render background
+	bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass;
+
+	// possible two cameras (one for culling, one for rendering)
+	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
+							mCullCamera ? getCamera("CullCamera") : NULL,
+							leaveTransparentsInQueue);
+
+	// call initframe to reset culling manager stats
+	mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
+	
+	mSkipTransparents = false;
+
+	//-- render background, in case there is one
 	clearSpecialCaseRenderQueues();
 	addSpecialCaseRenderQueue(RENDER_QUEUE_BACKGROUND);
 	addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_EARLY);
-
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_INCLUDE);
+
 	SceneManager::_renderVisibleObjects();
 
+
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
+	_deleteRenderedQueueGroups(false);
 #endif
 
-	//-- render visible objects (i.e., all but overlay)
+	//-- render visible objects (i.e., all but overlay and skies late)
 	clearSpecialCaseRenderQueues();
+	addSpecialCaseRenderQueue(RENDER_QUEUE_SKIES_LATE);
 	addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
 
-
+	// transparents are skipped from hierarchical rendering
+	// => they need sorting, thus we render them afterwards
+	mSkipTransparents = mDelayRenderTransparents;
+
+	// set state for depth pass
+    mIsDepthPass = mUseDepthPass;
+	
 	/** 
-	* the hierarchical culling algorithm
+	  * the hierarchical culling algorithm
+	  * for depth pass: will just find objects and update depth buffer
+	  * for delayed rendering: will render all but transparents
 	**/
+	
 	mVisibilityManager->ApplyVisibilityCulling();
 
 
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
-#endif
-
-	//-- render overlay
+	// 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;
+
+	//-- now we can render all remaining queue objects
+	// for depth pass: all
+	// for delayed rendering: transparents, overlay 
 	clearSpecialCaseRenderQueues();
 	SceneManager::_renderVisibleObjects();
@@ -171,7 +249,7 @@
 bool VisibilityTerrainSceneManager::setOption(const String & key, const void * val)
 {
-	if (key == "UseVisibilityCulling")
-	{
-		mUseVisibilityCulling = (*static_cast<const bool *>(val));
+	if (key == "UseDepthPass")
+	{
+		mUseDepthPass = (*static_cast<const bool *>(val));
 		return true;
 	}
@@ -209,4 +287,9 @@
 	{
 		mVisualizeCulledNodes = (*static_cast<const bool *>(val));
+		return true;
+	}
+	if (key == "DelayRenderTransparents")
+	{
+		mDelayRenderTransparents = (*static_cast<const bool *>(val));
 		return true;
 	}
@@ -266,5 +349,5 @@
             bool doLightIteration, const LightList* manualLightList)
 {
-	if (mRenderTransparentObjects)
+	if (!mSkipTransparents)
 	{
 		OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
Index: trunk/VUT/Ogre/src/OgrePlatformOcclusionQuery.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformOcclusionQuery.cpp	(revision 96)
+++ trunk/VUT/Ogre/src/OgrePlatformOcclusionQuery.cpp	(revision 115)
@@ -1,3 +1,4 @@
 #include "OgrePlatformOcclusionQuery.h"
+#include <OgreLogManager.h>
 
 namespace Ogre {
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 104)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManagerDll.cpp	(revision 115)
@@ -27,9 +27,9 @@
 #include <OgreVisibilityOctreeSceneManager.h>
 //#include <OgreVisibilityDotSceneManager.h>
+
 #include <OgreHeightmapTerrainPageSource.h>
 #include <OgreRoot.h>
-
+#include <OgreLogManager.h>
 #include "VisibilityManager.h"
-#include "StopAndWaitCullingManager.h"
 #include "VisibilityEnvironment.h"
 
@@ -39,7 +39,7 @@
 namespace Ogre {
 
-// VisibilityDotSceneManager *cullingDotPlugin;
-VisibilityOctreeSceneManager *cullingOctreePlugin;
-VisibilityTerrainSceneManager *cullingTerrainPlugin;
+VisibilityOctreeSceneManager *visibilityOctreePlugin;
+VisibilityTerrainSceneManager *visibilityTerrainPlugin;
+//VisibilityDotSceneManager *visibilityDotPlugin;
 
 HeightmapTerrainPageSource *heightmapTerrainPageSource;
@@ -48,25 +48,34 @@
 extern "C" void dllStartPlugin(void)
 {
+	//visEnv = new GtpVisibility::VisibilityEnvironment();
 	visManager = new GtpVisibility::VisibilityManager(visEnv);
+
 	// Create new scene manager
+	visibilityOctreePlugin = new VisibilityOctreeSceneManager(visManager);
+	visibilityTerrainPlugin = new VisibilityTerrainSceneManager(visManager);
 	//occlusionDotPlugin = new VisibilityDotSceneManager();
-	cullingOctreePlugin = new VisibilityOctreeSceneManager(visManager);
-	cullingTerrainPlugin = new VisibilityTerrainSceneManager(visManager);
+
 	heightmapTerrainPageSource = new HeightmapTerrainPageSource();
+	visibilityTerrainPlugin->registerPageSource("Heightmap", heightmapTerrainPageSource);
 
-	cullingTerrainPlugin->registerPageSource("Heightmap", heightmapTerrainPageSource);
+	
+	// Register
+	Root::getSingleton().setSceneManager(ST_GENERIC, visibilityOctreePlugin);
+	Root::getSingleton().setSceneManager(ST_EXTERIOR_CLOSE, visibilityTerrainPlugin);
+	//Root::getSingleton().setSceneManager(ST_GENERIC, occlusionDotPlugin);
 
-	// Register
-	//Root::getSingleton().setSceneManager( ST_GENERIC, occlusionDotPlugin );
-	Root::getSingleton().setSceneManager( ST_GENERIC, cullingOctreePlugin );
-	Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, cullingTerrainPlugin );
+	LogManager::getSingleton().logMessage("registered akira plugins");
 }
+//-----------------------------------------------------------------------
 extern "C" void dllStopPlugin(void)
 {
 	delete heightmapTerrainPageSource;
-    //delete occlusionDotPlugin;
-	delete cullingOctreePlugin;
-	delete cullingTerrainPlugin;
+  
+	delete visibilityOctreePlugin;
+	delete visibilityTerrainPlugin;
+	//delete occlusionDotPlugin;
+
 	delete visManager;
+	//delete visEnv;
 }
 
Index: trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 112)
+++ trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 115)
@@ -12,5 +12,5 @@
 //-----------------------------------------------------------------------
 VisibilitySceneManager::VisibilitySceneManager(GtpVisibility::VisibilityManager *visManager)
-:mVisibilityManager(visManager), mUseVisibilityCulling(true), mShowVisualization(false)
+:mVisibilityManager(visManager), mUseDepthPass(false), mShowVisualization(false)
 {
 	mHierarchyInterface = 
@@ -29,5 +29,5 @@
 	// we interleave identification and rendering of objects 
 	// in _renderVisibibleObjects
-	if (!mUseVisibilityCulling)
+	if (!mUseDepthPass)
 	{
 		SceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -48,5 +48,5 @@
 
 	// standard terrain scenemanager rendering without hierarchical culling
-	if (!mUseVisibilityCulling || mShowVisualization)
+	if (!mUseDepthPass || mShowVisualization)
 	{	
 		SceneManager::_renderVisibleObjects();
@@ -68,5 +68,5 @@
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
+	_deleteRenderedQueueGroups(false);
 #endif
 
@@ -84,5 +84,5 @@
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
+	//_deleteRenderedQueueGroups();
 #endif
 
@@ -136,5 +136,5 @@
 }
 //-----------------------------------------------------------------------
-GtpVisibility::VisibilityManager *VisibilitySceneManager::getVisibilityManager( void )
+GtpVisibility::VisibilityManager *VisibilitySceneManager::getVisibilityManager()
 {
 	return mVisibilityManager;
Index: trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 113)
+++ trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 115)
@@ -4,5 +4,5 @@
 #include <OgreLogManager.h>
 #include <OgreStringConverter.h>
-#include <windows.h>
+
 
 namespace Ogre {
@@ -107,5 +107,5 @@
 
 		static_cast<OctreeSceneManager *>(mSceneManager)->_renderOctant(mCamera, 
-			octant, mOnlyShadowCasters);
+			octant, mOnlyShadowCasters, mLeaveTransparentsInQueue);
 
 		mNumRenderedNodes ++;
Index: trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 114)
+++ trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 115)
@@ -14,9 +14,10 @@
 : 
 mVisibilityManager(visManager), 
-mUseVisibilityCulling(true),
+mUseDepthPass(false),
 mShowVisualization(false),
 mRenderNodesForViz(false),
 mVisualizeCulledNodes(false),
-mRenderTransparentObjects(false)
+mSkipTransparents(false),
+mDelayRenderTransparents(true)
 {
 	mHierarchyInterface = 
@@ -29,4 +30,29 @@
 	// TODO: find reasonable value for max depth
 	mMaxDepth = 50;
+
+	CreateDepthPass();
+}
+//-----------------------------------------------------------------------
+void VisibilityOctreeSceneManager::CreateDepthPass()
+{
+	MaterialPtr depthMat = MaterialManager::getSingleton().getByName("Visibility/DepthPass");
+
+	if (depthMat.isNull())
+    {
+		// Init
+		depthMat = MaterialManager::getSingleton().create(
+                "Visibility/DepthPass",
+                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+
+		depthMat->createTechnique()->createPass();
+        mDepthPass = depthMat->getTechnique(0)->getPass(0);
+		mDepthPass->setColourWriteEnabled(false);
+		mDepthPass->setDepthWriteEnabled(true);
+		mDepthPass->setLightingEnabled(false);
+	}
+	else
+	{
+		mDepthPass = depthMat->getTechnique(0)->getPass(0);
+	}
 }
 //-----------------------------------------------------------------------
@@ -38,21 +64,27 @@
 void VisibilityOctreeSceneManager::_renderVisibleObjects()
 {
-	// two cameras (one for culling, one for rendering)
-	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
-							mCullCamera ? getCamera("CullCamera") : NULL);
-
-	if (!mShowVisualization)
+		if (!mShowVisualization)
 	{
 		// two cameras (one for culling, one for rendering)
 		mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
-								mCullCamera ? getCamera("CullCamera") : NULL);
+								mCullCamera ? getCamera("CullCamera") : NULL, mDelayRenderTransparents);
 
 		// call initframe to reset culling manager stats
 		mVisibilityManager->GetCullingManager()->InitFrame(mVisualizeCulledNodes);
 	}
+	
+	// standard terrain scenemanager rendering without hierarchical culling
+	if (!mUseDepthPass || mShowVisualization)
+	{	
+		OctreeSceneManager::_renderVisibleObjects();
+	
+		return;
+	} 
 	
 	//-- hierarchical culling
 	// the objects of different layers (e.g., background, scene, 
 	// overlay) must be identified and rendered one after another
+
+	mSkipTransparents = false;
 
 	//-- render background
@@ -65,5 +97,5 @@
 
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
+	_deleteRenderedQueueGroups(false);
 #endif
 
@@ -72,17 +104,18 @@
 	addSpecialCaseRenderQueue(RENDER_QUEUE_OVERLAY);
 	setSpecialCaseRenderQueueMode(SceneManager::SCRQM_EXCLUDE);
-
+	
+	// render only solids in hierarchical algorithm. 
+	// Transparents need sorting, thus we render them afterwards
+	mSkipTransparents = mDelayRenderTransparents;
 
 	/** 
 	* the hierarchical culling algorithm
 	**/
+	
 	mVisibilityManager->ApplyVisibilityCulling();
-
-
-#ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	_deleteRenderedQueueGroups();
-#endif
-
-	//-- render overlay
+	
+	//-- now we can savely render all remaining objects, e.g., transparents, overlay
+	mSkipTransparents = false;
+
 	clearSpecialCaseRenderQueues();
 	SceneManager::_renderVisibleObjects();
@@ -99,5 +132,5 @@
 	// we interleave identification and rendering of objects 
 	// in _renderVisibibleObjects
-	if (!mUseVisibilityCulling)
+	if (!mUseDepthPass)
 	{
 		OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -123,6 +156,6 @@
 		if (mRenderNodesForViz || mRenderNodesContentForViz)
 		{
-			// change node material so it is better suited for visualization
-		/*	MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
+		/*	// change node material so it is better suited for visualization
+			MaterialPtr nodeMat = MaterialManager::getSingleton().getByName("Core/NodeMaterial");
 			nodeMat->setAmbient(1, 1, 0);
 			nodeMat->setLightingEnabled(true);
@@ -164,7 +197,7 @@
 bool VisibilityOctreeSceneManager::setOption(const String & key, const void * val)
 {
-	if (key == "UseVisibilityCulling")
-	{
-		mUseVisibilityCulling = (*static_cast<const bool *>(val));
+	if (key == "UseDepthPass")
+	{
+		mUseDepthPass = (*static_cast<const bool *>(val));
 		return true;
 	}
@@ -199,5 +232,9 @@
 		return true;
 	}
-
+	if (key == "DelayRenderTransparents")
+	{
+		mDelayRenderTransparents = (*static_cast<const bool *>(val));
+		return true;
+	}
 	return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface).
 		setOption(key, val) || OctreeSceneManager::setOption(key, val);
@@ -240,5 +277,5 @@
             bool doLightIteration, const LightList* manualLightList)
 {
-	if (mRenderTransparentObjects)
+	if (!mSkipTransparents)
 	{
 		OctreeSceneManager::renderObjects(objs, doLightIteration, manualLightList);
Index: trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 113)
+++ trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 115)
@@ -10,9 +10,9 @@
 PlatformHierarchyInterface::PlatformHierarchyInterface(SceneManager *sm, RenderSystem *rsys):
 mSceneManager(sm), mRenderSystem(rsys), mSolidBoundingBox(NULL),
-mCamera(NULL), mCullCamera(NULL), mOnlyShadowCasters(false)
-{
-}
-//-----------------------------------------------------------------------
-void PlatformHierarchyInterface::CreateCulledNodeMaterials()
+mCamera(NULL), mCullCamera(NULL), mOnlyShadowCasters(false), mLeaveTransparentsInQueue(false)
+{
+}
+//-----------------------------------------------------------------------
+void PlatformHierarchyInterface::CreateNodeVizMaterials()
 {
 	// material for frustum culled nodes
@@ -25,8 +25,7 @@
 		mat->createTechnique()->createPass();
 		
-		mat->getTechnique(0)->getPass(0)->setAmbient(1,0,0);
+		mat->getTechnique(0)->getPass(0)->setAmbient(1, 0, 0);
 		mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
 		//mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
-		
 		mat->load();
 	}
@@ -41,8 +40,22 @@
 		mat->createTechnique()->createPass();
 		
-		mat->getTechnique(0)->getPass(0)->setAmbient(0,0,1);
+		mat->getTechnique(0)->getPass(0)->setAmbient(0, 0, 1);
 		mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
 		mat->load();
 	}
+
+	// material for scene nodes
+	/*mat = MaterialManager::getSingleton().getByName("SceneNodesMaterial");
+
+	if (mat.isNull())
+	{
+		mat = MaterialManager::getSingleton().create("SceneNodesMaterial", 
+			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
+		mat->createTechnique()->createPass();
+		
+		mat->getTechnique(0)->getPass(0)->setAmbient(1, 1, 0);
+		mat->getTechnique(0)->getPass(0)->setLightingEnabled(true);
+		mat->load();
+	}*/
 }
 //-----------------------------------------------------------------------
@@ -71,5 +84,7 @@
 	mRenderSystem->_setWorldMatrix(Ogre::Matrix4::IDENTITY);
 	mSceneManager->useRenderableViewProjMode(solidBox);
-	//mSceneManager->setOcclusionPass(solidBox->getTechnique()->getPass(0));
+	
+	// set no depth write, no color, no lighting material
+	//mSceneManager->setPass(solidBox->getTechnique()->getPass(0));
 	SetOcclusionPass();
 
@@ -112,9 +127,9 @@
 //-----------------------------------------------------------------------
 void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, 
-										   Camera *cam, Camera *cullCam)
+										   Camera *cam, Camera *cullCam, bool leaveTransparentsInQueue)
 {
 	GtpVisibility::HierarchyInterface::InitFrame(root);
 	mPreviousNode = NULL;
-
+	mLeaveTransparentsInQueue = leaveTransparentsInQueue;
 	SetCamera(cam);
 
@@ -128,5 +143,5 @@
 	}
 
-	CreateCulledNodeMaterials();
+	CreateNodeVizMaterials();
 }
 //-----------------------------------------------------------------------
@@ -151,4 +166,13 @@
 }
 //-----------------------------------------------------------------------
+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) 
@@ -162,6 +186,5 @@
 	// if node is leaf and was visible => will be rendered anyway.
 	// In this case we can also test with the real geometry.
-	// if camera for culling is different from camera for rendering => cannot optimize
-	if (mUseOptimization && wasVisible && IsLeaf(node) && (mCamera == mCullCamera))
+	if (UseOptimization() && wasVisible && IsLeaf(node) ) 
 	{
 		//LogManager::getSingleton().logMessage("render node\n");
