Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h	(revision 1425)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreSharedRuns.h	(revision 1722)
@@ -186,5 +186,7 @@
 	void runChanged(RenderingRunType runType, RenderingRun* run);
 	virtual void addTechniqueGroup(TechniqueGroup* group){childTechniqueGroups.push_back(group);}
-	
+	void setMaterial(String materialName);
+	void restoreMaterial();
+
 protected:
 	/**
@@ -206,4 +208,5 @@
 	*/
 	std::map<OgreRenderable*, bool> renderables; 
+	std::map<OgreRenderable*, String> renderableMaterials;
 	/**
 		@brief the bounding sphere of all the objects connected to this node.
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderingRun.h	(revision 1644)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/OgreRenderingRun.h	(revision 1722)
@@ -32,6 +32,5 @@
 	OgreRenderingRun* asOgreRenderingRun(){return this;}
 
-	virtual bool canJoin(OgreRenderingRun* run){return true;}
-
+	
 protected:
 
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h	(revision 1722)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h	(revision 1722)
@@ -0,0 +1,83 @@
+#pragma once
+
+//disable inheritance warning caused by multiple inheritance
+#if _WIN32
+#if _MSC_VER
+#pragma warning(disable: 4250)
+#endif
+#endif
+
+#include "OgreRenderingRun.h"
+#include "CubeMapRenderingRun.h"
+#include "OgreSharedRuns.h"
+
+
+/**
+	@brief ColorCubeMapRenderingRun used in an OGRE environment.
+*/
+class OgreCubeMapRenderingRun : public OgreRenderingRun,
+								public CubeMapRenderingRun
+{	
+public:
+
+	/**
+		@brief Constructor.
+
+		@param sharedRuns			a pointer to the OgreSharedRuns this run belongs to
+		@param name					the name of the cubemap texture to be created
+		@param startFrame			adds an offset to the current frame number to help evenly distribute updates between frames
+		@param updateInterval		update frequency
+		@param resolution			cubemap resolution
+		@param useDistCalc			flag to skip cube face update if object is far away
+		@param useFaceAngleCalc		flag to skip cube face update if face is neglible
+		@param distTolerance		distance tolerance used in face skip
+		@param angleTolerance		angle tolerance used in face skip		
+		@param updateAllFace		defines if all cubemap faces should be updated in a frame or only one face per frame
+	*/	
+	OgreCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
+								 String name,
+								 unsigned long startFrame,
+								 unsigned long updateInterval,
+								 unsigned int resolution,
+								 bool useDistCalc,
+								 bool useFaceAngleCalc,
+								 float distTolerance,
+								 float angleTolerance,
+								 bool updateAllFace,
+								 bool renderSelf,
+								 bool renderEnvironment,
+								 String selfMaterial,
+								 String environmentMaterial);
+	/**
+		@brief returns the name of the resulting color cubemap texture
+	*/
+	String getCubeMapTextureName(){return name;}
+	
+protected:
+
+	/**
+		@brief a pointer to the OgreSharedRuns this run belongs to
+	*/
+	OgreSharedRuns* sharedRuns;
+	/**
+		@brief the name of the cubemap texture that was created by this run
+	*/
+	String name;
+	/**
+		@brief a pointer to the cubemap texture that was created by this run
+	*/
+	Texture* cubemapTexture;
+	String selfMaterial;
+	bool useSelfMaterial;
+	String environmentMaterial;
+	bool useEnvMaterial;
+
+	
+	
+	//inherited
+	inline void createCubeMap();
+	//inherited
+	inline void updateCubeFace(int facenum);
+	//inherited
+    bool faceNeedsUpdate(int facenum); 	
+};
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h	(revision 1055)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgrePhotonMapRenderingRun.h	(revision 1722)
@@ -48,7 +48,7 @@
 	void refreshLight();
 
-	bool canJoin(OgreRenderingRun* run)
+	bool canJoin(RenderingRun* run)
 	{
-		OgrePhotonMapRenderingRun* r = (OgrePhotonMapRenderingRun*) run;
+		OgrePhotonMapRenderingRun* r = (OgrePhotonMapRenderingRun*) run->asOgreRenderingRun();
 		if(r->materialName == materialName)
 			return true;
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCausticCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCausticCubeMapRenderingRun.h	(revision 1688)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCausticCubeMapRenderingRun.h	(revision 1722)
@@ -60,7 +60,7 @@
 	float getAttenuation(){return attenuation;}
 	
-	bool canJoin(OgreRenderingRun* run)
+	bool canJoin(RenderingRun* run)
 	{
-		OgreCausticCubeMapRenderingRun* r = (OgreCausticCubeMapRenderingRun*) run;
+		OgreCausticCubeMapRenderingRun* r = (OgreCausticCubeMapRenderingRun*) run->asOgreRenderingRun();
 		if(r->materialName == materialName)
 			return true;
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreChildPSystemRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreChildPSystemRenderingRun.h	(revision 1330)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreChildPSystemRenderingRun.h	(revision 1722)
@@ -46,5 +46,5 @@
 	String getImpostorTextureName(){return name;}
 	
-	bool canJoin(OgreRenderingRun* run)
+	bool canJoin(RenderingRun* run)
 	{
 		
Index: P/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreColorCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreColorCubeMapRenderingRun.h	(revision 790)
+++ 	(revision )
@@ -1,74 +1,0 @@
-#pragma once
-
-//disable inheritance warning caused by multiple inheritance
-#if _WIN32
-#if _MSC_VER
-#pragma warning(disable: 4250)
-#endif
-#endif
-
-#include "OgreRenderingRun.h"
-#include "ColorCubeMapRenderingRun.h"
-#include "OgreSharedRuns.h"
-
-
-/**
-	@brief ColorCubeMapRenderingRun used in an OGRE environment.
-*/
-class OgreColorCubeMapRenderingRun : public OgreRenderingRun,
-									public ColorCubeMapRenderingRun
-{	
-public:
-
-	/**
-		@brief Constructor.
-
-		@param sharedRuns			a pointer to the OgreSharedRuns this run belongs to
-		@param name					the name of the cubemap texture to be created
-		@param startFrame			adds an offset to the current frame number to help evenly distribute updates between frames
-		@param updateInterval		update frequency
-		@param resolution			cubemap resolution
-		@param useDistCalc			flag to skip cube face update if object is far away
-		@param useFaceAngleCalc		flag to skip cube face update if face is neglible
-		@param distTolerance		distance tolerance used in face skip
-		@param angleTolerance		angle tolerance used in face skip		
-		@param updateAllFace		defines if all cubemap faces should be updated in a frame or only one face per frame
-	*/	
-	OgreColorCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
-								 String name,
-								 unsigned long startFrame,
-								 unsigned long updateInterval,
-								 unsigned int resolution,
-								 bool useDistCalc = false,
-								 bool useFaceAngleCalc = false,
-								 float distTolerance = 15,
-								 float angleTolerance = 10,
-								 bool updateAllFace = false);
-	/**
-		@brief returns the name of the resulting color cubemap texture
-	*/
-	String getColorCubeMapTextureName(){return name;}
-	
-protected:
-
-	/**
-		@brief a pointer to the OgreSharedRuns this run belongs to
-	*/
-	OgreSharedRuns* sharedRuns;
-	/**
-		@brief the name of the cubemap texture that was created by this run
-	*/
-	String name;
-	/**
-		@brief a pointer to the cubemap texture that was created by this run
-	*/
-	Texture* colorCubemapTexture;
-	
-	
-	//inherited
-	inline void createColorCubeMap();
-	//inherited
-	inline void updateCubeFace(int facenum);
-	//inherited
-    bool faceNeedsUpdate(int facenum); 	
-};
Index: P/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDistanceCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreDistanceCubeMapRenderingRun.h	(revision 790)
+++ 	(revision )
@@ -1,73 +1,0 @@
-#pragma once
-
-//disable inheritance warning caused by multiple inheritance
-#if _WIN32
-#if _MSC_VER
-#pragma warning(disable: 4250)
-#endif
-#endif
-
-#include "OgreRenderingRun.h"
-#include "DistanceCubeMapRenderingRun.h"
-#include "OgreSharedRuns.h"
-
-
-/**
-	@brief ColorCubeMapRenderingRun used in an OGRE environment.
-*/
-class OgreDistanceCubeMapRenderingRun : public OgreRenderingRun,
-									public DistanceCubeMapRenderingRun
-{	
-public:
-
-	/**
-		@brief Constructor.
-
-		@param sharedRuns			a pointer to the OgreSharedRuns this run belongs to
-		@param name					the name of the cubemap texture to be created
-		@param startFrame			adds an offset to the current frame number to help evenly distribute updates between frames
-		@param updateInterval		update frequency
-		@param resolution			cubemap resolution
-		@param useDistCalc			flag to skip cube face update if object is far away
-		@param useFaceAngleCalc		flag to skip cube face update if face is neglible
-		@param distTolerance		distance tolerance used in face skip
-		@param angleTolerance		angle tolerance used in face skip		
-		@param updateAllFace		defines if all cubemap faces should be updated in a frame or only one face per frame
-	*/	
-	OgreDistanceCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
-								String name,
-								  unsigned long startFrame,
-								unsigned long updateInterval,
-								unsigned int resolution,
-								 bool useDistCalc = false,
-								 bool useFaceAngleCalc = false,
-								 float distTolerance = 15,
-								 float angleTolerance = 10,
-								 bool updateAllFace = false);
-	/**
-		@brief returns the name of the resulting distance cubemap texture
-	*/
-	String getDistanceCubeMapTextureName(){return name;}
-	
-protected:	
-	/**
-		@brief a pointer to the OgreSharedRuns this run belongs to
-	*/
-	OgreSharedRuns* sharedRuns;
-	/**
-		@brief the name of the cubemap texture that was created by this run
-	*/
-	String name;
-	/**
-		@brief a pointer to the cubemap texture that was created by this run
-	*/
-	Texture* distanceCubemapTexture;
-	
-	
-	//inherited
-	inline void createDistanceCubeMap();
-	//inherited
-	inline void updateCubeFace(int facenum);
-	//inherited
-    bool faceNeedsUpdate(int facenum); 	
-};
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h	(revision 1722)
@@ -48,4 +48,7 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
+							String selfMaterial,
+							String environmentMaterial,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -64,6 +67,4 @@
 	//inherited
 	void distanceCubeMapRunChanged(RenderingRun* run);
-	//inherited
-	RenderingRun* createDistanceCubeMapRun();
 	//inherited
 	void distanceCubeMapRunUpdated(RenderingRun* run);
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h	(revision 1722)
@@ -48,4 +48,7 @@
 									bool updateAllFace,
 									bool renderSelf,
+									bool renderEnvironment,
+									String selfMaterial,
+									String environmentMaterial,
 									Pass* pass,
 									OgreRenderable* parentRenderable,
@@ -63,9 +66,5 @@
 	
 	//inherited
-	void colorCubeMapRunChanged(RenderingRun* run);
-	//inherited
-	RenderingRun* createColorCubeMapRun();
-
-	
+	void colorCubeMapRunChanged(RenderingRun* run);	
 };
 
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h	(revision 1722)
@@ -50,4 +50,7 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
+							String selfMaterial,
+							String environmentMaterial,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -68,6 +71,4 @@
 	//inherited
 	void colorCubeMapRunChanged(RenderingRun* run);
-	//inherited
-	RenderingRun* createColorCubeMapRun();
 	//inherited
 	RenderingRun* createReducedCubeMapRun();
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h	(revision 1722)
@@ -48,7 +48,11 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
+							String selfMaterial,
+							String environmentMaterial,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
-							OgreTechniqueGroup* parentTechniqueGroup
+							OgreTechniqueGroup* parentTechniqueGroup,
+							bool createCubeRun = false
 							);
 	/**
@@ -56,4 +60,5 @@
 	*/
 	~OgreCubeMapRenderTechnique();
+	
 		
 protected:
@@ -62,5 +67,11 @@
 		@brief the id of the texture unit state the resulting cubemap should be bound to
 	*/
-	unsigned char texID;	
+	unsigned char texID;
+	String selfMaterial;
+	String environmentMaterial;
+	String texturePostFix;
+
+	RenderingRun* createCubeMapRun();
+	void cubeMapRunChanged(RenderingRun* run);	
 };
 
@@ -70,4 +81,11 @@
 	
 	OgreCubeMapRenderTechniqueFactory();
+
+	OgreRenderTechnique* createInstance(IllumTechniqueParams* params,
+										Pass* pass,
+										OgreRenderable* parentRenderable,
+										OgreTechniqueGroup* parentTechniqueGroup);
+
+	void resetParams();
 	
 	unsigned long startFrame;
@@ -81,6 +99,6 @@
 	bool updateAllFace;
 	bool renderSelf;
-
-	void resetParams();
-
+	bool renderEnvironment;
+	String selfMaterial;
+	String environmentMaterial;
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/scripts/OgreIllumModule.vcproj
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/scripts/OgreIllumModule.vcproj	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/scripts/OgreIllumModule.vcproj	(revision 1722)
@@ -249,13 +249,9 @@
 				</File>
 				<File
-					RelativePath="..\src\RenderingRuns\OgreColorCubeMapRenderingRun.cpp"
+					RelativePath="..\src\RenderingRuns\OgreCubeMapRenderingRun.cpp"
 					>
 				</File>
 				<File
 					RelativePath="..\src\RenderingRuns\OgreDepthShadowMapRenderingRun.cpp"
-					>
-				</File>
-				<File
-					RelativePath="..\src\RenderingRuns\OgreDistanceCubeMapRenderingRun.cpp"
 					>
 				</File>
@@ -379,13 +375,9 @@
 				</File>
 				<File
-					RelativePath="..\include\RenderingRuns\OgreColorCubeMapRenderingRun.h"
+					RelativePath="..\include\RenderingRuns\OgreCubeMapRenderingRun.h"
 					>
 				</File>
 				<File
 					RelativePath="..\include\RenderingRuns\OgreDepthShadowMapRenderingRun.h"
-					>
-				</File>
-				<File
-					RelativePath="..\include\RenderingRuns\OgreDistanceCubeMapRenderingRun.h"
 					>
 				</File>
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 1425)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreLightVolumeRenderingRun.cpp	(revision 1722)
@@ -1,5 +1,4 @@
 #include "OgreLightVolumeRenderingRun.h"
 #include "OgreIlluminationManager.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
 #include "OgreChildPSystemRenderingRun.h"
 
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 1628)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgrePhotonMapRenderingRun.cpp	(revision 1722)
@@ -1,6 +1,5 @@
 #include "OgrePhotonMapRenderingRun.h"
 //#include "OgreIlluminationManager.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
-
+#include "OgreCubeMapRenderingRun.h"
 
 
@@ -139,6 +138,6 @@
 {
 	Material* mat = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
-	OgreDistanceCubeMapRenderingRun* cuberun =(OgreDistanceCubeMapRenderingRun*) (run->asOgreRenderingRun());
-	String cubemapname = cuberun->getDistanceCubeMapTextureName();
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
 	mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName(cubemapname);
 }
@@ -147,6 +146,6 @@
 {
 	Material* mat = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
-	OgreDistanceCubeMapRenderingRun* cuberun =(OgreDistanceCubeMapRenderingRun*) (run->asOgreRenderingRun());
-	String cubemapname = cuberun->getDistanceCubeMapTextureName();
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
 	GpuProgramParametersSharedPtr fpParams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters();
 	Vector3 center = ((OgreSharedRuns*) sharedRuns)->getRootPosition(ILLUMRUN_DISTANCE_CUBEMAP);
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreChildParticlesystemRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreChildParticlesystemRenderingRun.cpp	(revision 1425)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreChildParticlesystemRenderingRun.cpp	(revision 1722)
@@ -1,7 +1,4 @@
 #include "OgreChildPSystemRenderingRun.h"
 #include "OgreIlluminationManager.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
-
-
 
 OgreChildPSystemRenderingRun::OgreChildPSystemRenderingRun(OgreSharedRuns* sharedRuns,
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp	(revision 1722)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp	(revision 1722)
@@ -0,0 +1,166 @@
+#include "OgreCubeMapRenderingRun.h"
+#include "OgreIlluminationManager.h"
+
+
+
+OgreCubeMapRenderingRun::OgreCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
+														   String name,
+														   unsigned long startFrame,
+														   unsigned long updateInterval,
+														   unsigned int resolution,
+														   bool useDistCalc,
+														   bool useFaceAngleCalc,
+														   float distTolerance,
+														   float angleTolerance,
+														   bool updateAllFace,
+														   bool renderSelf,
+														   bool renderEnvironment,
+														   String selfMaterial,
+														   String environmentMaterial)
+														   :CubeMapRenderingRun(startFrame, updateInterval, resolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment)
+							, OgreRenderingRun(startFrame, updateInterval)
+							, RenderingRun(startFrame, updateInterval)
+
+{
+	this->sharedRuns = sharedRuns;
+	this->name = name;
+	this->selfMaterial = selfMaterial;
+	this->environmentMaterial = environmentMaterial;
+	
+	if(environmentMaterial == "")
+		useEnvMaterial = false;
+	else
+		useEnvMaterial = true;
+
+	if(selfMaterial == "")
+		useSelfMaterial = false;
+	else
+		useSelfMaterial = true;
+
+
+	createCubeMap();
+}
+
+void OgreCubeMapRenderingRun::createCubeMap()
+{
+	cubemapTexture = createCubeRenderTexture(name, 
+												sharedRuns->getRootPosition(),
+												resolution,
+												PF_FLOAT16_RGBA,
+												//PF_R8G8B8A8,
+												0);	
+}
+
+void OgreCubeMapRenderingRun::updateCubeFace(int facenum)
+{
+	OgreSharedRuns* root = (OgreSharedRuns*) sharedRuns->getRoot(ILLUMRUN_COLOR_CUBEMAP);
+	SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager();
+	RenderQueue* rq = sm->getRenderQueue();
+	
+	RenderTarget* rt = cubemapTexture->getBuffer(facenum, 0).getPointer()->getRenderTarget();
+	Camera*  cam = 	rt->getViewport(0)->getCamera();
+	Vector3 center = sharedRuns->getRootPosition(ILLUMRUN_COLOR_CUBEMAP);
+	cam->setPosition(center);
+
+	bool renderAllwithOwnColor = false;
+
+	if(renderSelf && renderEnvironment && !useSelfMaterial && !useEnvMaterial)
+		renderAllwithOwnColor = true;
+
+	if(!renderAllwithOwnColor)
+	{
+		root->hide();
+
+		if(renderEnvironment)
+		{
+			if(useEnvMaterial)
+			{
+				setMaterialForVisibles(environmentMaterial, cam);
+				sm->_queueSkiesForRendering(cam);				
+			}
+			else
+			{
+				sm->_findVisibleObjects(cam, false);
+				sm->_queueSkiesForRendering(cam);
+				sm->setFindVisibleObjects(false);
+			}
+		}
+		else
+		{
+			rq->clear();
+			sm->setFindVisibleObjects(false);		
+		}
+		
+		if(renderSelf)
+		{
+			sharedRuns->getRoot(ILLUMRUN_COLOR_CUBEMAP)->restoreVisibility();
+			if(useSelfMaterial)
+				root->setMaterial(selfMaterial);
+			root->addRenderablesToQueue(rq);
+		}
+	}
+	
+
+	
+	rt->update();
+
+	//rt->writeContentsToFile("cubbe" + StringConverter::toString(facenum) + ".dds");
+	
+	if(!renderAllwithOwnColor)
+	{
+		if(renderEnvironment && useEnvMaterial)
+			restoreMaterials();
+		else
+			sm->setFindVisibleObjects(true);
+		
+		if(!renderSelf)
+			root->restoreVisibility();
+		else if(useSelfMaterial)
+			root->restoreMaterial();
+	}
+}
+
+bool OgreCubeMapRenderingRun::faceNeedsUpdate(int facenum)
+{	
+	if(useDistCalc || useFaceAngleCalc)
+	{
+		float chance1 = 1.0;
+		float chance2 = 1.0;
+		
+		Camera* mainCamera = OgreIlluminationManager::getSingleton().getMainCamera();
+
+		if(useDistCalc)
+		{
+			Vector3 cubemapPosition = sharedRuns->getRootPosition(ILLUMRUN_COLOR_CUBEMAP);
+			float objradius = sharedRuns->getRootBoundingSphere(ILLUMRUN_COLOR_CUBEMAP).getRadius();
+			float fov = mainCamera->getFOVy().valueRadians() / 2.0;
+			float dist = (cubemapPosition - mainCamera->getPosition()).length();
+			float vangle = Math::ASin( objradius / dist).valueRadians();
+			float angleratio = vangle / fov;
+			chance1 = Math::Pow(angleratio, 1.0 / distTolerance);
+		}
+
+		if(useFaceAngleCalc)
+		{
+			Vector3 faceDir = getCubeMapFaceDirection(facenum);			
+			Vector3 cameraDir = mainCamera->getDirection();
+			float angle = faceDir.dotProduct(-1 * cameraDir);
+			float facingforward = (angle + 1) / 2.0;
+			chance2 = Math::Pow(facingforward, 1.0 / angleTolerance);
+		}
+	
+		float dice = Math::UnitRandom();
+		float chance = chance1 * chance2;
+
+		if(dice < chance)
+		{	
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+
+	return true;
+}
Index: P/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDistanceCubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreDistanceCubeMapRenderingRun.cpp	(revision 790)
+++ 	(revision )
@@ -1,100 +1,0 @@
-#include "OgreDistanceCubeMapRenderingRun.h"
-#include "OgreIlluminationManager.h"
-
-
-
-OgreDistanceCubeMapRenderingRun::OgreDistanceCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
-														   String name,
-														   unsigned long startFrame,
-															unsigned long updateInterval,
-															unsigned int resolution,
-														   bool useDistCalc,
-														   bool useFaceAngleCalc,
-														   float distTolerance,
-														   float angleTolerance,
-														   bool updateAllFace)
-					:DistanceCubeMapRenderingRun(startFrame, updateInterval, resolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace)
-					, OgreRenderingRun(startFrame, updateInterval)
-					, RenderingRun(startFrame, updateInterval)
-{
-	this->sharedRuns = sharedRuns;
-	this->name = name;
-	
-	createDistanceCubeMap();
-}
-
-void OgreDistanceCubeMapRenderingRun::createDistanceCubeMap()
-{
-	distanceCubemapTexture = createCubeRenderTexture(name, 
-							sharedRuns->getRootPosition(),
-												resolution,
-												PF_FLOAT32_RGBA);
-}
-
-void OgreDistanceCubeMapRenderingRun::updateCubeFace(int facenum)
-{
-	sharedRuns->getRoot(ILLUMRUN_DISTANCE_CUBEMAP)->hide();
-
-	RenderTarget* rt = distanceCubemapTexture->getBuffer(facenum, 0).getPointer()
-							->getRenderTarget();
-
-	Vector3 center = sharedRuns->getRootPosition(ILLUMRUN_DISTANCE_CUBEMAP);
-	Camera*  cam = 	rt->getViewport(0)->getCamera();
-	cam->setPosition(center);
-
-	
-	setMaterialForVisibles(String("GameTools/DistanceShader"), cam);
-
-	rt->update();
-
-	restoreMaterials();
-	
-	//rt->writeContentsToFile("cubbe" + StringConverter::toString(facenum) + ".dds");
-	
-	sharedRuns->getRoot(ILLUMRUN_DISTANCE_CUBEMAP)->restoreVisibility();
-}
-
-bool OgreDistanceCubeMapRenderingRun::faceNeedsUpdate(int facenum)
-{	
-	if(useDistCalc || useFaceAngleCalc)
-	{
-		float chance1 = 1.0;
-		float chance2 = 1.0;
-		
-		Camera* mainCamera = OgreIlluminationManager::getSingleton().getMainCamera();
-
-		if(useDistCalc)
-		{
-			Vector3 cubemapPosition = sharedRuns->getRootPosition(ILLUMRUN_DISTANCE_CUBEMAP);
-			float objradius = sharedRuns->getRootBoundingSphere(ILLUMRUN_DISTANCE_CUBEMAP).getRadius();
-			float fov = mainCamera->getFOVy().valueRadians() / 2.0;
-			float dist = (cubemapPosition - mainCamera->getPosition()).length();
-			float vangle = Math::ASin( objradius / dist).valueRadians();
-			float angleratio = vangle / fov;
-			chance1 = Math::Pow(angleratio, 1.0 / distTolerance);
-		}
-
-		if(useFaceAngleCalc)
-		{
-			Vector3 faceDir = getCubeMapFaceDirection(facenum);			
-			Vector3 cameraDir = mainCamera->getDirection();
-			float angle = faceDir.dotProduct(-1 * cameraDir);
-			float facingforward = (angle + 1) / 2.0;
-			chance2 = Math::Pow(facingforward, 1.0 / angleTolerance);
-		}
-	
-		float dice = Math::UnitRandom();
-		float chance = chance1 * chance2;
-
-		if(dice < chance)
-		{	
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	return true;
-}
Index: P/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreColorCubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreColorCubeMapRenderingRun.cpp	(revision 790)
+++ 	(revision )
@@ -1,96 +1,0 @@
-#include "OgreColorCubeMapRenderingRun.h"
-#include "OgreIlluminationManager.h"
-
-
-
-OgreColorCubeMapRenderingRun::OgreColorCubeMapRenderingRun(OgreSharedRuns* sharedRuns,
-														   String name,
-														   unsigned long startFrame,
-															unsigned long updateInterval,
-															unsigned int resolution,
-														   bool useDistCalc,
-														   bool useFaceAngleCalc,
-														   float distTolerance,
-														   float angleTolerance,
-														   bool updateAllFace)
-							:ColorCubeMapRenderingRun(startFrame, updateInterval, resolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace)
-							, OgreRenderingRun(startFrame, updateInterval)
-							, RenderingRun(startFrame, updateInterval)
-
-{
-	this->sharedRuns = sharedRuns;
-	this->name = name;
-	
-	createColorCubeMap();
-}
-
-void OgreColorCubeMapRenderingRun::createColorCubeMap()
-{
-	colorCubemapTexture = createCubeRenderTexture(name, 
-												sharedRuns->getRootPosition(),
-												resolution,
-												PF_FLOAT16_RGBA,
-												//PF_R8G8B8A8,
-												0);	
-}
-
-void OgreColorCubeMapRenderingRun::updateCubeFace(int facenum)
-{
-	sharedRuns->getRoot(ILLUMRUN_COLOR_CUBEMAP)->hide();
-
-	RenderTarget* rt = colorCubemapTexture->getBuffer(facenum, 0).getPointer()
-							->getRenderTarget();
-
-	Vector3 center = sharedRuns->getRootPosition(ILLUMRUN_COLOR_CUBEMAP);
-	rt->getViewport(0)->getCamera()->setPosition(center);
-	rt->update();
-
-	//rt->writeContentsToFile("cubbe" + StringConverter::toString(facenum) + ".dds");
-	
-	sharedRuns->getRoot(ILLUMRUN_COLOR_CUBEMAP)->restoreVisibility();
-}
-
-bool OgreColorCubeMapRenderingRun::faceNeedsUpdate(int facenum)
-{	
-	if(useDistCalc || useFaceAngleCalc)
-	{
-		float chance1 = 1.0;
-		float chance2 = 1.0;
-		
-		Camera* mainCamera = OgreIlluminationManager::getSingleton().getMainCamera();
-
-		if(useDistCalc)
-		{
-			Vector3 cubemapPosition = sharedRuns->getRootPosition(ILLUMRUN_COLOR_CUBEMAP);
-			float objradius = sharedRuns->getRootBoundingSphere(ILLUMRUN_COLOR_CUBEMAP).getRadius();
-			float fov = mainCamera->getFOVy().valueRadians() / 2.0;
-			float dist = (cubemapPosition - mainCamera->getPosition()).length();
-			float vangle = Math::ASin( objradius / dist).valueRadians();
-			float angleratio = vangle / fov;
-			chance1 = Math::Pow(angleratio, 1.0 / distTolerance);
-		}
-
-		if(useFaceAngleCalc)
-		{
-			Vector3 faceDir = getCubeMapFaceDirection(facenum);			
-			Vector3 cameraDir = mainCamera->getDirection();
-			float angle = faceDir.dotProduct(-1 * cameraDir);
-			float facingforward = (angle + 1) / 2.0;
-			chance2 = Math::Pow(facingforward, 1.0 / angleTolerance);
-		}
-	
-		float dice = Math::UnitRandom();
-		float chance = chance1 * chance2;
-
-		if(dice < chance)
-		{	
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	return true;
-}
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp	(revision 1722)
@@ -1,5 +1,5 @@
 #include "OgreColorCubeMapRenderTechnique.h"
 #include "OgreTechniqueGroup.h"
-#include "OgreColorCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 OgreColorCubeMapRenderTechnique::OgreColorCubeMapRenderTechnique(unsigned long startFrame,
@@ -13,15 +13,19 @@
 														bool updateAllFace,
 														bool renderSelf,
+														bool renderEnvironment,
+														String selfMaterial,
+														String environmentMaterial,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
-							:OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, pass, parentRenderable, parentTechniqueGroup),
-							ColorCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
-							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
-							RenderTechnique(parentRenderable, parentTechniqueGroup) 
+															:OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, pass, parentRenderable, parentTechniqueGroup),
+															ColorCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
+															CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
+															RenderTechnique(parentRenderable, parentTechniqueGroup) 
 {	
-	
+	texturePostFix = "_COLORCUBEMAP";
+
 	if(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP) == 0)
-		sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createColorCubeMapRun());
+		sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createCubeMapRun());
 	
 	colorCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP));
@@ -47,23 +51,11 @@
 void OgreColorCubeMapRenderTechnique::colorCubeMapRunChanged(RenderingRun* run)
 {
-	OgreColorCubeMapRenderingRun* cuberun =(OgreColorCubeMapRenderingRun*) (run->asOgreRenderingRun());
-	String cubemapname = cuberun->getColorCubeMapTextureName();
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
 	
 	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
 }
 
-RenderingRun* OgreColorCubeMapRenderTechnique::createColorCubeMapRun()
-{
-	return new OgreColorCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(), 
-												parentOgreRenderable->getName()  + "_COLORCUBEMAP",
-												startFrame,
-												cubeMapUpdateInterval,
-												cubeMapResolution,
-												useDistCalc,
-												useFaceAngleCalc,
-												distTolerance,
-												angleTolerance,
-												updateAllFace);
-}
+
 
 
@@ -96,4 +88,7 @@
 													updateAllFace,
 													renderSelf,
+													renderEnvironment,
+													selfMaterial,
+													environmentMaterial,
 													pass,
 													parentRenderable,
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp	(revision 1722)
@@ -2,5 +2,5 @@
 #include "OgreTechniqueGroup.h"
 #include "OgreReducedCubeMapRenderingRun.h"
-#include "OgreColorCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 OgreConvolvedCubeMapRenderTechnique::OgreConvolvedCubeMapRenderTechnique(unsigned long startFrame,
@@ -15,15 +15,20 @@
 														bool updateAllFace,
 														bool renderSelf,
+														bool renderEnvironment,
+														String selfMaterial,
+														String environmentMaterial,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
 							:
-							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, pass, parentRenderable, parentTechniqueGroup),
-							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
-							ConvolvedCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, reducedCubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
+							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, pass, parentRenderable, parentTechniqueGroup),
+							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
+							ConvolvedCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, reducedCubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
 							RenderTechnique(parentRenderable, parentTechniqueGroup) 
 {	
+	texturePostFix = "_COLORCUBEMAP";
+
 	if(sharedRuns->getRun(ILLUMRUN_COLOR_CUBEMAP) == 0)
-		sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createColorCubeMapRun());
+		sharedRuns->addRun(ILLUMRUN_COLOR_CUBEMAP, createCubeMapRun());
 
 	if(sharedRuns->getRun(ILLUMRUN_REDUCED_CUBEMAP) == 0)
@@ -55,25 +60,10 @@
 void OgreConvolvedCubeMapRenderTechnique::colorCubeMapRunChanged(RenderingRun* run)
 {
-	
-	OgreColorCubeMapRenderingRun* cuberun =(OgreColorCubeMapRenderingRun*) (run->asOgreRenderingRun());
-	String cubemapname = cuberun->getColorCubeMapTextureName();
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
 	
 	OgreReducedCubeMapRenderingRun* rr = (OgreReducedCubeMapRenderingRun*) sharedRuns->getRun(ILLUMRUN_REDUCED_CUBEMAP)->asOgreRenderingRun();
 	rr->colorCubeMapChanged(cubemapname);
 
-}
-
-RenderingRun* OgreConvolvedCubeMapRenderTechnique::createColorCubeMapRun()
-{
-	return new OgreColorCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(), 
-												parentOgreRenderable->getName()  + "_COLORCUBEMAP",
-												startFrame,
-												cubeMapUpdateInterval,
-												cubeMapResolution,
-												useDistCalc,
-												useFaceAngleCalc,
-												distTolerance,
-												angleTolerance,
-												updateAllFace);
 }
 
@@ -134,4 +124,7 @@
 												updateAllFace,
 												renderSelf,
+												renderEnvironment,
+												selfMaterial,
+												environmentMaterial,
 												pass,
 												parentRenderable,
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp	(revision 1722)
@@ -1,5 +1,5 @@
 #include "OgreCubeMapRenderTechnique.h"
 #include "OgreTechniqueGroup.h"
-#include "OgreColorCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 OgreCubeMapRenderTechnique::OgreCubeMapRenderTechnique(unsigned long startFrame,
@@ -13,12 +13,27 @@
 														bool updateAllFace,
 														bool renderSelf,
+														bool renderEnvironment,
+														String selfMaterial,
+														String environmentMaterial,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
-														OgreTechniqueGroup* parentTechniqueGroup)
+														OgreTechniqueGroup* parentTechniqueGroup,
+														bool createCubeRun)
 							:OgreRenderTechnique( pass, parentRenderable, parentTechniqueGroup),
-							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
+							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
 							RenderTechnique(parentRenderable, parentTechniqueGroup) 
 {	
-	this->texID = texID;	
+	this->texID = texID;
+	this->selfMaterial = selfMaterial;
+	this->environmentMaterial = environmentMaterial;
+	texturePostFix = "_CUBEMAP";
+
+	if(createCubeRun)
+	{
+		if(sharedRuns->getRun(ILLUMRUN_CUBEMAP) == 0)
+		sharedRuns->addRun(ILLUMRUN_CUBEMAP, createCubeMapRun());
+
+		cubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_CUBEMAP));
+	}
 }
 
@@ -27,4 +42,30 @@
 {
 
+}
+
+void OgreCubeMapRenderTechnique::cubeMapRunChanged(RenderingRun* run)
+{
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
+	
+	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
+}
+
+RenderingRun* OgreCubeMapRenderTechnique::createCubeMapRun()
+{
+	return new OgreCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(), 
+												parentOgreRenderable->getName()  + texturePostFix,
+												startFrame,
+												cubeMapUpdateInterval,
+												cubeMapResolution,
+												useDistCalc,
+												useFaceAngleCalc,
+												distTolerance,
+												angleTolerance,
+												updateAllFace,
+												renderSelf,
+												renderEnvironment,
+												selfMaterial,
+												environmentMaterial);
 }
 
@@ -107,4 +148,22 @@
 		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
 		f->renderSelf =  StringConverter::parseBool(params);
+	}
+
+	void parseRenderEnv(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->renderEnvironment =  StringConverter::parseBool(params);
+	}
+
+	void parseSelfMaterial(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->selfMaterial =  params;
+	}
+
+	void parseEnvMaterial(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->environmentMaterial =  params;
 	}
 }
@@ -123,5 +182,8 @@
 	this->attributeParsers.insert(AttribParserList::value_type("face_angle_calc", (ILLUM_ATTRIBUTE_PARSER) parseUseFaceAngleCalc));
 	this->attributeParsers.insert(AttribParserList::value_type("update_all_face", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
-	this->attributeParsers.insert(AttribParserList::value_type("render_self", (ILLUM_ATTRIBUTE_PARSER) parseUpdateAllFace));
+	this->attributeParsers.insert(AttribParserList::value_type("render_self", (ILLUM_ATTRIBUTE_PARSER) parseRenderSelf));
+	this->attributeParsers.insert(AttribParserList::value_type("render_env", (ILLUM_ATTRIBUTE_PARSER) parseRenderEnv));
+	this->attributeParsers.insert(AttribParserList::value_type("self_material", (ILLUM_ATTRIBUTE_PARSER) parseSelfMaterial));
+	this->attributeParsers.insert(AttribParserList::value_type("env_material", (ILLUM_ATTRIBUTE_PARSER) parseEnvMaterial));
 
 }
@@ -139,3 +201,37 @@
 	updateAllFace = false;
 	renderSelf = false;
-}
+	renderEnvironment = true;
+	selfMaterial = "";
+	environmentMaterial = "";
+}
+
+OgreRenderTechnique* OgreCubeMapRenderTechniqueFactory::createInstance( 
+										IllumTechniqueParams* params,
+										Pass* pass,
+										OgreRenderable* parentRenderable,
+										OgreTechniqueGroup* parentTechniqueGroup)
+{	
+	resetParams();
+	parseParams(params);
+	
+	OgreCubeMapRenderTechnique* result = new OgreCubeMapRenderTechnique(
+												startFrame,
+												cubeMapUpdateInterval,
+												cubeMapResolution,
+												texID,
+												useDistCalc,
+												useFaceAngleCalc,
+												distTolerance,
+												angleTolerance,
+												updateAllFace,
+												renderSelf,
+												renderEnvironment,
+												selfMaterial,
+												environmentMaterial,
+												pass,
+												parentRenderable,
+												parentTechniqueGroup,
+												true);
+
+	return result;
+}
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 1688)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 1722)
@@ -3,5 +3,5 @@
 #include "OgreCausticCubeMapRenderingRun.h"
 #include "OgrePhotonMapRenderingRun.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 
@@ -119,15 +119,18 @@
 RenderingRun* OgreCausticCasterRenderTechnique::createDistanceCubeMapRun()
 {
-	return new OgreDistanceCubeMapRenderingRun((OgreSharedRuns*) sharedRuns,
-												parentOgreRenderable->getName()  + "_DISTANCECUBEMAP",
-												startFrame,
-												photonMapUpdateInterval,
-												causticCubeMapResolution,
-												0,
-												0,
-												0,
-												0,
-												updateAllFace
-												);
+	return new OgreCubeMapRenderingRun((OgreSharedRuns*) sharedRuns,
+										parentOgreRenderable->getName()  + "_DISTANCECUBEMAP",
+										startFrame,
+										photonMapUpdateInterval,
+										causticCubeMapResolution,
+										0,
+										0,
+										0,
+										0,
+										updateAllFace,
+										false,
+										true,
+										"",
+										"GameTools/DistanceShader");
 
 }
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp	(revision 1518)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticRecieverRenderTechnique.cpp	(revision 1722)
@@ -3,5 +3,5 @@
 #include "OgreIlluminationManager.h"
 #include "OgreCausticCubeMapRenderingRun.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 OgreCausticRecieverRenderTechnique::OgreCausticRecieverRenderTechnique(
@@ -97,9 +97,9 @@
 				cauCubeRun->getCausticCubeMapTextureName());
 
-			OgreDistanceCubeMapRenderingRun* cauPhotonRun = 
-				(OgreDistanceCubeMapRenderingRun*) causticCasters.at(i)->
+			OgreCubeMapRenderingRun* distCubeRun = 
+				(OgreCubeMapRenderingRun*) causticCasters.at(i)->
 					getRun(ILLUMRUN_DISTANCE_CUBEMAP)->asOgreRenderingRun();
 			passes.at(i)->getTextureUnitState(1)->setTextureName(
-				cauPhotonRun->getDistanceCubeMapTextureName());
+				distCubeRun->getCubeMapTextureName());
 			
 			//set caster position
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp	(revision 1722)
@@ -1,5 +1,5 @@
 #include "OgreDistanceCubeMapRenderTechnique.h"
 #include "OgreTechniqueGroup.h"
-#include "OgreDistanceCubeMapRenderingRun.h"
+#include "OgreCubeMapRenderingRun.h"
 
 OgreDistanceCubeMapRenderTechnique::OgreDistanceCubeMapRenderTechnique(unsigned long startFrame,
@@ -13,15 +13,20 @@
 														bool updateAllFace,
 														bool renderSelf,
+														bool renderEnvironment,
+														String selfMaterial,
+														String environmentMaterial,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
 							:
-							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, pass, parentRenderable, parentTechniqueGroup),
-							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
-							DistanceCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, parentRenderable, parentTechniqueGroup),
+							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, pass, parentRenderable, parentTechniqueGroup),
+							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
+							DistanceCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
 							RenderTechnique(parentRenderable, parentTechniqueGroup) 
 {	
+	texturePostFix = "_DISTANCECUBEMAP";
+
 	if(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP) == 0)
-		sharedRuns->addRun(ILLUMRUN_DISTANCE_CUBEMAP, createDistanceCubeMapRun());
+		sharedRuns->addRun(ILLUMRUN_DISTANCE_CUBEMAP, createCubeMapRun());
 
 	distanceCubeMapRunChanged(sharedRuns->getRun(ILLUMRUN_DISTANCE_CUBEMAP));
@@ -41,6 +46,6 @@
 void OgreDistanceCubeMapRenderTechnique::distanceCubeMapRunChanged(RenderingRun* run)
 {
-	OgreDistanceCubeMapRenderingRun* cuberun =(OgreDistanceCubeMapRenderingRun*) (run->asOgreRenderingRun());
-	String cubemapname = cuberun->getDistanceCubeMapTextureName();
+	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	String cubemapname = cuberun->getCubeMapTextureName();
 	
 	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
@@ -54,17 +59,5 @@
 }
 
-RenderingRun* OgreDistanceCubeMapRenderTechnique::createDistanceCubeMapRun()
-{
-	return new OgreDistanceCubeMapRenderingRun( (OgreSharedRuns*) parentTechniqueGroup->getSharedRuns(), 
-												parentOgreRenderable->getName()  + "_DISTANCECUBEMAP",
-												startFrame,
-												cubeMapUpdateInterval,
-												cubeMapResolution,
-												useDistCalc,
-												useFaceAngleCalc,
-												distTolerance,
-												angleTolerance,
-												updateAllFace);
-}
+
 
 ///Technique factory
@@ -82,4 +75,6 @@
 	OgreCubeMapRenderTechniqueFactory::resetParams();
 	texID = 1;
+	environmentMaterial = "GameTools/DistanceShader";
+	selfMaterial = "GameTools/DistanceShader";
 	OgreCubeMapRenderTechniqueFactory::parseParams(params);	
 	parseParams(params);
@@ -96,4 +91,7 @@
 												updateAllFace,
 												renderSelf,
+												renderEnvironment,
+												selfMaterial,
+												environmentMaterial,
 												pass,
 												parentRenderable,
Index: /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp	(revision 1425)
+++ /GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/OgreSharedRuns.cpp	(revision 1722)
@@ -294,2 +294,36 @@
 		((OgreSharedRuns*)child2)->findSharedRootsForType(runType, roots);
 }
+
+void OgreSharedRuns::setMaterial(String materialName)
+{
+	renderableMaterials.clear();
+	std::map<OgreRenderable*, bool>::iterator it = renderables.begin();
+	std::map<OgreRenderable*, bool>::iterator itend = renderables.end();
+	while(it != itend)
+	{		
+		renderableMaterials[(*it).first] = (*it).first->getMaterialName();
+		(*it).first->setMaterialName(materialName);
+		it++;
+	}
+
+	if(child1 != 0)
+		((OgreSharedRuns*)child1)->setMaterial(materialName);
+	if(child2 != 0)
+		((OgreSharedRuns*)child2)->setMaterial(materialName);
+}
+
+void OgreSharedRuns::restoreMaterial()
+{
+	std::map<OgreRenderable*, String>::iterator it = renderableMaterials.begin();
+	std::map<OgreRenderable*, String>::iterator itend = renderableMaterials.end();
+	while(it != itend)
+	{		
+		(*it).first->setMaterialName((*it).second);
+		it++;
+	}
+
+	if(child1 != 0)
+		((OgreSharedRuns*)child1)->restoreMaterial();
+	if(child2 != 0)
+		((OgreSharedRuns*)child2)->restoreMaterial();
+}
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/SharedRuns.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/SharedRuns.h	(revision 1491)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/SharedRuns.h	(revision 1722)
@@ -5,5 +5,5 @@
 
 
-#define RUN_TYPE_COUNT 11
+#define RUN_TYPE_COUNT 24
 /**
 	@brief Enum of RenderingRun types.
@@ -14,6 +14,19 @@
 enum RenderingRunType
 {
+	ILLUMRUN_CUBEMAP,
 	ILLUMRUN_COLOR_CUBEMAP,
+	ILLUMRUN_COLOR_CUBEMAP_L1,
+	ILLUMRUN_COLOR_CUBEMAP_L2,
+	ILLUMRUN_COLOR_CUBEMAP_L3,
+	ILLUMRUN_COLOR_CUBEMAP_L4,
+	ILLUMRUN_COLOR_CUBEMAP_L5,
+	ILLUMRUN_COLOR_CUBEMAP_L6,
 	ILLUMRUN_DISTANCE_CUBEMAP,
+	ILLUMRUN_DISTANCE_CUBEMAP_L1,
+	ILLUMRUN_DISTANCE_CUBEMAP_L2,
+	ILLUMRUN_DISTANCE_CUBEMAP_L3,
+	ILLUMRUN_DISTANCE_CUBEMAP_L4,
+	ILLUMRUN_DISTANCE_CUBEMAP_L5,
+	ILLUMRUN_DISTANCE_CUBEMAP_L6,
 	ILLUMRUN_CAUSTIC_CUBEMAP,
 	ILLUMRUN_REDUCED_CUBEMAP,
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/CubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/CubeMapRenderingRun.h	(revision 1722)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/CubeMapRenderingRun.h	(revision 1722)
@@ -0,0 +1,98 @@
+#pragma once
+#include "RenderingRun.h"
+
+/**
+	@brief Base abstract class that defines a rendering process of a color-cubemap.
+
+	A color cubemap is a cubemap of the colors of the surrounding environment.
+*/
+class CubeMapRenderingRun : virtual public RenderingRun
+{	
+public:
+	/**
+		@brief Constructor.
+
+		@param startFrame				adds an offset to the current frame number to help evenly distribute updates between frames
+		@param updateInterval			update frequency
+		@param resolution				color cubemap resolution
+		@param useDistCalc				flag to skip cube face update if object is far away
+		@param useFaceAngleCalc			flag to skip cube face update if face is neglible
+		@param distTolerance			distance tolerance used in face skip
+		@param angleTolerance			angle tolerance used in face skip
+		@param updateAllFace			defines if all cubemap faces should be updated in a frame or only one face per frame
+		
+	*/
+	CubeMapRenderingRun(unsigned long startFrame,
+								unsigned long updateInterval,
+								unsigned int resolution,
+								bool useDistCalc,
+								bool useFaceAngleCalc,
+								float distTolerance,
+								float angleTolerance,
+								bool updateAllFace,
+								bool renderSelf,
+								bool renderEnvironment);
+
+	
+protected:
+	/**
+			@brief defines if all cubemap faces should be updated in a frame or only one face per frame
+	*/
+	bool updateAllFace;	
+	/**
+		@brief the number of the face to be updated
+	*/
+	unsigned char currentFace;	
+	/**
+		@brief the resolution of the cubemap texture that was created by this run
+	*/
+	unsigned int resolution;
+	/**
+		@brief a flag to skip cube face update if object is far away or too small.
+
+		@see distTolerance
+	*/
+	bool useDistCalc;
+	/**
+		@brief a flag to skip cube face update the face is neglible.
+
+		@see angleTolerance
+	*/
+	bool useFaceAngleCalc;
+	/**
+		@brief A value used in face skip test.
+
+		The higher this value gets the more precise, but slower the method will be.
+	*/
+	float distTolerance;
+	/**
+		@brief A value used in face skip test.
+
+		The higher this value gets the more precise, but slower the method will be.
+	*/
+	float angleTolerance;
+	bool renderSelf;
+	bool renderEnvironment;
+
+	/**
+		@brief Creates a cubemap texture used for the color-cubemap.
+	*/
+	virtual inline void createCubeMap() = 0;
+	/**
+		@brief Updates one face of the cubemap.
+
+		@param facenum the number of the face to be updated
+	*/
+	virtual inline void updateCubeFace(int facenum) = 0;
+	/**
+		@brief Checks if a cubemap face needs to be updated.
+
+		If the object we are updating the cubemap for is far from the camera, or too small, or
+		the given cubemapface does not have significant effect on the rendering the face can be skipped.
+
+		@param facenum the number of the face to be checked
+	*/
+    virtual bool faceNeedsUpdate(int facenum) = 0;
+	//inherited
+	virtual void updateFrame(unsigned long frameNum);	
+};
Index: P/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/DistanceCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/DistanceCubeMapRenderingRun.h	(revision 780)
+++ 	(revision )
@@ -1,95 +1,0 @@
-#pragma once
-#include "RenderingRun.h"
-
-/**
-	@brief Base abstract class that defines a rendering process of a distance cubemap.
-
-	A distance cubemap stores the distances of the surrounding environment from the cubemap center.
-*/
-class DistanceCubeMapRenderingRun : virtual public RenderingRun
-{	
-public:
-
-	/**
-		@brief Constructor.
-
-		@param startFrame				adds an offset to the current frame number to help evenly distribute updates between frames
-		@param updateInterval			update frequency
-		@param resolution				distance cubemap resolution
-		@param useDistCalc				flag to skip cube face update if object is far away
-		@param useFaceAngleCalc			flag to skip cube face update if face is neglible
-		@param distTolerance			distance tolerance used in face skip
-		@param angleTolerance			angle tolerance used in face skip
-		@param updateAllFace			defines if all cubemap faces should be updated in a frame or only one face per frame		
-	*/
-	DistanceCubeMapRenderingRun(unsigned long startFrame,
-								unsigned long updateInterval,
-								unsigned int resolution,
-								bool useDistCalc,
-								bool useFaceAngleCalc,
-								float distTolerance,
-								float angleTolerance,
-								bool updateAllFace);
-
-	
-protected:
-
-	/**
-			@brief defines if all cubemap faces should be updated in a frame or only one face per frame
-	*/
-	bool updateAllFace;
-	/**
-		@brief the number of the face to be updated
-	*/
-	unsigned char currentFace;
-	/**
-		@brief the resolution of the cubemap texture that was created by this run
-	*/
-	unsigned int resolution;
-	/**
-		@brief a flag to skip cube face update if object is far away or too small.
-
-		@see distTolerance
-	*/
-	bool useDistCalc;
-	/**
-		@brief a flag to skip cube face update the face is neglible.
-
-		@see angleTolerance
-	*/
-	bool useFaceAngleCalc;
-	/**
-		@brief A value used in face skip test.
-
-		The higher this value gets the more precise, but slower the method will be.
-	*/
-	float distTolerance;
-	/**
-		@brief A value used in face skip test.
-
-		The higher this value gets the more precise, but slower the method will be.
-	*/
-	float angleTolerance;
-
-	/**
-		@brief Creates a cubemap texture used for the color-cubemap.
-	*/
-	virtual inline void createDistanceCubeMap() = 0;
-	/**
-		@brief Updates one face of the cubemap.
-
-		@param facenum the number of the face to be updated
-	*/
-	virtual inline void updateCubeFace(int facenum) = 0;
-	/**
-		@brief Checks if a cubemap face needs to be updated.
-
-		If the object we are updating the cubemap for is far from the camera, or too small, or
-		the given cubemapface does not have significant effect on the rendering the face can be skipped.
-
-		@param facenum the number of the face to be checked
-	*/
-    virtual bool faceNeedsUpdate(int facenum) = 0; 
-	//inherited
-	virtual void updateFrame(unsigned long frameNum);	
-};
Index: P/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/ColorCubeMapRenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRuns/ColorCubeMapRenderingRun.h	(revision 780)
+++ 	(revision )
@@ -1,94 +1,0 @@
-#pragma once
-#include "RenderingRun.h"
-
-/**
-	@brief Base abstract class that defines a rendering process of a color-cubemap.
-
-	A color cubemap is a cubemap of the colors of the surrounding environment.
-*/
-class ColorCubeMapRenderingRun : virtual public RenderingRun
-{	
-public:
-	/**
-		@brief Constructor.
-
-		@param startFrame				adds an offset to the current frame number to help evenly distribute updates between frames
-		@param updateInterval			update frequency
-		@param resolution				color cubemap resolution
-		@param useDistCalc				flag to skip cube face update if object is far away
-		@param useFaceAngleCalc			flag to skip cube face update if face is neglible
-		@param distTolerance			distance tolerance used in face skip
-		@param angleTolerance			angle tolerance used in face skip
-		@param updateAllFace			defines if all cubemap faces should be updated in a frame or only one face per frame
-		
-	*/
-	ColorCubeMapRenderingRun(unsigned long startFrame,
-								unsigned long updateInterval,
-								unsigned int resolution,
-								bool useDistCalc,
-								bool useFaceAngleCalc,
-								float distTolerance,
-								float angleTolerance,
-								bool updateAllFace);
-
-	
-protected:
-	/**
-			@brief defines if all cubemap faces should be updated in a frame or only one face per frame
-	*/
-	bool updateAllFace;	
-	/**
-		@brief the number of the face to be updated
-	*/
-	unsigned char currentFace;	
-	/**
-		@brief the resolution of the cubemap texture that was created by this run
-	*/
-	unsigned int resolution;
-	/**
-		@brief a flag to skip cube face update if object is far away or too small.
-
-		@see distTolerance
-	*/
-	bool useDistCalc;
-	/**
-		@brief a flag to skip cube face update the face is neglible.
-
-		@see angleTolerance
-	*/
-	bool useFaceAngleCalc;
-	/**
-		@brief A value used in face skip test.
-
-		The higher this value gets the more precise, but slower the method will be.
-	*/
-	float distTolerance;
-	/**
-		@brief A value used in face skip test.
-
-		The higher this value gets the more precise, but slower the method will be.
-	*/
-	float angleTolerance;
-
-	/**
-		@brief Creates a cubemap texture used for the color-cubemap.
-	*/
-	virtual inline void createColorCubeMap() = 0;
-	/**
-		@brief Updates one face of the cubemap.
-
-		@param facenum the number of the face to be updated
-	*/
-	virtual inline void updateCubeFace(int facenum) = 0;
-	/**
-		@brief Checks if a cubemap face needs to be updated.
-
-		If the object we are updating the cubemap for is far from the camera, or too small, or
-		the given cubemapface does not have significant effect on the rendering the face can be skipped.
-
-		@param facenum the number of the face to be checked
-	*/
-    virtual bool faceNeedsUpdate(int facenum) = 0;
-	//inherited
-	virtual void updateFrame(unsigned long frameNum);	
-};
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/DistanceCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/DistanceCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/DistanceCubeMapRenderTechnique.h	(revision 1722)
@@ -33,4 +33,5 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
 							ElementaryRenderable* parentRenderable,
 							TechniqueGroup* parentTechniqueGroup
@@ -63,9 +64,4 @@
 	*/		
 	virtual void distanceCubeMapRunUpdated(RenderingRun* run) = 0;
-	/**
-			@brief Creates a ColorCubeMapRenderingRun.
-
-			@return the new ColorCubeMapRenderingRun instance.
-	*/
-	virtual RenderingRun* createDistanceCubeMapRun() = 0;
+	
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ColorCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ColorCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ColorCubeMapRenderTechnique.h	(revision 1722)
@@ -33,4 +33,5 @@
 								bool updateAllFace,
 								bool renderSelf,
+								bool renderEnvironment,
 								ElementaryRenderable* parentRenderable,
 								TechniqueGroup* parentTechniqueGroup
@@ -50,10 +51,4 @@
 protected:
 	
-	virtual void colorCubeMapRunChanged(RenderingRun* run) = 0;
-	/**
-			@brief Creates a ColorCubeMapRenderingRun.
-
-			@return the new ColorCubeMapRenderingRun instance.
-	*/
-	virtual RenderingRun* createColorCubeMapRun() = 0;
+	virtual void colorCubeMapRunChanged(RenderingRun* run) = 0;	
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ConvolvedCubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ConvolvedCubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/ConvolvedCubeMapRenderTechnique.h	(revision 1722)
@@ -37,4 +37,5 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
 							ElementaryRenderable* parentRenderable,
 							TechniqueGroup* parentTechniqueGroup
@@ -72,10 +73,4 @@
 			@return the new ColorCubeMapRenderingRun instance.
 	*/
-	virtual RenderingRun* createColorCubeMapRun() = 0;
-	/**
-			@brief Creates a ColorCubeMapRenderingRun.
-
-			@return the new ColorCubeMapRenderingRun instance.
-	*/
 	virtual RenderingRun* createReducedCubeMapRun() = 0;
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CubeMapRenderTechnique.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CubeMapRenderTechnique.h	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderTechniques/CubeMapRenderTechnique.h	(revision 1722)
@@ -33,4 +33,5 @@
 							bool updateAllFace,
 							bool renderSelf,
+							bool renderEnvironment,
 							ElementaryRenderable* parentRenderable,
 							TechniqueGroup* parentTechniqueGroup
@@ -38,4 +39,6 @@
 	~CubeMapRenderTechnique();
 	
+	void runChanged(RenderingRunType runType, RenderingRun* run);
+
 protected:
 	/**
@@ -79,4 +82,7 @@
 	*/
 	unsigned long startFrame;
-	bool renderSelf;		
+	bool renderSelf;
+	bool renderEnvironment;
+	virtual RenderingRun* createCubeMapRun() = 0;
+	virtual void cubeMapRunChanged(RenderingRun* run) = 0;	
 };
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h	(revision 1125)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/include/RenderingRun.h	(revision 1722)
@@ -44,4 +44,6 @@
 	*/
 	virtual class OgreRenderingRun* asOgreRenderingRun(){return 0;}
+	
+	virtual bool canJoin(RenderingRun* run){return true;}
 
 protected:
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/scripts/illummodule.vcproj
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/scripts/illummodule.vcproj	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/scripts/illummodule.vcproj	(revision 1722)
@@ -241,13 +241,9 @@
 				</File>
 				<File
-					RelativePath="..\src\RenderingRuns\ColorCubeMapRenderingRun.cpp"
+					RelativePath="..\src\RenderingRuns\CubeMapRenderingRun.cpp"
 					>
 				</File>
 				<File
 					RelativePath="..\src\RenderingRuns\DepthShadowMapRenderingRun.cpp"
-					>
-				</File>
-				<File
-					RelativePath="..\src\RenderingRuns\DistanceCubeMapRenderingRun.cpp"
 					>
 				</File>
@@ -358,13 +354,9 @@
 				</File>
 				<File
-					RelativePath="..\include\RenderingRuns\ColorCubeMapRenderingRun.h"
+					RelativePath="..\include\RenderingRuns\CubeMapRenderingRun.h"
 					>
 				</File>
 				<File
 					RelativePath="..\include\RenderingRuns\DepthShadowMapRenderingRun.h"
-					>
-				</File>
-				<File
-					RelativePath="..\include\RenderingRuns\DistanceCubeMapRenderingRun.h"
 					>
 				</File>
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/CubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/CubeMapRenderingRun.cpp	(revision 1722)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/CubeMapRenderingRun.cpp	(revision 1722)
@@ -0,0 +1,55 @@
+#include "CubeMapRenderingRun.h"
+
+
+
+CubeMapRenderingRun::CubeMapRenderingRun(unsigned long startFrame,
+													unsigned long updateInterval,
+													unsigned int resolution,
+													bool useDistCalc,
+													bool useFaceAngleCalc,
+													float distTolerance,
+													float angleTolerance,
+													bool updateAllFace,
+													bool renderSelf,
+													bool renderEnvironment)
+													:RenderingRun(startFrame, updateInterval)
+{
+	this->useDistCalc = useDistCalc;
+	this->useFaceAngleCalc = useFaceAngleCalc;
+	this->distTolerance = distTolerance;
+	this->angleTolerance = angleTolerance;
+	this->resolution = resolution;
+	this->updateAllFace = updateAllFace;
+	this->renderSelf = renderSelf;
+	this->renderEnvironment = renderEnvironment;
+
+	currentFace = 0;
+}
+
+void CubeMapRenderingRun::updateFrame(unsigned long frameNum)
+{
+	if(updateAllFace)
+	{
+		for(int i=0;i<6;i++)
+		{
+			updateCubeFace(i);
+		}
+	}
+	else
+	{
+		if(lastupdated == 0 && updateInterval == 0)
+		{
+			for(int i=0;i<6;i++)
+			{
+				updateCubeFace(i);
+			}
+		}
+		else
+		{
+			if(faceNeedsUpdate(currentFace))
+				updateCubeFace(currentFace);
+
+			currentFace = (currentFace + 1) % 6;
+		}
+	}
+}
Index: P/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/ColorCubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/ColorCubeMapRenderingRun.cpp	(revision 874)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#include "ColorCubeMapRenderingRun.h"
-
-
-
-ColorCubeMapRenderingRun::ColorCubeMapRenderingRun(unsigned long startFrame,
-														unsigned long updateInterval,
-														unsigned int resolution,
-													bool useDistCalc,
-													bool useFaceAngleCalc,
-													float distTolerance,
-													float angleTolerance,
-													bool updateAllFace)
-													:RenderingRun(startFrame, updateInterval)
-{
-	this->useDistCalc = useDistCalc;
-	this->useFaceAngleCalc = useFaceAngleCalc;
-	this->distTolerance = distTolerance;
-	this->angleTolerance = angleTolerance;
-	this->resolution = resolution;
-	this->updateAllFace = updateAllFace;
-
-	currentFace = 0;
-}
-
-void ColorCubeMapRenderingRun::updateFrame(unsigned long frameNum)
-{
-	if(updateAllFace)
-	{
-		for(int i=0;i<6;i++)
-		{
-			updateCubeFace(i);
-		}
-	}
-	else
-	{
-		if(lastupdated == 0 && updateInterval == 0)
-		{
-			for(int i=0;i<6;i++)
-			{
-				updateCubeFace(i);
-			}
-		}
-		else
-		{
-			if(faceNeedsUpdate(currentFace))
-				updateCubeFace(currentFace);
-
-			currentFace = (currentFace + 1) % 6;
-		}
-	}
-}
Index: P/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/DistanceCubeMapRenderingRun.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderingRuns/DistanceCubeMapRenderingRun.cpp	(revision 874)
+++ 	(revision )
@@ -1,51 +1,0 @@
-#include "DistanceCubeMapRenderingRun.h"
-
-
-
-DistanceCubeMapRenderingRun::DistanceCubeMapRenderingRun(unsigned long startFrame,
-														unsigned long updateInterval,
-														unsigned int resolution,
-														   bool useDistCalc,
-														   bool useFaceAngleCalc,
-														   float distTolerance,
-														   float angleTolerance,
-														   bool updateAllFace)
-														   :RenderingRun(startFrame, updateInterval)
-{
-	this->useDistCalc = useDistCalc;
-	this->useFaceAngleCalc = useFaceAngleCalc;
-	this->distTolerance = distTolerance;
-	this->angleTolerance = angleTolerance;
-	this->resolution = resolution;
-	this->updateAllFace = updateAllFace;
-
-	currentFace = 0;
-}
-
-void DistanceCubeMapRenderingRun::updateFrame(unsigned long frameNum)
-{
-	if(updateAllFace)
-	{
-		for(int i=0;i<6;i++)
-		{
-			updateCubeFace(i);
-		}
-	}
-	else
-	{
-		if(lastupdated == 0 && updateInterval == 0)
-		{
-			for(int i=0;i<6;i++)
-			{
-				updateCubeFace(i);
-			}
-		}
-		else
-		{
-			if(faceNeedsUpdate(currentFace))
-				updateCubeFace(currentFace);
-
-			currentFace = (currentFace + 1) % 6;
-		}
-	}
-}
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ColorCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ColorCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ColorCubeMapRenderTechnique.cpp	(revision 1722)
@@ -11,4 +11,5 @@
 															bool updateAllFace,
 															bool renderSelf,
+															bool renderEnvironment,
 															ElementaryRenderable* parentRenderable,
 															TechniqueGroup* parentTechniqueGroup)
@@ -16,5 +17,5 @@
 															:CubeMapRenderTechnique( startFrame, cubeMapUpdateInterval, cubeMapResolution,
 																					useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance,
-																					updateAllFace, renderSelf,
+																					updateAllFace, renderSelf, renderEnvironment,
 																					parentRenderable, parentTechniqueGroup),
 														     RenderTechnique(parentRenderable, parentTechniqueGroup)
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ConvolvedCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ConvolvedCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/ConvolvedCubeMapRenderTechnique.cpp	(revision 1722)
@@ -12,4 +12,5 @@
 												bool updateAllFace,
 												bool renderSelf,
+												bool renderEnvironment,
 												ElementaryRenderable* parentRenderable,
 												TechniqueGroup* parentTechniqueGroup)
@@ -17,5 +18,5 @@
 												:CubeMapRenderTechnique( startFrame, cubeMapUpdateInterval, cubeMapResolution,
 																					useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance,
-																					updateAllFace, renderSelf,
+																					updateAllFace, renderSelf, renderEnvironment,
 																					parentRenderable, parentTechniqueGroup),
 												RenderTechnique(parentRenderable, parentTechniqueGroup)
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/CubeMapRenderTechnique.cpp	(revision 1722)
@@ -11,4 +11,5 @@
 												bool updateAllFace,
 												bool renderSelf,
+												bool renderEnvironment,
 												ElementaryRenderable* parentRenderable,
 												TechniqueGroup* parentTechniqueGroup)
@@ -24,4 +25,11 @@
 	this->updateAllFace = updateAllFace;	
 	this->renderSelf = renderSelf;	
+	this->renderEnvironment = renderEnvironment;
+}
+
+void CubeMapRenderTechnique::runChanged(RenderingRunType runType, RenderingRun* run)
+{
+	if(runType == ILLUMRUN_CUBEMAP)
+		cubeMapRunChanged(run);
 }
 
Index: /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/DistanceCubeMapRenderTechnique.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/DistanceCubeMapRenderTechnique.cpp	(revision 1711)
+++ /GTP/trunk/Lib/Illum/IllumModule/IllumModule/src/RenderTechniques/DistanceCubeMapRenderTechnique.cpp	(revision 1722)
@@ -11,4 +11,5 @@
 												bool updateAllFace,
 												bool renderSelf,
+												bool renderEnvironment,
 												ElementaryRenderable* parentRenderable,
 												TechniqueGroup* parentTechniqueGroup)
@@ -16,5 +17,5 @@
 												:CubeMapRenderTechnique( startFrame, cubeMapUpdateInterval, cubeMapResolution,
 																					useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance,
-																					updateAllFace, renderSelf,
+																					updateAllFace, renderSelf, renderEnvironment,
 																					parentRenderable, parentTechniqueGroup),
 												 RenderTechnique(parentRenderable, parentTechniqueGroup)
