Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3047)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h	(revision 3048)
@@ -105,4 +105,5 @@
 	GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
 
+	static Technique GetQueryTechnique();
 
 protected:
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3047)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp	(revision 3048)
@@ -17,5 +17,5 @@
 
 RenderState::RenderState():
-mRenderType(FORWARD),
+mRenderTechnique(FORWARD),
 mUseAlphaToCoverage(true),
 mLockCullFaceEnabled(false)
@@ -85,24 +85,21 @@
 	if (mode == QUERY)
 	{
-		if (mRenderType != DEPTH_PASS)
-		{
+		if (mLightingEnabled)
 			glDisable(GL_LIGHTING);
+
+		if (mColorWriteEnabled)
 			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-		}
 
 		if (mFragmentProgramEnabled)
-		{
 			ResourceManager::GetSingleton()->DisableFragmentProfile();
-		}
 			
 		if (mVertexProgramEnabled)
-		{
 			ResourceManager::GetSingleton()->DisableVertexProfile();
-		}
 		
 		glDepthMask(GL_FALSE);
 
-		static Technique defaultTech;
-		SetState(&defaultTech);
+		/// the query box material
+		static Technique queryTech = Technique::GetQueryTechnique();
+		SetState(&queryTech);
 	}
 	else // mode returns to render
@@ -111,19 +108,15 @@
 		//-- restore render state
 
-		if (mRenderType != DEPTH_PASS)
-		{
+		if (mLightingEnabled)
 			glEnable(GL_LIGHTING);
+
+		if (mColorWriteEnabled)
 			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-		}
 		
 		if (mFragmentProgramEnabled)
-		{
 			ResourceManager::GetSingleton()->EnableFragmentProfile();
-		}
 			
 		if (mVertexProgramEnabled)
-		{
 			ResourceManager::GetSingleton()->EnableVertexProfile();
-		}
 
 		glDepthMask(GL_TRUE);
@@ -175,6 +168,5 @@
 	}
 
-	if (mTexturesEnabled && 
-		(!texturing || (mRenderType == DEPTH_PASS) && !mAlphaTestEnabled))
+	if (mTexturesEnabled && !texturing)
 	{
 		mTexturesEnabled = false;
@@ -187,6 +179,5 @@
 	else if (!mTexturesEnabled && texturing)
 	{
-		// support only alpha textures in depth pass
-		if ((mRenderType != DEPTH_PASS) || mAlphaTestEnabled)
+		if (mAlphaTestEnabled)
 		{
 			mTexturesEnabled = true;
@@ -282,13 +273,13 @@
 
 
-void RenderState::SetRenderPassType(RenderPassType t) 
+void RenderState::SetRenderTechnique(RenderTechnique t) 
 { 
-	mRenderType = t; 
-}
-
-
-RenderState::RenderPassType RenderState::GetRenderPassType() const 
-{
-	return mRenderType; 
+	mRenderTechnique = t; 
+}
+
+
+RenderState::RenderTechnique RenderState::GetRenderTechnique() const 
+{
+	return mRenderTechnique; 
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3047)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3048)
@@ -118,5 +118,5 @@
 
 	///////////////
-	//-- load lod levels
+	//-- load LOD levels
 
 	// note: lods must be ordered from smallest distance to largest
@@ -126,4 +126,5 @@
 	for (int i = 0; i < numLODs; ++ i)
 	{
+		// the distance until the next LOD level is used
 		float dist;
 		str.read(reinterpret_cast<char *>(&dist), sizeof(float));
@@ -158,5 +159,5 @@
 	//-- hack: add tree animation (should be done per material script!)
 
-	if (numLODs > 1)
+	if (0)//numLODs > 1)
 	{
 		ShapeContainer::iterator sstart, send;
@@ -320,5 +321,14 @@
 	deferred->SetVertexProgram(mMrtDefaultVertexProgram);
 	
+
+	///////////
+	//-- add depth pass
+
+	Technique *depthPass = new Technique(*tech);
+	depthPass->SetColorWriteEnabled(false);
+	depthPass->SetLightingEnabled(false);
+
 	mat->AddTechnique(deferred);
+	mat->AddTechnique(depthPass);
 
 	return mat;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3045)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp	(revision 3048)
@@ -121,8 +121,5 @@
 	Technique *tech;
 
-	if (state->GetRenderPassType() == RenderState::DEFERRED)
-		tech = mat->GetTechnique(1);
-	else
-		tech = mat->GetTechnique(0);
+	tech = mat->GetTechnique(state->GetRenderTechnique());
 
 	GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters();
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3047)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h	(revision 3048)
@@ -25,10 +25,10 @@
 	};
 
-	/// the used render type for this render pass
-	enum RenderPassType
+	/// the used render technique
+	enum RenderTechnique
 	{
 		FORWARD,
-		DEPTH_PASS,
-		DEFERRED
+		DEFERRED,
+		DEPTH_PASS
 	};
 
@@ -58,10 +58,10 @@
 	*/
 	inline int GetCurrentVboId() const { return mCurrentVboId; }
-	/** Sets the type of rendering used (foreward, depth pass, deferred)
+	/** Sets the render technique (foreward, depth pass, deferred)
 	*/
-	void SetRenderPassType(RenderPassType t);
+	void SetRenderTechnique(RenderTechnique t);
 	/** See Set
 	*/
-	RenderPassType GetRenderPassType() const;
+	RenderTechnique GetRenderTechnique() const;
 	/** If alpha to coverage is instead of alpha testing
 	*/
@@ -84,6 +84,6 @@
 
 	int mCurrentVboId;
-
-	RenderPassType mRenderType;
+	/// the current render technique
+	RenderTechnique mRenderTechnique;
 
 	bool mUseAlphaToCoverage;
@@ -99,5 +99,5 @@
 	bool mVertexProgramEnabled;
 
-	bool mUseLighting;
+	bool mLightingEnabled;
 	bool mColorWriteEnabled;
 };
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3047)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp	(revision 3048)
@@ -33,5 +33,5 @@
 	mColorWriteEnabled = true;
 	/// if lighting is used
-	bool mLightingEnabled = true;
+	mLightingEnabled = true;
 }
 
@@ -92,4 +92,17 @@
 
 
+Technique Technique::GetQueryTechnique()
+{
+	Technique tech;
+
+	tech.Init();
+
+	tech.SetColorWriteEnabled(false);
+	tech.SetLightingEnabled(false);
+
+	return tech;
+}
+
+
 /***********************************************/
 /*        class Material implementation        */
@@ -99,8 +112,5 @@
 void Material::Render(RenderState *state)
 {
-	if (state->GetRenderPassType() == RenderState::DEFERRED)
-		mTechniques[1]->Render(state);
-	else
-		mTechniques[0]->Render(state);
+	mTechniques[state->GetRenderTechnique()]->Render(state);
 }
 
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3046)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3048)
@@ -485,5 +485,5 @@
 	visualization = new Visualization(bvh, camera, NULL, &state);
 	
-	state.SetRenderPassType(RenderState::FORWARD);
+	state.SetRenderTechnique(RenderState::FORWARD);
 
 	// frame time is restarted every frame
@@ -819,5 +819,5 @@
 	glDisable(GL_MULTISAMPLE_ARB);
 
-	state.SetRenderPassType(RenderState::DEFERRED);
+	state.SetRenderTechnique(RenderState::DEFERRED);
 
 	loader->EnableVertexProfile();
@@ -905,5 +905,5 @@
 		glEnable(GL_MULTISAMPLE_ARB);
 		
-		state.SetRenderPassType(RenderState::FORWARD);
+		state.SetRenderTechnique(RenderState::FORWARD);
 		glEnable(GL_LIGHTING);
 
@@ -919,5 +919,5 @@
 		state.SetUseAlphaToCoverage(false);
 
-		state.SetRenderPassType(RenderState::DEPTH_PASS);
+		state.SetRenderTechnique(RenderState::DEPTH_PASS);
 
 		if (!fbo) InitFBO(); fbo->Bind();
@@ -939,5 +939,5 @@
 		glEnable(GL_MULTISAMPLE_ARB);
 		
-		state.SetRenderPassType(RenderState::DEPTH_PASS);
+		state.SetRenderTechnique(RenderState::DEPTH_PASS);
 
 		// the scene is rendered withouth any shading	
@@ -951,5 +951,5 @@
 		break;
 	
-	case RenderState::DEFERRED:
+	case RENDER_DEFERRED:
 
 		if (showShadowMap && !renderLightView)
@@ -1012,5 +1012,5 @@
 	// this would conveniently solves some issues (e.g, skys without shadows)
 
-	RenderSky();
+	//RenderSky();
 
 
@@ -1048,5 +1048,5 @@
 
 
-	state.SetRenderPassType(RenderState::FORWARD);
+	state.SetRenderTechnique(RenderState::FORWARD);
 	state.Reset();
 
@@ -1863,5 +1863,5 @@
 {
 	if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED))
-		state.SetRenderPassType(RenderState::DEFERRED);
+		state.SetRenderTechnique(RenderState::DEFERRED);
 
 	const bool useToneMapping = 
@@ -1870,5 +1870,5 @@
 
 	preetham->RenderSkyDome(-light->GetDirection(), camera, &state, !useToneMapping);
-
+	/// once again reset the state
 	state.Reset();
 }
@@ -1890,5 +1890,5 @@
 		glDisable(GL_LIGHTING);
 		glViewport(0, 0, texWidth, texHeight);
-
+		// rese the state before the final visible objects pass
 		state.Reset();
 		InitDeferredRendering();
@@ -1897,5 +1897,6 @@
 	{
 		glEnable(GL_LIGHTING);
-		state.SetRenderPassType(RenderState::FORWARD);
+		state.SetRenderTechnique(RenderState::FORWARD);
+		// rese the state before the final visible objects pass
 		state.Reset();
 	}
@@ -1955,5 +1956,5 @@
 	glDisableClientState(GL_NORMAL_ARRAY);
 
-	state.SetRenderPassType(RenderState::DEPTH_PASS);
+	state.SetRenderTechnique(RenderState::DEPTH_PASS);
 	
 	// hack: disable cull face because of alpha textured balconies
