Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 137)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 139)
@@ -75,5 +75,5 @@
 mCullCamera(false),
 mRecord(false),
-mUseShadows(false),
+mShowShadows(false),
 mShowHelp(false),
 mDisplayCameraDetails(false),
@@ -159,5 +159,5 @@
 	mSceneMgr->setOption("ShowOctree", &mShowOctree);
 	mSceneMgr->setOption("CullCamera", &mCullCamera);
-	mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
+	mSceneMgr->setOption("PrepareVisualization", &mShowVisualization);
 
 	// TODO: change this (does not work with other scene manager plugins)
@@ -257,5 +257,10 @@
 	}
 
-//	mInputDevice->capture();
+	if (mDisplayCameraDetails)
+    {
+        // Print camera details
+        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + 
+			" " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
+    }
 
 	//-- IMPORTANT: must be set, otherwise terrain is not rendered correctly
@@ -706,7 +711,6 @@
 void TerrainFrameListener::toggleShowViz()
 {
-	mShowVisualization = !mShowVisualization;
-	mVisualizeCulledNodes = !mVisualizeCulledNodes;
-
+	mVisualizeCulledNodes = mShowVisualization = !mShowVisualization;
+	
 	// create viewport with priority VIZ_VIEWPORT_Z_ORDER: 
 	// will be rendered over standard viewport
@@ -721,5 +725,5 @@
 		// Alter the camera aspect ratio to match the viewport
         mVizCamera->setAspectRatio(Real(vizvp->getActualWidth()) / 
-			Real(vizvp->getActualHeight()));
+								   Real(vizvp->getActualHeight()));
 		
 		mSceneMgr->setOption("VisualizeCulledNodes", &mVisualizeCulledNodes);
@@ -733,23 +737,26 @@
 		mSceneMgr->setSkyPlane(true, plane, "Examples/TransparentTest", 4000, 75, false);
 		*/
-		
 	}
 	else
 	{
+		// remove visualization viewport
 		mWindow->removeViewport(VIZ_VIEWPORT_Z_ORDER);
-		// if octree was enabled for visualization purpose, reset now
+
+		// octree bounding boxes are shown for visualization purpose, reset now
 		mSceneMgr->setOption("ShowOctree", &mShowOctree);
 	}
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::toggleUseShadows()
-{
-	mUseShadows = !mUseShadows;
-
-	mSunLight->setCastShadows(mUseShadows);
-
-	if (mUseShadows)
+void TerrainFrameListener::toggleShowShadows()
+{
+	mShowShadows = !mShowShadows;
+
+	mSunLight->setCastShadows(mShowShadows);
+
+	if (mShowShadows)
 	{
 		mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
+		//mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_MODULATIVE);
+		//mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);		
 	}
 	else
@@ -805,5 +812,5 @@
 		break;
 	case KC_S:
-		toggleUseShadows();
+		toggleShowShadows();
 		break;
 
@@ -857,11 +864,4 @@
 		break;
 	}
-
-	if (mDisplayCameraDetails)
-    {
-        // Print camera details
-        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + 
-			" " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
-    }
 
 	CEGUI::System::getSingleton().injectKeyDown(e->getKey());
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 137)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 139)
@@ -84,5 +84,6 @@
 {
 	// Set ambient light
-	mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
+	mAmbientLight = ColourValue(0.5, 0.5, 0.5);
+	mSceneMgr->setAmbientLight(mAmbientLight);
 	
 	//-- create light
@@ -100,5 +101,4 @@
 	mSunLight->setDirection(dir);
 	//mSunLight->setDirection(Vector3::NEGATIVE_UNIT_Y);
-
 	mSunLight->setDiffuseColour(1, 1, 1);
 	mSunLight->setSpecularColour(1, 1, 1);
@@ -137,14 +137,6 @@
 	*/
 	mSceneMgr->setShadowTextureSettings(1024, 2);
-/*	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE))
-    {	// In D3D, use a 1024x1024 shadow texture
-		mSceneMgr->setShadowTextureSettings(1024, 2);	}	else	{
-		// Use 512x512 texture in GL since we can't go higher than the window res
-		mSceneMgr->setShadowTextureSettings(512, 2);}
-		*/
-
-	//mSceneMgr->setShadowColour(ColourValue(0, 0, 0));
 	mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
-    // mSceneMgr->setShowDebugShadows(true);
+    //mSceneMgr->setShowDebugShadows(true);
 
 
@@ -220,15 +212,15 @@
 	const bool nShowViz = !showViz;
 
-	// ambient light must be full for visualization
+	mSavedShadowTechnique = mSceneMgr->getShadowTechnique();
+	mSavedAmbientLight = mSceneMgr->getAmbientLight();
+
+	// -- ambient light must be full for visualization, shadows disabled
     if (showViz)
 	{
 		mSceneMgr->setAmbientLight(ColourValue(1, 1, 1));
-	}
-	else
-	{
-		mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
-	}
-
-    mSceneMgr->setOption("ShowVisualization", &showViz);
+		mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE);
+	}
+	
+    mSceneMgr->setOption("PrepareVisualization", &showViz);
 	mSceneMgr->setOption("SkyBoxEnabled", &nShowViz);
 	//mSceneMgr->setOption("SkyPlaneEnabled", &showViz);
@@ -239,4 +231,8 @@
 void VisualizationRenderTargetListener::postRenderTargetUpdate(const RenderTargetEvent &evt)
 {
+	// reset values
+	mSceneMgr->setShadowTechnique(mSavedShadowTechnique);
+	mSceneMgr->setAmbientLight(mSavedAmbientLight);
+	
 	RenderTargetListener::postRenderTargetUpdate(evt);
 }
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 135)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 139)
@@ -98,5 +98,5 @@
 	void toggleShowStats();
 
-	void toggleUseShadows();
+	void toggleShowShadows();
 	void toggleDisplayCameraDetails();
 	void takeScreenShot();
@@ -175,5 +175,5 @@
 	bool mCullCamera;
 	bool mRecord;
-	bool mUseShadows;
+	bool mShowShadows;
 	bool mVisualizeCulledNodes;
 	bool mShowHelp;
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 139)
@@ -3,8 +3,8 @@
 
 #include "CEGUIForwardRefs.h"
+#include <OgreRenderTargetListener.h>
 #include "ExampleApplication.h"
+
 #include "OgreTerrainContentGenerator.h"
-
-#include <OgreRenderTargetListener.h>
 #include "TerrainFrameListener.h"
 
@@ -19,4 +19,7 @@
 
 	SceneManager *mSceneMgr;
+	
+	ShadowTechnique mSavedShadowTechnique;
+	ColourValue mSavedAmbientLight;
 };
 
@@ -54,7 +57,8 @@
 	SceneNode *mCamNode;
 	Light *mSunLight;
-	VisualizationRenderTargetListener *mRenderTargetListener;
 
 	TerrainFrameListener *mTerrainFrameListener;
+	ColourValue mAmbientLight;
+	//VisualizationRenderTargetListener *mVizRenderTargetListener;
 	
 private:
