Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudDiffuseColorTextureViewMode.h
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudDiffuseColorTextureViewMode.h	(revision 778)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudDiffuseColorTextureViewMode.h	(revision 778)
@@ -0,0 +1,119 @@
+#ifndef _LBBCBILLBOARDCLOUDDIFFUSECOLORTEXTUREVIEWMODE_H
+#define _LBBCBILLBOARDCLOUDDIFFUSECOLORTEXTUREVIEWMODE_H
+
+#include <LBBCPrerequisites.h>
+#include <LBBCManager.h>
+#include <IMG.h>
+#include <OBAOgreFrameListenerMode.h>
+
+namespace LBBC {
+
+class _BBCExport BillboardCloudDiffuseColorTextureViewMode : public OBA::OgreFrameListenerMode 
+{
+	protected:
+		unsigned int mFrame;
+
+		Ogre::SceneNode *mEntityClustersGroupedSceneNode;
+		
+		Ogre::SceneNode *mBillboardCloudSplittedSceneNode;
+
+		Ogre::Entity *mEntityClustersGrouped;
+
+		Ogre::Entity *mBillboardCloudSplitted;
+
+		IMG::TexturePtr mClusterTexture;
+
+		IMG::TextureAtlasPtr mTextureAtlas;
+
+		unsigned int mNumTextures;
+
+		unsigned int mCurrentTexture;
+
+		unsigned int mTextureAtlasSize;
+
+		unsigned int mTextureSize;
+
+		unsigned int mBitRange;
+
+		Ogre::PixelFormat mSrcPixelFormat;
+
+		Ogre::PixelFormat mDestPixelFormat;
+
+		Ogre::String mTextureAtlasName;
+
+		Ogre::String mTextureAtlasFolder;
+
+		Ogre::String mEntityClustersGroupedName;
+
+		Ogre::String mBillboardCloudSplittedName;
+
+		Ogre::Matrix4 mCustomProjMatrix;
+
+		Ogre::String mTextureName;
+
+		bool mDebugBillboardGeneration;
+
+		bool mDebugTextureAtlasGeneration;
+
+		unsigned int mCurrentBillboardGroup;
+
+		unsigned int mCurrentBillboard;
+
+	public:
+
+		BillboardCloudDiffuseColorTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);	
+
+		virtual ~BillboardCloudDiffuseColorTextureViewMode();		
+
+		virtual bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader);
+
+		virtual void createScene();
+
+		virtual void destroyScene();
+
+		void setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration);
+
+		void setTextureName(Ogre::String textureName);
+
+		void configureBillboard();
+
+		void enableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped);
+
+		void disableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped);
+
+		void configureTexture();
+
+		void configureTextureAtlas();
+	
+		bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt);
+
+		void saveTextureAtlas();
+		
+		void setTextureAtlasSize(unsigned int size);
+
+		void setTextureSize(unsigned int size);
+
+		void setEntityClustersGroupedName(Ogre::String entityClustersGrouped);
+
+		void setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName);
+
+		void setTextureAtlasName(Ogre::String textureAtlasName);
+
+		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
+
+		void setTextureAtlasBitRange(unsigned int bitRange);
+
+		void configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard);
+
+		void initializeEntityClustersGrouped();
+
+		void initializeBillboardCloudSplitted();
+		
+		void generateTexture();
+
+		void generateTextureAtlas();
+
+};
+
+}
+#endif
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h	(revision 745)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBC.h	(revision 778)
@@ -10,4 +10,5 @@
 #include <LBBCClusterViewMode.h>
 #include <LBBCEntityTextureAtlasViewMode.h>
-#include <LBBCBillboardCloudTextureViewMode.h>
+#include <LBBCBillboardCloudDiffuseColorTextureViewMode.h>
+#include <LBBCBillboardCloudIndirectTextureViewMode.h>
 #endif
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudIndirectTextureViewMode.h
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudIndirectTextureViewMode.h	(revision 778)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudIndirectTextureViewMode.h	(revision 778)
@@ -0,0 +1,121 @@
+#ifndef _LBBCBILLBOARDCLOUDINDIRECTTEXTUREVIEWMODE_H
+#define _LBBCBILLBOARDCLOUDINDIRECTTEXTUREVIEWMODE_H
+
+#include <LBBCPrerequisites.h>
+#include <LBBCManager.h>
+#include <IMG.h>
+#include <OBAOgreFrameListenerMode.h>
+
+namespace LBBC {
+
+class _BBCExport BillboardCloudIndirectTextureViewMode : public OBA::OgreFrameListenerMode 
+{
+	protected:
+		unsigned int mFrame;
+
+		Ogre::SceneNode *mBillboardCloudPointClustersSceneNode;
+		
+		Ogre::SceneNode *mBillboardCloudSplittedSceneNode;
+
+		Ogre::SceneNode *mEntityClustersGroupedSceneNode;
+
+		Ogre::Entity *mEntityClustersGrouped;
+
+		Ogre::Entity *mBillboardCloudPointClusters;
+
+		Ogre::Entity *mBillboardCloudSplitted;
+
+		IMG::TexturePtr mClusterTexture;
+
+		IMG::TextureAtlasPtr mTextureAtlas;
+
+		unsigned int mNumTextures;
+
+		unsigned int mCurrentTexture;
+
+		unsigned int mTextureAtlasSize;
+
+		unsigned int mTextureSize;
+
+		unsigned int mBitRange;
+
+		Ogre::PixelFormat mSrcPixelFormat;
+
+		Ogre::PixelFormat mDestPixelFormat;
+
+		Ogre::String mTextureAtlasName;
+
+		Ogre::String mTextureAtlasFolder;
+
+		Ogre::String mBillboardCloudPointClustersName;
+
+		Ogre::String mBillboardCloudSplittedName;
+
+		Ogre::String mEntityClustersGroupedName;
+
+		Ogre::Matrix4 mCustomProjMatrix;
+
+		bool mDebugBillboardGeneration;
+
+		bool mDebugTextureAtlasGeneration;
+
+		unsigned int mCurrentBillboardGroup;
+
+		unsigned int mCurrentBillboard;
+
+	public:
+
+		BillboardCloudIndirectTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);	
+
+		virtual ~BillboardCloudIndirectTextureViewMode();		
+
+		virtual bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader);
+
+		virtual void createScene();
+
+		virtual void destroyScene();
+
+		void setEntityClustersGroupedName(Ogre::String entityClustersGrouped);
+
+		void initializeBillboardCloudPointClusters();
+
+		void setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration);
+
+		void configureBillboard();
+
+		void configureTexture();
+
+		void configureTextureAtlas();
+	
+		bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt);
+
+		void saveTextureAtlas();
+		
+		void setTextureAtlasSize(unsigned int size);
+
+		void setTextureSize(unsigned int size);
+
+		void setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName);
+
+		void setBillboardCloudPointClustersName(Ogre::String billboardCloudPointClustersName);
+
+		void setTextureAtlasName(Ogre::String textureAtlasName);
+
+		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
+
+		void setTextureAtlasBitRange(unsigned int bitRange);
+
+		void configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard);
+
+		void initializeEntityClustersGrouped();
+
+		void initializeBillboardCloudSplitted();
+		
+		void generateTexture();
+
+		void generateTextureAtlas();
+
+};
+
+}
+#endif
Index: P/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudTextureViewMode.h
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/LBBC/LBBCBillboardCloudTextureViewMode.h	(revision 751)
+++ 	(revision )
@@ -1,194 +1,0 @@
-#ifndef _LBBCBILLBOARDCLOUDTEXTUREVIEWMODE_H
-#define _LBBCBILLBOARDCLOUDTEXTUREVIEWMODE_H
-
-#include <LBBCPrerequisites.h>
-#include <LBBCManager.h>
-#include <IMG.h>
-#include <OBAOgreFrameListenerMode.h>
-
-namespace LBBC {
-
-class _BBCExport ClusterTextureListener : public Ogre::RenderTargetListener
-{
-protected:
-	IMG::TextureAtlasPtr mTextureAtlas;
-
-	IMG::TexturePtr mTexture;
-
-	unsigned int mNumTextures;
-
-	unsigned int mCurrentTexture;
-
-	unsigned int mSubEntityVisible;
-
-	Ogre::Entity *mEntityClusters;
-
-public:
-	
-	void setEntityClusters(Ogre::Entity *entity)
-	{
-		mEntityClusters = entity;
-	}
-
-	void setSubEntityVisible(unsigned int iSubEntity)
-	{
-		mSubEntityVisible = iSubEntity;
-	}
-
-	void setTexture(IMG::TexturePtr texture)
-	{
-		mTexture = texture;
-	}
-
-	void setTextureAtlas(IMG::TextureAtlasPtr textureAtlas)
-	{
-		mTextureAtlas = textureAtlas;
-	}
-
-	void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
-    {
-		if (mCurrentTexture < mNumTextures)
-		{
-		}
-    }
-
-	void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
-    {   
-
-    }
-
-	void setNumTextures(unsigned int numTextures)
-	{
-		mNumTextures = numTextures;
-		mCurrentTexture = 0;
-	}
-
-
-};
-
-class _BBCExport TextureAtlasListener : public Ogre::RenderTargetListener
-{
-public:
-	void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
-    {
-    }
-
-	void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt)
-    {
-		
-    }
-};
-
-class _BBCExport BillboardCloudTextureViewMode : public OBA::OgreFrameListenerMode 
-{
-	protected:
-		unsigned int mFrame;
-
-		Ogre::SceneNode *mEntityClustersGroupedSceneNode;
-		
-		Ogre::SceneNode *mBillboardCloudSplittedSceneNode;
-
-		Ogre::Entity *mEntityClustersGrouped;
-
-		Ogre::Entity *mBillboardCloudSplitted;
-
-		ClusterTextureListener mClusterTextureListener;
-
-		TextureAtlasListener mTextureAtlasListener;
-
-		IMG::TexturePtr mClusterTexture;
-
-		IMG::TextureAtlasPtr mTextureAtlas;
-
-		unsigned int mNumTextures;
-
-		unsigned int mCurrentTexture;
-
-		unsigned int mTextureAtlasSize;
-
-		unsigned int mTextureSize;
-
-		unsigned int mBitRange;
-
-		Ogre::PixelFormat mSrcPixelFormat;
-
-		Ogre::PixelFormat mDestPixelFormat;
-
-		Ogre::String mTextureAtlasName;
-
-		Ogre::String mTextureAtlasFolder;
-
-		Ogre::String mEntityClustersGroupedName;
-
-		Ogre::String mBillboardCloudSplittedName;
-
-		Ogre::Matrix4 mCustomProjMatrix;
-
-		Ogre::String mTextureName;
-
-		bool mDebugBillboardGeneration;
-
-		bool mDebugTextureAtlasGeneration;
-
-		unsigned int mCurrentBillboardGroup;
-
-		unsigned int mCurrentBillboard;
-
-	public:
-
-		BillboardCloudTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys = false, bool useBufferedInputMouse = false);	
-
-		virtual ~BillboardCloudTextureViewMode();		
-
-		virtual bool frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader);
-
-		virtual void createScene();
-
-		virtual void destroyScene();
-
-		void setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration);
-
-		void setTextureName(Ogre::String textureName);
-
-		void configureBillboard();
-
-		void enableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped);
-
-		void disableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped);
-
-		void configureTexture();
-
-		void configureTextureAtlas();
-	
-		bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt);
-
-		void saveTextureAtlas();
-		
-		void setTextureAtlasSize(unsigned int size);
-
-		void setTextureSize(unsigned int size);
-
-		void setEntityClustersGroupedName(Ogre::String entityClustersGrouped);
-
-		void setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName);
-
-		void setTextureAtlasName(Ogre::String textureAtlasName);
-
-		void setTextureAtlasFolder(Ogre::String textureAtlasFolder);
-
-		void setTextureAtlasBitRange(unsigned int bitRange);
-
-		void configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard);
-
-		void initializeEntityClustersGrouped();
-
-		void initializeBillboardCloudSplitted();
-		
-		void generateTexture();
-
-		void generateTextureAtlas();
-
-};
-
-}
-#endif
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCUtil.h
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCUtil.h	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/include/BBC/BBCUtil.h	(revision 778)
@@ -5,4 +5,6 @@
 
 namespace BBC {
+
+const Ogre::Real EPSILON_INTERSECT = 0.00000001;
 
 class _BBCExport Util
@@ -35,13 +37,70 @@
 	}
 
+	// Calculate the line segment PaPb that is the shortest route between
+	// two lines P1P2 and P3P4. Calculate also the values of mua and mub where
+	//   Pa = P1 + mua (P2 - P1)
+	//	 Pb = P3 + mub (P4 - P3)
+	// Return false if no solution exists.
+
+	static int lineLineIntersect(
+		Ogre::Vector3 p1, Ogre::Vector3 p2, Ogre::Vector3 p3, Ogre::Vector3 p4, Ogre::Vector3 *pa, Ogre::Vector3 *pb,
+		Ogre::Real *mua, Ogre::Real *mub)
+	{
+		Ogre::Vector3 p13,p43,p21;
+		Ogre::Real d1343,d4321,d1321,d4343,d2121;
+		Ogre::Real numer,denom;
+
+		p13.x = p1.x - p3.x;
+		p13.y = p1.y - p3.y;
+		p13.z = p1.z - p3.z;
+		p43.x = p4.x - p3.x;
+		p43.y = p4.y - p3.y;
+		p43.z = p4.z - p3.z;
+		if (Ogre::Math::Abs(p43.x)  < EPSILON_INTERSECT && Ogre::Math::Abs(p43.y)  < EPSILON_INTERSECT && Ogre::Math::Abs(p43.z)  < EPSILON_INTERSECT)
+		{
+			return(false);
+		}
+		p21.x = p2.x - p1.x;
+		p21.y = p2.y - p1.y;
+		p21.z = p2.z - p1.z;
+		if (Ogre::Math::Abs(p21.x)  < EPSILON_INTERSECT && Ogre::Math::Abs(p21.y)  < EPSILON_INTERSECT && Ogre::Math::Abs(p21.z)  < EPSILON_INTERSECT)
+		{
+			return(false);
+		}
+
+		d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z;
+		d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z;
+		d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z;
+		d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z;
+		d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
+
+		denom = d2121 * d4343 - d4321 * d4321;
+		if (Ogre::Math::Abs(denom) < EPSILON_INTERSECT)
+		{
+			return(false);
+		}
+		numer = d1343 * d4321 - d1321 * d4343;
+
+		*mua = numer / denom;
+		*mub = (d1343 + d4321 * (*mua)) / d4343;
+
+		pa->x = p1.x + *mua * p21.x;
+		pa->y = p1.y + *mua * p21.y;
+		pa->z = p1.z + *mua * p21.z;
+		pb->x = p3.x + *mub * p43.x;
+		pb->y = p3.y + *mub * p43.y;
+		pb->z = p3.z + *mub * p43.z;
+
+		return(true);
+	}
 };
 
 /*
-extern "C" _BBCExport double fround(double n, unsigned d)
+extern "C" _BBCExport Ogre::Real fround(Ogre::Real n, unsigned d)
 { 
-	return floor(n * pow((double)10.,(int) d) + .5) / pow((double)10.,(int) d);
+	return floor(n * pow((Ogre::Real)10.,(int) d) + .5) / pow((Ogre::Real)10.,(int) d);
 }
 
-extern "C" _BBCExport int iround(double x)
+extern "C" _BBCExport int iround(Ogre::Real x)
 {
       return (int)floor(x + 0.5);
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/scripts/IBRBillboardCloudTreeGenerator.vcproj
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/scripts/IBRBillboardCloudTreeGenerator.vcproj	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/scripts/IBRBillboardCloudTreeGenerator.vcproj	(revision 778)
@@ -213,5 +213,8 @@
 				Filter="">
 				<File
-					RelativePath="..\src\LBBCBillboardCloudTextureViewMode.cpp">
+					RelativePath="..\src\LBBCBillboardCloudDiffuseColorTextureViewMode.cpp">
+				</File>
+				<File
+					RelativePath="..\src\LBBCBillboardCloudIndirectTextureViewMode.cpp">
 				</File>
 				<File
@@ -416,5 +419,8 @@
 				</File>
 				<File
-					RelativePath="..\include\Lbbc\LBBCBillboardCloudTextureViewMode.h">
+					RelativePath="..\include\Lbbc\LBBCBillboardCloudDiffuseColorTextureViewMode.h">
+				</File>
+				<File
+					RelativePath="..\include\Lbbc\LBBCBillboardCloudIndirectTextureViewMode.h">
 				</File>
 				<File
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/OBAOgreFrameListener.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/OBAOgreFrameListener.cpp	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/OBAOgreFrameListener.cpp	(revision 778)
@@ -102,5 +102,6 @@
     }
 
-	if (mInputDevice->isKeyDown(Ogre::KC_TAB) && mTimeUntilNextToggle <= 0)
+	//if (mInputDevice->isKeyDown(Ogre::KC_TAB) && mTimeUntilNextToggle <= 0)
+	if (mInputDevice->isKeyDown(Ogre::KC_TAB))
     {		
 		mCurrentOgreFrameListenerMode = (mCurrentOgreFrameListenerMode+1) % this->getNumFrameListenerModes();		
@@ -108,5 +109,5 @@
 		mWindow->setDebugText("P: " + mDefaultOgreFrameListenerMode->getSceneManager()->getName());
 
-		mTimeUntilNextToggle = 0.25;
+		//mTimeUntilNextToggle = 0.25;		
     }
 
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudIndirectTextureViewMode.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudIndirectTextureViewMode.cpp	(revision 778)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudIndirectTextureViewMode.cpp	(revision 778)
@@ -0,0 +1,449 @@
+
+#include "LBBCBillboardCloudIndirectTextureViewMode.h"
+#include "LBBCLeaves.h"
+#include "LBBCManager.h"
+
+namespace LBBC {
+
+BillboardCloudIndirectTextureViewMode::BillboardCloudIndirectTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys, bool useBufferedInputMouse)
+:OBA::OgreFrameListenerMode(win, ogreFrameListenerModeHandle, useBufferedInputKeys, useBufferedInputMouse)
+{	
+	mFrame = 0;
+	mCurrentBillboardGroup = 0;
+	mCurrentBillboard = 0;
+	showDebugOverlay(false);
+	mDebugBillboardGeneration = false;
+	mDebugTextureAtlasGeneration = false;
+}
+
+BillboardCloudIndirectTextureViewMode::~BillboardCloudIndirectTextureViewMode()
+{
+
+}
+
+
+void BillboardCloudIndirectTextureViewMode::setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration)
+{
+	mDebugTextureAtlasGeneration = debugTextureAtlasGeneration;
+}
+
+void BillboardCloudIndirectTextureViewMode::configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard)
+{
+	BBC::BillboardPtr billboardPtr = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(iBillboard);
+	Ogre::Vector3 vTopLeft = billboardPtr->getBillboardClusterData()->getQuadTopLeftCorner();
+	Ogre::Vector3 vTopRight = billboardPtr->getBillboardClusterData()->getQuadTopRightCorner();
+	Ogre::Vector3 vBottomLeft = billboardPtr->getBillboardClusterData()->getQuadBottomLeftCorner();
+	Ogre::Vector3 vBottomRight = billboardPtr->getBillboardClusterData()->getQuadBottomRightCorner();
+
+	Ogre::Vector3 vMidPoint = vTopLeft.midPoint(vBottomRight);
+	Ogre::Vector3 vWidth(vTopRight - vTopLeft);
+	Ogre::Vector3 vHeight(vBottomLeft - vTopLeft);
+
+	Ogre::Real w = vWidth.length();
+	Ogre::Real h = vHeight.length();
+	Ogre::Real aspect = w / h;
+	Ogre::Radian fovy = Ogre::Radian(Ogre::Degree(90.0));
+	Ogre::Real nearPlane =	h / Ogre::Math::Tan(fovy/2.0,false);
+	Ogre::Real farPlane = 100000;
+
+	Ogre::Vector3 vUp = vTopLeft - vBottomLeft;
+	vUp.normalise();
+
+	Ogre::Vector3 vI(vTopRight-vTopLeft);
+	vI.normalise();
+
+	Ogre::Vector3 vJ(vBottomLeft-vTopLeft);
+	vJ.normalise();
+
+	Ogre::Vector3 vDir = -vI.crossProduct(vJ);
+	vDir.normalise();
+
+	Ogre::Vector3 vRight = vDir.crossProduct(vUp);
+	vRight.normalise();	
+
+	Ogre::Quaternion qOrientation(vRight, vUp, -vDir);
+	
+	mCamera->setNearClipDistance(nearPlane);
+	mCamera->setOrientation(qOrientation);
+	mCamera->setPosition(vMidPoint - (vDir * (nearPlane*nearPlane)));
+
+	if (Ogre::Root::getSingleton().getRenderSystem()->getName() != "Direct3D9 Rendering SubSystem")
+	{
+		Ogre::Radian thetaY (fovy / 2.0f);
+		Ogre::Real tanThetaY = Ogre::Math::Tan(thetaY);
+
+		Ogre::Real tanThetaX = tanThetaY * aspect;
+
+		Ogre::Real half_w,half_h;
+		half_w = w / 2.0;
+		half_h = h / 2.0;
+
+		Ogre::Real iw = 1.0 / half_w;
+		Ogre::Real ih = 1.0 / half_h;
+		Ogre::Real q;
+		if (farPlane == 0)
+		{
+			q = 0;
+		}
+		else
+		{
+			q = 2.0 / (farPlane - nearPlane);
+		}
+		mCustomProjMatrix = Ogre::Matrix4::ZERO;
+		mCustomProjMatrix[0][0] = iw;
+		mCustomProjMatrix[1][1] = ih;
+		mCustomProjMatrix[2][2] = -q;
+		mCustomProjMatrix[2][3] = - (farPlane + nearPlane)/(farPlane - nearPlane);
+		mCustomProjMatrix[3][3] = 1;	
+	}
+	else
+	{
+		Ogre::Radian thetaY (fovy / 2.0f);
+		Ogre::Real tanThetaY = Ogre::Math::Tan(thetaY);
+
+		//Real thetaX = thetaY * aspect;
+		Ogre::Real tanThetaX = tanThetaY * aspect; //Math::Tan(thetaX);
+		Ogre::Real half_w = w / 2;
+		Ogre::Real half_h = h / 2;
+		Ogre::Real iw = 1.0 / half_w;
+		Ogre::Real ih = 1.0 / half_h;
+		Ogre::Real q;
+		if (farPlane == 0)
+		{
+			q = 0;
+		}
+		else
+		{
+			q = 1.0 / (farPlane - nearPlane);
+		}
+
+		mCustomProjMatrix = Ogre::Matrix4::ZERO;
+		mCustomProjMatrix[0][0] = iw;
+		mCustomProjMatrix[1][1] = ih;
+		mCustomProjMatrix[2][2] = q;
+		mCustomProjMatrix[2][3] = -nearPlane / (farPlane - nearPlane);
+		mCustomProjMatrix[3][3] = 1;
+
+		mCustomProjMatrix[2][2] = -mCustomProjMatrix[2][2];
+	}	
+}
+
+void BillboardCloudIndirectTextureViewMode::saveTextureAtlas()
+{
+	if (mBitRange == 32)
+	{
+		mDestPixelFormat = Ogre::PF_FLOAT32_RGBA;
+	}
+	else if (mBitRange == 16)
+	{
+		mDestPixelFormat = Ogre::PF_FLOAT16_RGBA;
+	}
+	else  // mBitRange == 8
+	{
+		mDestPixelFormat = Ogre::PF_BYTE_RGBA;
+	}
+
+	Ogre::String textureAtlasFileName = BBC::Util::getBaseName(mTextureAtlasName) + Ogre::StringConverter::toString(mCurrentBillboardGroup) + "." + BBC::Util::getExtensionName(mTextureAtlasName);
+	mTextureAtlas->save(mTextureAtlasFolder, textureAtlasFileName, mDestPixelFormat);
+}
+
+void BillboardCloudIndirectTextureViewMode::configureTexture()
+{
+	mTextureAtlas->getRectangle2D()->setVisible(false);
+
+	//mClusterTexture->getRectangle2D()->setVisible(true);
+	//mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("customNormalMap128x128.png");
+	//mClusterTexture->setCorners(-1.0, 1.0, 1.0, -1.0);
+
+	mBillboardCloudPointClusters->getSubEntity((mCurrentTexture-1) % mBillboardCloudPointClusters->getNumSubEntities())->setVisible(false);
+	mBillboardCloudPointClusters->getSubEntity(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->setVisible(true);
+
+	configureBillboardOrthogonalAlignedCamera(mCurrentTexture % mBillboardCloudSplitted->getNumSubEntities());
+	mCamera->setCustomProjectionMatrix(true,mCustomProjMatrix);
+
+	Ogre::GpuProgramParametersSharedPtr fragParams;
+	
+	fragParams = mBillboardCloudPointClusters->getSubEntity(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
+	fragParams->setNamedConstant("textureSize", (Ogre::Real)mTextureSize);
+	mBillboardCloudPointClusters->getSubEntity(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->getMaterial()->reload();
+	
+	if (mDebugTextureAtlasGeneration)
+	{
+		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0));
+		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setDiffuse(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), 1.0);
+	}
+}
+
+void BillboardCloudIndirectTextureViewMode::generateTexture()
+{
+	configureTexture();
+	
+	mClusterTexture->update();	
+	//mClusterTexture->debug();
+}
+
+void BillboardCloudIndirectTextureViewMode::setEntityClustersGroupedName(Ogre::String entityClustersGroupedName)
+{
+	mEntityClustersGroupedName = entityClustersGroupedName;
+}
+
+void BillboardCloudIndirectTextureViewMode::initializeEntityClustersGrouped()
+{
+	if (mFrame == 1)
+	{
+		for (unsigned int iSubEntity = 0; iSubEntity < mBillboardCloudPointClusters->getNumSubEntities(); iSubEntity++)
+		{
+			mEntityClustersGrouped->getSubEntity(iSubEntity)->setVisible(false);
+		}
+	}
+}
+
+void BillboardCloudIndirectTextureViewMode::initializeBillboardCloudPointClusters()
+{
+	if (mFrame == 1)
+	{
+		for (unsigned int iSubEntity = 0; iSubEntity < mBillboardCloudPointClusters->getNumSubEntities(); iSubEntity++)
+		{
+			mBillboardCloudPointClusters->getSubEntity(iSubEntity)->setVisible(false);
+		}
+	}
+}
+
+void BillboardCloudIndirectTextureViewMode::initializeBillboardCloudSplitted()
+{
+	if (mFrame == 1)
+	{
+		for (unsigned int iSubEntity = 0; iSubEntity < mBillboardCloudSplitted->getNumSubEntities(); iSubEntity++)
+		{
+			mBillboardCloudSplitted->getSubEntity(iSubEntity)->setVisible(false);
+		}
+	}
+}
+
+bool BillboardCloudIndirectTextureViewMode::processUnbufferedKeyInput(const Ogre::FrameEvent& evt)
+{
+	if (mInputDevice->isKeyDown(Ogre::KC_SPACE))
+    {
+        mCurrentTexture++;
+    }
+
+	return OgreFrameListenerMode::processUnbufferedKeyInput(evt);
+}
+
+void BillboardCloudIndirectTextureViewMode::configureTextureAtlas()
+{
+	mBillboardCloudPointClusters->getSubEntity(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->setVisible(false);
+
+	mTextureAtlas->getRectangle2D()->setVisible(true);
+
+ 	Ogre::Vector2 uvMapMax = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMax(0);
+	Ogre::Vector2 uvMapMin = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMin(0);
+
+	mClusterTexture->setCorners(uvMapMin[0], uvMapMax[1], uvMapMax[0], uvMapMin[1]);
+	mClusterTexture->getRectangle2D()->setVisible(true);
+	//mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(mClusterTexture->getTextureName());
+}
+
+void BillboardCloudIndirectTextureViewMode::generateTextureAtlas()
+{	
+	configureTextureAtlas();
+
+	mTextureAtlas->update();		
+	//mTextureAtlas->debug();
+	
+	mClusterTexture->getRectangle2D()->setVisible(false);
+}
+
+bool BillboardCloudIndirectTextureViewMode::frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader)
+{
+	initializeEntityClustersGrouped();
+    initializeBillboardCloudSplitted();
+	initializeBillboardCloudPointClusters();
+
+	if (mFrame > 1)
+	{		
+		if (!mDebugBillboardGeneration)
+		{
+			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0));
+
+			if (mCurrentTexture < mNumTextures)
+			{
+				generateTexture();
+
+				generateTextureAtlas();
+
+				mCurrentTexture++;
+				mCurrentBillboard++;
+
+				unsigned int numBillboardsCurrentGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboardGroup(mCurrentBillboardGroup)->getNumBillboards();
+
+				if (mCurrentBillboard == numBillboardsCurrentGroups)
+				{
+					saveTextureAtlas();
+					
+					unsigned int numBillboardGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getNumBillboardGroups();
+
+					if (mCurrentBillboardGroup < numBillboardGroups)
+					{
+						mCurrentBillboard = 0;
+						mCurrentBillboardGroup++;						
+
+						mTextureAtlas->getRectangle2D()->setVisible(false);
+						mTextureAtlas->update();
+						//mTextureAtlas->debug();
+					}
+				}
+			}
+
+			if (mCurrentTexture == mNumTextures)
+			{				
+				mDebugBillboardGeneration = true;
+
+				mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
+
+				mTextureAtlas->getRectangle2D()->setVisible(false);
+
+				mCurrentTexture = 0;
+			}
+		}
+		else
+		{
+			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
+
+			configureBillboard();
+
+			configureTexture();
+
+			mCurrentTexture = mCurrentTexture % mNumTextures;
+		}
+	}
+
+	mFrame++;
+
+	return OgreFrameListenerMode::frameStarted(evt, inputReader);	
+}
+
+void BillboardCloudIndirectTextureViewMode::configureBillboard()
+{
+	mEntityClustersGrouped->getSubEntity((mCurrentTexture-1) % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
+	mEntityClustersGrouped->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(true);
+	mBillboardCloudSplitted->getSubEntity((mCurrentTexture-1) % mBillboardCloudPointClusters->getNumSubEntities())->setVisible(false);
+	mBillboardCloudSplitted->getSubEntity(mCurrentTexture % mBillboardCloudPointClusters->getNumSubEntities())->setVisible(true);
+}
+
+void BillboardCloudIndirectTextureViewMode::setTextureAtlasSize(unsigned int size)
+{
+	mTextureAtlasSize = size;
+}
+
+void BillboardCloudIndirectTextureViewMode::setBillboardCloudPointClustersName(Ogre::String billboardCloudPointClustersName)
+{
+	mBillboardCloudPointClustersName = billboardCloudPointClustersName;
+}
+
+void BillboardCloudIndirectTextureViewMode::setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName)
+{
+	mBillboardCloudSplittedName = billboardCloudSplittedName;
+}
+
+void BillboardCloudIndirectTextureViewMode::setTextureAtlasBitRange(unsigned int bitRange)
+{
+	mBitRange = bitRange;
+}
+
+void BillboardCloudIndirectTextureViewMode::setTextureSize(unsigned int size)
+{
+	mTextureSize = size;
+}
+
+void BillboardCloudIndirectTextureViewMode::setTextureAtlasFolder(Ogre::String textureAtlasFolder)
+{
+	mTextureAtlasFolder = textureAtlasFolder;
+}
+
+void BillboardCloudIndirectTextureViewMode::setTextureAtlasName(Ogre::String textureAtlasName)
+{
+	mTextureAtlasName = textureAtlasName;
+}
+
+void BillboardCloudIndirectTextureViewMode::createScene()
+{
+	if (mBitRange == 32)
+	{
+		mSrcPixelFormat = Ogre::PF_FLOAT32_RGBA;
+	}
+	else if (mBitRange == 16)
+	{
+		mSrcPixelFormat = Ogre::PF_FLOAT16_RGBA;
+	}
+	else  // mBitRange == 8
+	{
+		mSrcPixelFormat = Ogre::PF_A8R8G8B8;
+	}
+
+	LBBC::Leaves *mLeaves = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves();
+	Ogre::Vector2 uvMapMax = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMax(0);
+	Ogre::Vector2 uvMapMin = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMin(0);
+
+	mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0)); 
+
+	mBillboardCloudPointClustersSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+	mBillboardCloudSplittedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+
+	mBillboardCloudPointClusters = mSceneMgr->createEntity(mBillboardCloudPointClustersName, mBillboardCloudPointClustersName);
+    mBillboardCloudPointClustersSceneNode->attachObject(mBillboardCloudPointClusters);
+
+	mBillboardCloudSplitted = mSceneMgr->createEntity(mBillboardCloudSplittedName, mBillboardCloudSplittedName);
+    mBillboardCloudSplittedSceneNode->attachObject(mBillboardCloudSplitted);
+
+	mEntityClustersGroupedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+	mEntityClustersGrouped = mSceneMgr->createEntity(mEntityClustersGroupedName, mEntityClustersGroupedName);
+    mEntityClustersGroupedSceneNode->attachObject(mEntityClustersGrouped);
+
+	mTextureAtlas = IMG::TextureAtlasPtr( new IMG::TextureAtlas() );
+	mTextureAtlas->create("IndirectTextureAtlas", mTextureAtlasSize, mTextureAtlasSize, mSrcPixelFormat, mCamera, Ogre::ColourValue(0.0, 0.0, 0.0));
+	mTextureAtlas->setTextureAtlasSceneNode(mBillboardCloudPointClustersSceneNode);
+	Ogre::MaterialPtr materialPtr1 = Ogre::MaterialManager::getSingleton().create("IndirectTextureAtlasMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);		
+	materialPtr1->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
+	materialPtr1->getTechnique(0)->getPass(0)->createTextureUnitState("transparent.png");
+	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
+	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
+	materialPtr1->getTechnique(0)->getPass(0)->setLightingEnabled(false);
+	mTextureAtlas->setMaterial(materialPtr1.getPointer());
+	mTextureAtlas->setCorners(-1.0, 1.0, 1.0, -1.0);	
+
+	mClusterTexture = IMG::TexturePtr( new IMG::Texture() );
+	mClusterTexture->create("ClusterIndirectTexture", mTextureSize, mTextureSize, mSrcPixelFormat, mCamera, Ogre::ColourValue(0.0, 0.0, 0.0));
+	Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().create("IndirectTextureMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);			
+	if (!mDebugTextureAtlasGeneration)
+	{
+		materialPtr->getTechnique(0)->getPass(0)->createTextureUnitState("customNormalMap128x128.png", 0);
+		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
+		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);		
+
+		materialPtr->getTechnique(0)->createPass();
+		materialPtr->getTechnique(0)->getPass(1)->setSceneBlending(Ogre::SBT_ADD);
+		materialPtr->getTechnique(0)->getPass(1)->setDepthWriteEnabled(false);
+
+		materialPtr->getTechnique(0)->getPass(1)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
+		materialPtr->getTechnique(0)->getPass(1)->createTextureUnitState("ClusterIndirectTexture", 0);
+		materialPtr->getTechnique(0)->getPass(1)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
+		materialPtr->getTechnique(0)->getPass(1)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);		
+
+		materialPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
+	}
+
+	mClusterTexture->setMaterial(materialPtr.getPointer());
+
+	mTextureAtlas->addTexture(mClusterTexture);
+
+	mNumTextures = mBillboardCloudPointClusters->getNumSubEntities();
+	mCurrentTexture = 0;
+}
+
+void BillboardCloudIndirectTextureViewMode::destroyScene()
+{
+	
+}
+
+}
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeApplication.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeApplication.cpp	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/IBRBillboardCloudTreeApplication.cpp	(revision 778)
@@ -147,4 +147,5 @@
 	mSceneMgr = mFrameListener->getEnabledFrameListenerMode()->getSceneManager();	
 
+	if (mSampleConfigFile->getBillboardCloudDiffuseColorEntityTextureAtlasGeneration())
 	{
 		LBBC::EntityTextureAtlasViewMode *textureAtlasFrameListenerMode;
@@ -164,7 +165,8 @@
 	}
 
-	{
-		LBBC::BillboardCloudTextureViewMode *anotherFrameListenerMode;
-		anotherFrameListenerMode = new LBBC::BillboardCloudTextureViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
+	if (mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasGeneration())
+	{
+		LBBC::BillboardCloudDiffuseColorTextureViewMode *anotherFrameListenerMode;
+		anotherFrameListenerMode = new LBBC::BillboardCloudDiffuseColorTextureViewMode(mWindow,mFrameListener->getNumFrameListenerModes());
 		anotherFrameListenerMode->chooseSceneManager();
 		anotherFrameListenerMode->createCamera();
@@ -177,7 +179,26 @@
 		anotherFrameListenerMode->setTextureAtlasFolder(mSampleConfigFile->getBillboardCloudFolder());
 		anotherFrameListenerMode->setEntityClustersGroupedName(mSampleConfigFile->getEntityClustersGroupedMeshName());
-		//anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudSplittedMeshName());
-		anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudIndirectPointMeshName());
+		anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudSplittedMeshName());
 		anotherFrameListenerMode->setBillboardCloudGroupedTextureAtlasDebug(mSampleConfigFile->getBillboardCloudDiffuseColorGroupedBillboardsTextureAtlasDebug());
+		anotherFrameListenerMode->createScene();
+		mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
+	}
+
+	if (mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasGeneration())
+	{
+		LBBC::BillboardCloudIndirectTextureViewMode *anotherFrameListenerMode;
+		anotherFrameListenerMode = new LBBC::BillboardCloudIndirectTextureViewMode(mWindow, mFrameListener->getNumFrameListenerModes());
+		anotherFrameListenerMode->chooseSceneManager();
+		anotherFrameListenerMode->createCamera();
+		anotherFrameListenerMode->createViewports();
+		anotherFrameListenerMode->setTextureAtlasSize(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasSize());
+		anotherFrameListenerMode->setTextureSize(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureSize());
+		anotherFrameListenerMode->setTextureAtlasBitRange(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasBitRange());
+		anotherFrameListenerMode->setTextureAtlasName(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasName());
+		anotherFrameListenerMode->setTextureAtlasFolder(mSampleConfigFile->getBillboardCloudFolder());
+		anotherFrameListenerMode->setBillboardCloudPointClustersName(mSampleConfigFile->getBillboardCloudIndirectPointMeshName());
+		anotherFrameListenerMode->setBillboardCloudSplittedName(mSampleConfigFile->getBillboardCloudSplittedMeshName());
+		anotherFrameListenerMode->setEntityClustersGroupedName(mSampleConfigFile->getEntityClustersGroupedMeshName());
+		anotherFrameListenerMode->setBillboardCloudGroupedTextureAtlasDebug(mSampleConfigFile->getBillboardCloudIndirectGroupedBillboardsTextureAtlasDebug());
 		anotherFrameListenerMode->createScene();
 		mFrameListener->addFrameListenerMode(anotherFrameListenerMode);
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCBillboardCloudUVMapper.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCBillboardCloudUVMapper.cpp	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/BBCBillboardCloudUVMapper.cpp	(revision 778)
@@ -152,15 +152,28 @@
 	Ogre::Vector2 texCoords01,texCoords02,texCoords03,texCoords04;
 
+	// DirectX working version...
+	texCoords03[0] = min[0] / mTextureAtlasWidth;
+	texCoords03[1] = 1.0 - (min[1] / mTextureAtlasHeight);
+
+	texCoords04[0] = max[0] / mTextureAtlasWidth;
+	texCoords04[1] = 1.0 - (min[1] / mTextureAtlasHeight);
+
+	texCoords01[0] = max[0] / mTextureAtlasWidth;
+	texCoords01[1] = 1.0 - (max[1] / mTextureAtlasHeight);
+
 	texCoords02[0] = min[0] / mTextureAtlasWidth;
-	texCoords02[1] = 1.0 - (min[1] / mTextureAtlasHeight);
-
-	texCoords01[0] = max[0] / mTextureAtlasWidth;
-	texCoords01[1] = 1.0 - (min[1] / mTextureAtlasHeight);
-
-	texCoords04[0] = max[0] / mTextureAtlasWidth;
-	texCoords04[1] = 1.0 - (max[1] / mTextureAtlasHeight);
-
-	texCoords03[0] = min[0] / mTextureAtlasWidth;
-	texCoords03[1] = 1.0 - (max[1] / mTextureAtlasHeight);
+	texCoords02[1] = 1.0 - (max[1] / mTextureAtlasHeight);
+
+	//texCoords02[0] = min[0] / mTextureAtlasWidth;
+	//texCoords02[1] = 1.0 - (min[1] / mTextureAtlasHeight);
+
+	//texCoords01[0] = max[0] / mTextureAtlasWidth;
+	//texCoords01[1] = 1.0 - (min[1] / mTextureAtlasHeight);
+
+	//texCoords04[0] = max[0] / mTextureAtlasWidth;
+	//texCoords04[1] = 1.0 - (max[1] / mTextureAtlasHeight);
+
+	//texCoords03[0] = min[0] / mTextureAtlasWidth;
+	//texCoords03[1] = 1.0 - (max[1] / mTextureAtlasHeight);
 	
 	if (groupedBillboards)
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudDiffuseColorTextureViewMode.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudDiffuseColorTextureViewMode.cpp	(revision 778)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudDiffuseColorTextureViewMode.cpp	(revision 778)
@@ -0,0 +1,438 @@
+
+#include "LBBCBillboardCloudDiffuseColorTextureViewMode.h"
+#include "LBBCLeaves.h"
+#include "LBBCManager.h"
+
+namespace LBBC {
+
+BillboardCloudDiffuseColorTextureViewMode::BillboardCloudDiffuseColorTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys, bool useBufferedInputMouse)
+:OBA::OgreFrameListenerMode(win, ogreFrameListenerModeHandle, useBufferedInputKeys, useBufferedInputMouse)
+{	
+	mFrame = 0;
+	mCurrentBillboardGroup = 0;
+	mCurrentBillboard = 0;
+	showDebugOverlay(false);
+	mDebugBillboardGeneration = false;
+	mDebugTextureAtlasGeneration = false;
+}
+
+BillboardCloudDiffuseColorTextureViewMode::~BillboardCloudDiffuseColorTextureViewMode()
+{
+
+}
+
+
+void BillboardCloudDiffuseColorTextureViewMode::setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration)
+{
+	mDebugTextureAtlasGeneration = debugTextureAtlasGeneration;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard)
+{
+	BBC::BillboardPtr billboardPtr = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(iBillboard);
+	Ogre::Vector3 vTopLeft = billboardPtr->getBillboardClusterData()->getQuadTopLeftCorner();
+	Ogre::Vector3 vTopRight = billboardPtr->getBillboardClusterData()->getQuadTopRightCorner();
+	Ogre::Vector3 vBottomLeft = billboardPtr->getBillboardClusterData()->getQuadBottomLeftCorner();
+	Ogre::Vector3 vBottomRight = billboardPtr->getBillboardClusterData()->getQuadBottomRightCorner();
+
+	Ogre::Vector3 vMidPoint = vTopLeft.midPoint(vBottomRight);
+	Ogre::Vector3 vWidth(vTopRight - vTopLeft);
+	Ogre::Vector3 vHeight(vBottomLeft - vTopLeft);
+
+	Ogre::Real w = vWidth.length();
+	Ogre::Real h = vHeight.length();
+	Ogre::Real aspect = w / h;
+	Ogre::Radian fovy = Ogre::Radian(Ogre::Degree(90.0));
+	Ogre::Real nearPlane =	h / Ogre::Math::Tan(fovy/2.0,false);
+	Ogre::Real farPlane = 100000;
+
+	Ogre::Vector3 vUp = vTopLeft - vBottomLeft;
+	vUp.normalise();
+
+	Ogre::Vector3 vI(vTopRight-vTopLeft);
+	vI.normalise();
+
+	Ogre::Vector3 vJ(vBottomLeft-vTopLeft);
+	vJ.normalise();
+
+	Ogre::Vector3 vDir = -vI.crossProduct(vJ);
+	vDir.normalise();
+
+	Ogre::Vector3 vRight = vDir.crossProduct(vUp);
+	vRight.normalise();	
+
+	Ogre::Quaternion qOrientation(vRight, vUp, -vDir);
+	
+	mCamera->setNearClipDistance(nearPlane);
+	mCamera->setOrientation(qOrientation);
+	mCamera->setPosition(vMidPoint - (vDir * (nearPlane*nearPlane)));
+
+	if (Ogre::Root::getSingleton().getRenderSystem()->getName() != "Direct3D9 Rendering SubSystem")
+	{
+		Ogre::Radian thetaY (fovy / 2.0f);
+		Ogre::Real tanThetaY = Ogre::Math::Tan(thetaY);
+
+		Ogre::Real tanThetaX = tanThetaY * aspect;
+
+		Ogre::Real half_w,half_h;
+		half_w = w / 2.0;
+		half_h = h / 2.0;
+
+		Ogre::Real iw = 1.0 / half_w;
+		Ogre::Real ih = 1.0 / half_h;
+		Ogre::Real q;
+		if (farPlane == 0)
+		{
+			q = 0;
+		}
+		else
+		{
+			q = 2.0 / (farPlane - nearPlane);
+		}
+		mCustomProjMatrix = Ogre::Matrix4::ZERO;
+		mCustomProjMatrix[0][0] = iw;
+		mCustomProjMatrix[1][1] = ih;
+		mCustomProjMatrix[2][2] = -q;
+		mCustomProjMatrix[2][3] = - (farPlane + nearPlane)/(farPlane - nearPlane);
+		mCustomProjMatrix[3][3] = 1;	
+	}
+	else
+	{
+		Ogre::Radian thetaY (fovy / 2.0f);
+		Ogre::Real tanThetaY = Ogre::Math::Tan(thetaY);
+
+		//Real thetaX = thetaY * aspect;
+		Ogre::Real tanThetaX = tanThetaY * aspect; //Math::Tan(thetaX);
+		Ogre::Real half_w = w / 2;
+		Ogre::Real half_h = h / 2;
+		Ogre::Real iw = 1.0 / half_w;
+		Ogre::Real ih = 1.0 / half_h;
+		Ogre::Real q;
+		if (farPlane == 0)
+		{
+			q = 0;
+		}
+		else
+		{
+			q = 1.0 / (farPlane - nearPlane);
+		}
+
+		mCustomProjMatrix = Ogre::Matrix4::ZERO;
+		mCustomProjMatrix[0][0] = iw;
+		mCustomProjMatrix[1][1] = ih;
+		mCustomProjMatrix[2][2] = q;
+		mCustomProjMatrix[2][3] = -nearPlane / (farPlane - nearPlane);
+		mCustomProjMatrix[3][3] = 1;
+
+		mCustomProjMatrix[2][2] = -mCustomProjMatrix[2][2];
+	}
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::saveTextureAtlas()
+{
+	if (mBitRange == 32)
+	{
+		mDestPixelFormat = Ogre::PF_FLOAT32_RGBA;
+	}
+	else if (mBitRange == 16)
+	{
+		mDestPixelFormat = Ogre::PF_FLOAT16_RGBA;
+	}
+	else  // mBitRange == 8
+	{
+		mDestPixelFormat = Ogre::PF_BYTE_RGBA;
+	}
+
+	Ogre::String textureAtlasFileName = BBC::Util::getBaseName(mTextureAtlasName) + Ogre::StringConverter::toString(mCurrentBillboardGroup) + "." + BBC::Util::getExtensionName(mTextureAtlasName);
+	mTextureAtlas->save(mTextureAtlasFolder, textureAtlasFileName, mDestPixelFormat);
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::disableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped)
+{
+	//mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setVertexProgram("");
+	//mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setFragmentProgram("");
+	//mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->reload();
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::enableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped)
+{
+	//mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setVertexProgram("diffuseTextureScreenAligned_VP20");
+	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setFragmentProgram("diffuseTextureScreenAligned_FP20");
+
+	//Ogre::GpuProgramParametersSharedPtr vertParams;
+	//Ogre::GpuProgramParametersSharedPtr fragParams;
+	//vertParams = mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->getVertexProgramParameters();
+	//fragParams = mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
+
+	//vertParams->setNamedConstant("projectionmatrix", mCamera->getProjectionMatrixWithRSDepth());
+	//vertParams->setNamedAutoConstant("worldmatrix", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
+	//vertParams->setNamedAutoConstant("viewmatrix", Ogre::GpuProgramParameters::ACT_VIEW_MATRIX);
+	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->reload();
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::configureTexture()
+{
+	mTextureAtlas->getRectangle2D()->setVisible(false);
+	mEntityClustersGrouped->getSubEntity((mCurrentTexture-1) % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
+	mEntityClustersGrouped->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(true);
+
+	configureBillboardOrthogonalAlignedCamera(mCurrentTexture % mBillboardCloudSplitted->getNumSubEntities());
+	mCamera->setCustomProjectionMatrix(true,mCustomProjMatrix);
+
+	if (mDebugTextureAtlasGeneration)
+	{
+		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0));
+		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setDiffuse(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), 1.0);
+	}
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::generateTexture()
+{
+	configureTexture();
+
+	enableEntityClusterCustomOrthogonalCameraMaterial(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities());
+	
+	mClusterTexture->update();		
+
+	disableEntityClusterCustomOrthogonalCameraMaterial(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities());
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::initializeEntityClustersGrouped()
+{
+	if (mFrame == 1)
+	{
+		for (unsigned int iSubEntity = 0; iSubEntity < mEntityClustersGrouped->getNumSubEntities(); iSubEntity++)
+		{
+			mEntityClustersGrouped->getSubEntity(iSubEntity)->setVisible(false);
+		}
+	}
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::initializeBillboardCloudSplitted()
+{
+	if (mFrame == 1)
+	{
+		for (unsigned int iSubEntity = 0; iSubEntity < mBillboardCloudSplitted->getNumSubEntities(); iSubEntity++)
+		{
+			mBillboardCloudSplitted->getSubEntity(iSubEntity)->setVisible(false);
+		}
+	}
+}
+
+bool BillboardCloudDiffuseColorTextureViewMode::processUnbufferedKeyInput(const Ogre::FrameEvent& evt)
+{
+	if (mInputDevice->isKeyDown(Ogre::KC_SPACE))
+    {
+        mCurrentTexture++;
+    }
+
+	return OgreFrameListenerMode::processUnbufferedKeyInput(evt);
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::configureTextureAtlas()
+{
+	mEntityClustersGrouped->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
+
+	mClusterTexture->getRectangle2D()->setVisible(true);
+	mTextureAtlas->getRectangle2D()->setVisible(true);
+
+ 	Ogre::Vector2 uvMapMax = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMax(0);
+	Ogre::Vector2 uvMapMin = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMin(0);
+
+	mClusterTexture->setCorners(uvMapMin[0], uvMapMax[1], uvMapMax[0], uvMapMin[1]);
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::generateTextureAtlas()
+{	
+	configureTextureAtlas();
+
+	mTextureAtlas->update();		
+	//mTextureAtlas->debug();
+	
+	mClusterTexture->getRectangle2D()->setVisible(false);
+}
+
+bool BillboardCloudDiffuseColorTextureViewMode::frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader)
+{
+	initializeEntityClustersGrouped();
+    initializeBillboardCloudSplitted();
+
+	if (mFrame > 1)
+	{		
+		if (!mDebugBillboardGeneration)
+		{
+			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0));
+
+			if (mCurrentTexture < mNumTextures)
+			{
+				generateTexture();
+
+				generateTextureAtlas();
+
+				mCurrentTexture++;
+				mCurrentBillboard++;
+
+				unsigned int numBillboardsCurrentGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboardGroup(mCurrentBillboardGroup)->getNumBillboards();
+
+				if (mCurrentBillboard == numBillboardsCurrentGroups)
+				{
+					saveTextureAtlas();
+					
+					unsigned int numBillboardGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getNumBillboardGroups();
+
+					if (mCurrentBillboardGroup < numBillboardGroups)
+					{
+						mCurrentBillboard = 0;
+						mCurrentBillboardGroup++;						
+
+						mTextureAtlas->getRectangle2D()->setVisible(false);
+						mTextureAtlas->update();
+						//mTextureAtlas->debug();
+					}
+				}
+			}
+
+			if (mCurrentTexture == mNumTextures)
+			{				
+				mDebugBillboardGeneration = true;
+
+				mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
+
+				mTextureAtlas->getRectangle2D()->setVisible(false);
+
+				mCurrentTexture = 0;
+			}
+		}
+		else
+		{
+			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
+
+			configureBillboard();
+
+			configureTexture();
+
+			mCurrentTexture = mCurrentTexture % mNumTextures;
+		}
+	}
+
+	mFrame++;
+
+	return OgreFrameListenerMode::frameStarted(evt, inputReader);	
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::configureBillboard()
+{
+	mBillboardCloudSplitted->getSubEntity((mCurrentTexture-1) % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
+	mBillboardCloudSplitted->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(true);
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureAtlasSize(unsigned int size)
+{
+	mTextureAtlasSize = size;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setEntityClustersGroupedName(Ogre::String entityClustersGroupedName)
+{
+	mEntityClustersGroupedName = entityClustersGroupedName;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName)
+{
+	mBillboardCloudSplittedName = billboardCloudSplittedName;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureAtlasBitRange(unsigned int bitRange)
+{
+	mBitRange = bitRange;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureSize(unsigned int size)
+{
+	mTextureSize = size;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureAtlasFolder(Ogre::String textureAtlasFolder)
+{
+	mTextureAtlasFolder = textureAtlasFolder;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureAtlasName(Ogre::String textureAtlasName)
+{
+	mTextureAtlasName = textureAtlasName;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::setTextureName(Ogre::String textureName)
+{
+	mTextureName = textureName;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::createScene()
+{
+	if (mBitRange == 32)
+	{
+		mSrcPixelFormat = Ogre::PF_FLOAT32_RGBA;
+	}
+	else if (mBitRange == 16)
+	{
+		mSrcPixelFormat = Ogre::PF_FLOAT16_RGBA;
+	}
+	else  // mBitRange == 8
+	{
+		mSrcPixelFormat = Ogre::PF_A8R8G8B8;
+	}
+
+	LBBC::Leaves *mLeaves = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves();
+	Ogre::Vector2 uvMapMax = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMax(0);
+	Ogre::Vector2 uvMapMin = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMin(0);
+
+	IMG::TexturePtr texturePtr ( new IMG::Texture() );
+	texturePtr->bind(mTextureName);
+	Ogre::ColourValue avgColour = texturePtr->getAvgColour();
+	mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0)); 
+
+	mEntityClustersGroupedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+	mBillboardCloudSplittedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
+
+	mEntityClustersGrouped = mSceneMgr->createEntity(mEntityClustersGroupedName, mEntityClustersGroupedName);
+    mEntityClustersGroupedSceneNode->attachObject(mEntityClustersGrouped);
+
+	mBillboardCloudSplitted = mSceneMgr->createEntity(mBillboardCloudSplittedName, mBillboardCloudSplittedName);
+    mBillboardCloudSplittedSceneNode->attachObject(mBillboardCloudSplitted);
+
+	mTextureAtlas = IMG::TextureAtlasPtr( new IMG::TextureAtlas() );
+	mTextureAtlas->create("TextureAtlasDiffuseColor", mTextureAtlasSize, mTextureAtlasSize, mSrcPixelFormat, mCamera, avgColour);
+	mTextureAtlas->setTextureAtlasSceneNode(mEntityClustersGroupedSceneNode);
+	Ogre::MaterialPtr materialPtr1 = Ogre::MaterialManager::getSingleton().create("DiffuseColorTextureAtlasMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);		
+	materialPtr1->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
+	materialPtr1->getTechnique(0)->getPass(0)->createTextureUnitState("transparent.png");
+	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
+	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
+	materialPtr1->getTechnique(0)->getPass(0)->setLightingEnabled(false);
+	mTextureAtlas->setMaterial(materialPtr1.getPointer());
+	mTextureAtlas->setCorners(-1.0, 1.0, 1.0, -1.0);	
+
+	mClusterTexture = IMG::TexturePtr( new IMG::Texture() );
+	mClusterTexture->create("ClusterTextureDiffuseColor", mTextureSize, mTextureSize, mSrcPixelFormat, mCamera, avgColour);
+	Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().create("DiffuseColorTextureMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);			
+	if (!mDebugTextureAtlasGeneration)
+	{
+		materialPtr->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
+		materialPtr->getTechnique(0)->getPass(0)->createTextureUnitState("ClusterTextureDiffuseColor", 0);
+		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
+		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);		
+		materialPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
+	}
+	mClusterTexture->setMaterial(materialPtr.getPointer());
+
+	mTextureAtlas->addTexture(mClusterTexture);
+
+	mNumTextures = mEntityClustersGrouped->getNumSubEntities();
+	mCurrentTexture = 0;
+}
+
+void BillboardCloudDiffuseColorTextureViewMode::destroyScene()
+{
+	
+}
+
+}
Index: /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCManager.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCManager.cpp	(revision 751)
+++ /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCManager.cpp	(revision 778)
@@ -497,6 +497,15 @@
 			entity->getSubEntity(numSubEntities)->setMaterialName(mSampleConfigFile->getBillboardCloudIndirectPointMaterialName());
 			entity->getSubEntity(numSubEntities)->enableNormals(false);
-			entity->getSubEntity(numSubEntities)->enableTextureCoords(false);
+			entity->getSubEntity(numSubEntities)->enableTextureCoords(true);
+			entity->getSubEntity(numSubEntities)->addTextureCoordSet(2);
 			entity->getSubEntity(numSubEntities)->enableVertexColours(true);
+
+			Ogre::Vector3 p1, p2, p3, p4, pa, pb;
+			Ogre::Real mua, mub;
+			Ogre::Real height, width;
+			Ogre::Real hDistance, wDistance;
+
+			height = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadBottomLeftCorner()).length();
+			width = Ogre::Vector3(billboard->getBillboardClusterData()->getQuadTopLeftCorner() - billboard->getBillboardClusterData()->getQuadTopRightCorner()).length();
 
 			for (unsigned int iLeaf = 0; iLeaf < entityCluster->getNumEntitiesClusterData(); iLeaf++)
@@ -507,4 +516,41 @@
 				Leaf *leaf = (Leaf*)leafKMeansClusterData->getEntity().get();
 				vertex.position = leaf->getPosition();
+
+				hDistance = 0.0;
+				wDistance = 0.0;
+
+				p1 = billboard->getBillboardClusterData()->getQuadTopRightCorner();
+				p2 = billboard->getBillboardClusterData()->getQuadBottomRightCorner();
+				p3 = leaf->getPosition();
+				p4 = leaf->getPosition() + billboard->getBillboardClusterData()->getAxisY();
+
+				if (BBC::Util::lineLineIntersect(p1, p2, p3, p4, &pa, &pb, &mua, &mub))
+				{
+					hDistance = Ogre::Vector3(pa - p1).length();
+				}
+				else
+				{
+					Ogre::LogManager::getSingleton().logMessage("Error with intersection: no solution exists.");
+				}
+
+				p1 = billboard->getBillboardClusterData()->getQuadTopLeftCorner();
+				p2 = billboard->getBillboardClusterData()->getQuadTopRightCorner();
+				p3 = leaf->getPosition();
+				p4 = leaf->getPosition() + billboard->getBillboardClusterData()->getAxisX();
+
+				if (BBC::Util::lineLineIntersect(p1, p2, p3, p4, &pa, &pb, &mua, &mub))
+				{
+					wDistance = Ogre::Vector3(pa - p2).length();
+				}
+				else
+				{
+					Ogre::LogManager::getSingleton().logMessage("Error with intersection: no solution exists.");
+				}
+
+				//Ogre::LogManager::getSingleton().logMessage("W:" + Ogre::StringConverter::toString(width) + " UW:" + Ogre::StringConverter::toString(wDistance));
+				//Ogre::LogManager::getSingleton().logMessage("H:" + Ogre::StringConverter::toString(height) + " UH:" + Ogre::StringConverter::toString(hDistance));
+
+				//vertex.uv[0] = Ogre::Vector3(wDistance / width, hDistance / height, 0.0);
+				vertex.uv[0] = Ogre::Vector3(1.0 - (hDistance / height), 1.0 - (wDistance / width), 0.0);
 				vertex.colour = Ogre::ColourValue(Ogre::Math::RangeRandom(0.0, 1.0), Ogre::Math::RangeRandom(0.0, 1.0), Ogre::Math::RangeRandom(0.0, 1.0), 1.0).getAsRGBA(); 
 				entity->getSubEntity(numSubEntities)->addUniqueVertex(vertex);
Index: P/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudTextureViewMode.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IBRBillboardCloudTrees/OGRE/src/LBBCBillboardCloudTextureViewMode.cpp	(revision 751)
+++ 	(revision )
@@ -1,412 +1,0 @@
-
-#include "LBBCBillboardCloudTextureViewMode.h"
-#include "LBBCLeaves.h"
-#include "LBBCManager.h"
-
-namespace LBBC {
-
-BillboardCloudTextureViewMode::BillboardCloudTextureViewMode(Ogre::RenderWindow* win, unsigned int ogreFrameListenerModeHandle, bool useBufferedInputKeys, bool useBufferedInputMouse)
-:OBA::OgreFrameListenerMode(win, ogreFrameListenerModeHandle, useBufferedInputKeys, useBufferedInputMouse)
-{	
-	mFrame = 0;
-	mCurrentBillboardGroup = 0;
-	mCurrentBillboard = 0;
-	showDebugOverlay(false);
-	mDebugBillboardGeneration = false;
-	mDebugTextureAtlasGeneration = false;
-}
-
-BillboardCloudTextureViewMode::~BillboardCloudTextureViewMode()
-{
-
-}
-
-
-void BillboardCloudTextureViewMode::setBillboardCloudGroupedTextureAtlasDebug(bool debugTextureAtlasGeneration)
-{
-	mDebugTextureAtlasGeneration = debugTextureAtlasGeneration;
-}
-
-void BillboardCloudTextureViewMode::configureBillboardOrthogonalAlignedCamera(unsigned int iBillboard)
-{
-	BBC::BillboardPtr billboardPtr = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(iBillboard);
-	Ogre::Vector3 vTopLeft = billboardPtr->getBillboardClusterData()->getQuadTopLeftCorner();
-	Ogre::Vector3 vTopRight = billboardPtr->getBillboardClusterData()->getQuadTopRightCorner();
-	Ogre::Vector3 vBottomLeft = billboardPtr->getBillboardClusterData()->getQuadBottomLeftCorner();
-	Ogre::Vector3 vBottomRight = billboardPtr->getBillboardClusterData()->getQuadBottomRightCorner();
-
-	Ogre::Vector3 vMidPoint = vTopLeft.midPoint(vBottomRight);
-	Ogre::Vector3 vWidth(vTopRight - vTopLeft);
-	Ogre::Vector3 vHeight(vBottomLeft - vTopLeft);
-
-	Ogre::Real w = vWidth.length();
-	Ogre::Real h = vHeight.length();
-	Ogre::Real aspect = w / h;
-	Ogre::Radian fovy = Ogre::Radian(Ogre::Degree(90.0));
-	Ogre::Real nearPlane =	h / Ogre::Math::Tan(fovy/2.0,false);
-	Ogre::Real farPlane = 100000;
-
-	Ogre::Vector3 vUp = vTopLeft - vBottomLeft;
-	vUp.normalise();
-
-	Ogre::Vector3 vI(vTopRight-vTopLeft);
-	vI.normalise();
-
-	Ogre::Vector3 vJ(vBottomLeft-vTopLeft);
-	vJ.normalise();
-
-	Ogre::Vector3 vDir = -vI.crossProduct(vJ);
-	vDir.normalise();
-
-	Ogre::Vector3 vRight = vDir.crossProduct(vUp);
-	vRight.normalise();	
-
-	Ogre::Quaternion qOrientation(vRight, vUp, -vDir);
-	
-	mCamera->setNearClipDistance(nearPlane);
-	mCamera->setOrientation(qOrientation);
-	mCamera->setPosition(vMidPoint - (vDir * (nearPlane*nearPlane)));
-
-	Ogre::Radian thetaY (fovy / 2.0f);
-	Ogre::Real tanThetaY = Ogre::Math::Tan(thetaY);
-
-	Ogre::Real tanThetaX = tanThetaY * aspect;
-
-	Ogre::Real half_w,half_h;
-	half_w = w / 2.0;
-	half_h = h / 2.0;
-
-	Ogre::Real iw = 1.0 / half_w;
-	Ogre::Real ih = 1.0 / half_h;
-	Ogre::Real q;
-	if (farPlane == 0)
-	{
-		q = 0;
-	}
-	else
-	{
-		q = 2.0 / (farPlane - nearPlane);
-	}
-	mCustomProjMatrix = Ogre::Matrix4::ZERO;
-	mCustomProjMatrix[0][0] = iw;
-	mCustomProjMatrix[1][1] = ih;
-	mCustomProjMatrix[2][2] = -q;
-	mCustomProjMatrix[2][3] = - (farPlane + nearPlane)/(farPlane - nearPlane);
-	mCustomProjMatrix[3][3] = 1;	
-}
-
-void BillboardCloudTextureViewMode::saveTextureAtlas()
-{
-	if (mBitRange == 32)
-	{
-		mDestPixelFormat = Ogre::PF_FLOAT32_RGBA;
-	}
-	else if (mBitRange == 16)
-	{
-		mDestPixelFormat = Ogre::PF_FLOAT16_RGBA;
-	}
-	else  // mBitRange == 8
-	{
-		mDestPixelFormat = Ogre::PF_BYTE_RGBA;
-	}
-
-	Ogre::String textureAtlasFileName = BBC::Util::getBaseName(mTextureAtlasName) + Ogre::StringConverter::toString(mCurrentBillboardGroup) + "." + BBC::Util::getExtensionName(mTextureAtlasName);
-	mTextureAtlas->save(mTextureAtlasFolder, textureAtlasFileName, mDestPixelFormat);
-}
-
-void BillboardCloudTextureViewMode::disableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped)
-{
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setVertexProgram("");
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setFragmentProgram("");
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->reload();
-}
-
-void BillboardCloudTextureViewMode::enableEntityClusterCustomOrthogonalCameraMaterial(unsigned int iEntityClusterGrouped)
-{
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setVertexProgram("diffuseTextureVP");
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->setFragmentProgram("diffuseTextureFP");
-
-	Ogre::GpuProgramParametersSharedPtr vertParams;
-	Ogre::GpuProgramParametersSharedPtr fragParams;
-	vertParams = mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->getVertexProgramParameters();
-	fragParams = mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
-
-	vertParams->setNamedConstant("projectionmatrix", mCamera->getProjectionMatrixWithRSDepth());
-	vertParams->setNamedAutoConstant("worldmatrix", Ogre::GpuProgramParameters::ACT_WORLD_MATRIX);
-	vertParams->setNamedAutoConstant("viewmatrix", Ogre::GpuProgramParameters::ACT_VIEW_MATRIX);
-	mEntityClustersGrouped->getSubEntity(iEntityClusterGrouped)->getMaterial()->reload();
-}
-
-void BillboardCloudTextureViewMode::configureTexture()
-{
-	mTextureAtlas->getRectangle2D()->setVisible(false);
-	mEntityClustersGrouped->getSubEntity((mCurrentTexture-1) % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
-	mEntityClustersGrouped->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(true);
-
-	configureBillboardOrthogonalAlignedCamera(mCurrentTexture % mBillboardCloudSplitted->getNumSubEntities());
-	mCamera->setCustomProjectionMatrix(true,mCustomProjMatrix);
-
-	if (mDebugTextureAtlasGeneration)
-	{
-		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setAmbient(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0));
-		mClusterTexture->getMaterial()->getTechnique(0)->getPass(0)->setDiffuse(Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), Ogre::Math::RangeRandom(0.0,1.0), 1.0);
-	}
-}
-
-void BillboardCloudTextureViewMode::generateTexture()
-{
-	configureTexture();
-
-	enableEntityClusterCustomOrthogonalCameraMaterial(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities());
-	
-	mClusterTexture->update();		
-
-	disableEntityClusterCustomOrthogonalCameraMaterial(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities());
-}
-
-void BillboardCloudTextureViewMode::initializeEntityClustersGrouped()
-{
-	if (mFrame == 1)
-	{
-		for (unsigned int iSubEntity = 0; iSubEntity < mEntityClustersGrouped->getNumSubEntities(); iSubEntity++)
-		{
-			mEntityClustersGrouped->getSubEntity(iSubEntity)->setVisible(false);
-		}
-	}
-}
-
-void BillboardCloudTextureViewMode::initializeBillboardCloudSplitted()
-{
-	if (mFrame == 1)
-	{
-		for (unsigned int iSubEntity = 0; iSubEntity < mBillboardCloudSplitted->getNumSubEntities(); iSubEntity++)
-		{
-			mBillboardCloudSplitted->getSubEntity(iSubEntity)->setVisible(false);
-		}
-	}
-}
-
-bool BillboardCloudTextureViewMode::processUnbufferedKeyInput(const Ogre::FrameEvent& evt)
-{
-	if (mInputDevice->isKeyDown(Ogre::KC_SPACE))
-    {
-        mCurrentTexture++;
-    }
-
-	return OgreFrameListenerMode::processUnbufferedKeyInput(evt);
-}
-
-void BillboardCloudTextureViewMode::configureTextureAtlas()
-{
-	mEntityClustersGrouped->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
-
-	mClusterTexture->getRectangle2D()->setVisible(true);
-	mTextureAtlas->getRectangle2D()->setVisible(true);
-
- 	Ogre::Vector2 uvMapMax = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMax(0);
-	Ogre::Vector2 uvMapMin = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboard(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->getBillboardClusterData()->getBillboardUVMapMin(0);
-
-	mClusterTexture->setCorners(uvMapMin[0], uvMapMax[1], uvMapMax[0], uvMapMin[1]);
-}
-
-void BillboardCloudTextureViewMode::generateTextureAtlas()
-{	
-	configureTextureAtlas();
-
-	mTextureAtlas->update();		
-	//mTextureAtlas->debug();
-	
-	mClusterTexture->getRectangle2D()->setVisible(false);
-}
-
-bool BillboardCloudTextureViewMode::frameStarted(const Ogre::FrameEvent& evt, Ogre::InputReader *inputReader)
-{
-	initializeEntityClustersGrouped();
-    initializeBillboardCloudSplitted();
-
-	if (mFrame > 1)
-	{		
-		if (!mDebugBillboardGeneration)
-		{
-			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0));
-
-			if (mCurrentTexture < mNumTextures)
-			{
-				generateTexture();
-
-				generateTextureAtlas();
-
-				mCurrentTexture++;
-				mCurrentBillboard++;
-
-				unsigned int numBillboardsCurrentGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getBillboardGroup(mCurrentBillboardGroup)->getNumBillboards();
-
-				if (mCurrentBillboard == numBillboardsCurrentGroups)
-				{
-					saveTextureAtlas();
-					
-					unsigned int numBillboardGroups = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves()->getBillboardCloud()->getNumBillboardGroups();
-
-					if (mCurrentBillboardGroup < numBillboardGroups)
-					{
-						mCurrentBillboard = 0;
-						mCurrentBillboardGroup++;						
-
-						mTextureAtlas->getRectangle2D()->setVisible(false);
-						mTextureAtlas->update();
-						//mTextureAtlas->debug();
-					}
-				}
-			}
-
-			if (mCurrentTexture == mNumTextures)
-			{				
-				mDebugBillboardGeneration = true;
-
-				mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
-
-				mTextureAtlas->getRectangle2D()->setVisible(false);
-
-				mCurrentTexture = 0;
-			}
-		}
-		else
-		{
-			mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(0.0, 0.0, 0.0, 1.0)); 
-
-			configureBillboard();
-
-			configureTexture();
-
-			mCurrentTexture = mCurrentTexture % mNumTextures;
-		}
-	}
-
-	mFrame++;
-
-	return OgreFrameListenerMode::frameStarted(evt, inputReader);	
-}
-
-void BillboardCloudTextureViewMode::configureBillboard()
-{
-	mBillboardCloudSplitted->getSubEntity((mCurrentTexture-1) % mEntityClustersGrouped->getNumSubEntities())->setVisible(false);
-	mBillboardCloudSplitted->getSubEntity(mCurrentTexture % mEntityClustersGrouped->getNumSubEntities())->setVisible(true);
-}
-
-void BillboardCloudTextureViewMode::setTextureAtlasSize(unsigned int size)
-{
-	mTextureAtlasSize = size;
-}
-
-void BillboardCloudTextureViewMode::setEntityClustersGroupedName(Ogre::String entityClustersGroupedName)
-{
-	mEntityClustersGroupedName = entityClustersGroupedName;
-}
-
-void BillboardCloudTextureViewMode::setBillboardCloudSplittedName(Ogre::String billboardCloudSplittedName)
-{
-	mBillboardCloudSplittedName = billboardCloudSplittedName;
-}
-
-void BillboardCloudTextureViewMode::setTextureAtlasBitRange(unsigned int bitRange)
-{
-	mBitRange = bitRange;
-}
-
-void BillboardCloudTextureViewMode::setTextureSize(unsigned int size)
-{
-	mTextureSize = size;
-}
-
-void BillboardCloudTextureViewMode::setTextureAtlasFolder(Ogre::String textureAtlasFolder)
-{
-	mTextureAtlasFolder = textureAtlasFolder;
-}
-
-void BillboardCloudTextureViewMode::setTextureAtlasName(Ogre::String textureAtlasName)
-{
-	mTextureAtlasName = textureAtlasName;
-}
-
-void BillboardCloudTextureViewMode::setTextureName(Ogre::String textureName)
-{
-	mTextureName = textureName;
-}
-
-void BillboardCloudTextureViewMode::createScene()
-{
-	if (mBitRange == 32)
-	{
-		mSrcPixelFormat = Ogre::PF_FLOAT32_RGBA;
-	}
-	else if (mBitRange == 16)
-	{
-		mSrcPixelFormat = Ogre::PF_FLOAT16_RGBA;
-	}
-	else  // mBitRange == 8
-	{
-		mSrcPixelFormat = Ogre::PF_A8R8G8B8;
-	}
-
-	LBBC::Leaves *mLeaves = ((LBBC::LBBCManager*)LBBC::LBBCManager::getSingletonPtr())->getLeaves();
-	Ogre::Vector2 uvMapMax = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMax(0);
-	Ogre::Vector2 uvMapMin = mLeaves->getBillboardCloud()->getBillboard(0)->getBillboardClusterData()->getBillboardUVMapMin(0);
-
-	IMG::TexturePtr texturePtr ( new IMG::Texture() );
-	texturePtr->bind(mTextureName);
-	Ogre::ColourValue avgColour = texturePtr->getAvgColour();
-	mWindow->getViewport(0)->setBackgroundColour(Ogre::ColourValue(1.0, 1.0, 1.0, 1.0)); 
-
-	mEntityClustersGroupedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
-	mBillboardCloudSplittedSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
-
-	mEntityClustersGrouped = mSceneMgr->createEntity(mEntityClustersGroupedName, mEntityClustersGroupedName);
-    mEntityClustersGroupedSceneNode->attachObject(mEntityClustersGrouped);
-
-	mBillboardCloudSplitted = mSceneMgr->createEntity(mBillboardCloudSplittedName, mBillboardCloudSplittedName);
-    mBillboardCloudSplittedSceneNode->attachObject(mBillboardCloudSplitted);
-
-	mTextureAtlas = IMG::TextureAtlasPtr( new IMG::TextureAtlas() );
-	mTextureAtlas->create("TextureAtlas", mTextureAtlasSize, mTextureAtlasSize, mSrcPixelFormat, mCamera, avgColour);
-	mTextureAtlas->setRenderTargetListener(&mTextureAtlasListener);
-	mTextureAtlas->setTextureAtlasSceneNode(mEntityClustersGroupedSceneNode);
-	Ogre::MaterialPtr materialPtr1 = Ogre::MaterialManager::getSingleton().create("textureAtlasMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);		
-	materialPtr1->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
-	materialPtr1->getTechnique(0)->getPass(0)->createTextureUnitState("transparent.png");
-	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
-	materialPtr1->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
-	materialPtr1->getTechnique(0)->getPass(0)->setLightingEnabled(false);
-	mTextureAtlas->setMaterial(materialPtr1.getPointer());
-	mTextureAtlas->setCorners(-1.0, 1.0, 1.0, -1.0);	
-
-	mClusterTexture = IMG::TexturePtr( new IMG::Texture() );
-	mClusterTexture->create("clusterTexture", mTextureSize, mTextureSize, mSrcPixelFormat, mCamera, avgColour);
-	mClusterTexture->setRenderTargetListener(&mClusterTextureListener);
-	Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().create("textureMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);			
-	if (!mDebugTextureAtlasGeneration)
-	{
-		materialPtr->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 10);
-		materialPtr->getTechnique(0)->getPass(0)->createTextureUnitState("clusterTexture", 0);
-		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);			
-		materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);		
-		materialPtr->getTechnique(0)->getPass(0)->setLightingEnabled(false);
-	}
-	mClusterTexture->setMaterial(materialPtr.getPointer());
-
-	mTextureAtlas->addTexture(mClusterTexture);
-	
-	mClusterTextureListener.setNumTextures(mEntityClustersGrouped->getNumSubEntities());
-	mClusterTextureListener.setTextureAtlas(mTextureAtlas);
-	mClusterTextureListener.setTexture(mClusterTexture);
-	mClusterTextureListener.setEntityClusters(mEntityClustersGrouped);
-
-	mNumTextures = mEntityClustersGrouped->getNumSubEntities();
-	mCurrentTexture = 0;
-}
-
-void BillboardCloudTextureViewMode::destroyScene()
-{
-	
-}
-
-}
