Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderingRuns/OgreCubeMapRenderingRun.h	(revision 1886)
@@ -49,4 +49,5 @@
 								 String selfMaterial,
 								 String environmentMaterial,
+								 bool getMinMax,
 								 RenderingRunType cubemapRunType);
 	/**
@@ -54,4 +55,7 @@
 	*/
 	String getCubeMapTextureName(){return name;}
+
+	Vector4 getMax(){return max;}
+	Vector4 getMin(){return min;}
 	
 protected:
@@ -74,6 +78,12 @@
 	bool useEnvMaterial;
 	RenderingRunType cubemapRunType;
+
+	Vector4 min;
+	Vector4 max;
+
+
+	bool getMinMax;
 	
-	
+	void getCubeMapMinMax();
 	//inherited
 	inline void createCubeMap();
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreDistanceCubeMapRenderTechnique.h	(revision 1886)
@@ -52,4 +52,8 @@
 							String environmentMaterial,
 							int layer,
+							bool getMinMax,
+							bool attachToTexUnit,
+							String minVariableName,
+							String maxVariableName,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreColorCubeMapRenderTechnique.h	(revision 1886)
@@ -52,4 +52,8 @@
 									String environmentMaterial,
 									int layer,
+									bool getMinMax,
+									bool attachToTexUnit,
+									String minVariableName,
+									String maxVariableName,
 									Pass* pass,
 									OgreRenderable* parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h	(revision 1722)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.h	(revision 1886)
@@ -53,4 +53,8 @@
 							String selfMaterial,
 							String environmentMaterial,
+							bool getMinMax,
+							bool attachToTexUnit,
+							String minVariableName,
+							String maxVariableName,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/include/RenderTechniques/OgreCubeMapRenderTechnique.h	(revision 1886)
@@ -52,4 +52,8 @@
 							String environmentMaterial,
 							int layer,
+							bool getMinMax,
+							bool attachToTexUnit,
+							String minVariableName,
+						    String maxVariableName,
 							Pass* pass,
 							OgreRenderable* parentRenderable,
@@ -72,4 +76,9 @@
 	String environmentMaterial;
 	String texturePostFix;
+
+	bool getMinMax;
+	bool attachToTexUnit;
+	String minVariableName;
+	String maxVariableName;
 
 	RenderingRun* createCubeMapRun();
@@ -104,3 +113,8 @@
 	String environmentMaterial;
 	int layer;
+
+	bool getMinMax;
+	bool attachToTexUnit;
+	String minVariableName;
+	String maxVariableName;
 };
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreCubeMapRenderingRun.cpp	(revision 1886)
@@ -17,5 +17,6 @@
 														   bool renderEnvironment,
 														   String selfMaterial,
-														   String environmentMaterial,														   
+														   String environmentMaterial,
+														   bool getMinMax,
 														   RenderingRunType cubemapRunType)
 														   :CubeMapRenderingRun(startFrame, updateInterval, resolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment)
@@ -24,4 +25,5 @@
 
 {
+	this->getMinMax = getMinMax;
 	this->cubemapRunType = cubemapRunType;
 	this->sharedRuns = sharedRuns;
@@ -124,4 +126,71 @@
 			root->restoreMaterial();
 	}
+
+	if(facenum == 5 && getMinMax)
+		getCubeMapMinMax();
+}
+
+void OgreCubeMapRenderingRun::getCubeMapMinMax()
+{
+    unsigned int buffersize = resolution * resolution * 4;
+	float* floatbuffer = new float[buffersize];
+	PixelBox lockBox(resolution, resolution, 1, PF_FLOAT32_RGBA, floatbuffer);
+	
+	float minX = 0;
+	float minY = 0;
+	float minZ = 0;
+	float minW = 0;
+	float maxX = 0;
+	float maxY = 0;
+	float maxZ = 0;
+	float maxW = 0;
+
+	bool first = true;
+		
+	for(int iFace = 0; iFace <6 ; iFace++)
+	{
+		this->cubemapTexture->getBuffer(iFace,0)->blitToMemory(lockBox);
+		
+		for(unsigned int i = 0; i < buffersize; i+= 4)
+		{
+			float x = floatbuffer[i];
+			float y = floatbuffer[i + 1];
+			float z = floatbuffer[i + 2];
+			float w = floatbuffer[i + 3];
+
+			if(first)
+			{
+				minX = x;
+				minY = y;
+				minZ = z;
+				minW = w;
+				maxX = x;
+				maxY = y;
+				maxZ = z;
+				maxW = w;				
+
+				first = false;
+			}
+			else if( (x * x + y * y + z * z + w * w) != 0)
+			{
+				if(x < minX)minX = x;
+				if(y < minY)minY = y;
+				if(z < minZ)minZ = z;
+				if(w < minW)minW = w;
+
+				if(x > maxX)maxX = x;
+				if(y > maxY)maxY = y;
+				if(z > maxZ)maxZ = z;
+				if(w > maxW)maxW = w;
+				
+			}
+		}
+	}
+	
+	min.x = minX; min.y = minY; min.z = minZ; min.w = minW;
+	max.x = maxX; max.y = maxY; max.z = maxZ; max.w = maxW;
+
+   
+	delete[] floatbuffer;
 }
 
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreColorCubeMapRenderTechnique.cpp	(revision 1886)
@@ -17,8 +17,12 @@
 														String environmentMaterial,
 														int layer,
+														bool getMinMax,
+														bool attachToTexUnit,
+														String minVariableName,
+														String maxVariableName,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
-															:OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, pass, parentRenderable, parentTechniqueGroup),
+														:OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, getMinMax, attachToTexUnit, minVariableName, maxVariableName, pass, parentRenderable, parentTechniqueGroup),
 															ColorCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
 															CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
@@ -75,8 +79,10 @@
 void OgreColorCubeMapRenderTechnique::colorCubeMapRunChanged(RenderingRun* run)
 {
-	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	OgreCubeMapRenderTechnique::cubeMapRunChanged(run);
+	/*OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
 	String cubemapname = cuberun->getCubeMapTextureName();
+		
+	pass->getTextureUnitState(texID)->setTextureName(cubemapname);*/
 	
-	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
 }
 
@@ -113,4 +119,8 @@
 													environmentMaterial,
 													layer,
+													getMinMax,
+												    attachToTexUnit,
+												    minVariableName,
+												    maxVariableName,
 													pass,
 													parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreConvolvedCubeMapRenderTechnique.cpp	(revision 1886)
@@ -18,9 +18,13 @@
 														String selfMaterial,
 														String environmentMaterial,
+														bool getMinMax,
+														bool attachToTexUnit,
+														String minVariableName,
+														String maxVariableName,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
 							:
-							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, pass, parentRenderable, parentTechniqueGroup),
+							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, getMinMax, attachToTexUnit, minVariableName, maxVariableName, pass, parentRenderable, parentTechniqueGroup),
 							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
 							ConvolvedCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, reducedCubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, parentRenderable, parentTechniqueGroup),
@@ -127,4 +131,8 @@
 												selfMaterial,
 												environmentMaterial,
+												getMinMax,
+												attachToTexUnit,
+												minVariableName,
+												maxVariableName,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCubeMapRenderTechnique.cpp	(revision 1886)
@@ -17,4 +17,8 @@
 														String environmentMaterial,
 														int layer,
+														bool getMinMax,
+														bool attachToTexUnit,
+														String minVariableName,
+														String maxVariableName,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
@@ -25,4 +29,9 @@
 							RenderTechnique(parentRenderable, parentTechniqueGroup) 
 {	
+	this->minVariableName = minVariableName;
+	this->maxVariableName = maxVariableName;
+	this->attachToTexUnit = attachToTexUnit;
+	this->getMinMax = getMinMax;
+
 	this->texID = texID;
 	this->selfMaterial = selfMaterial;
@@ -50,5 +59,13 @@
 	String cubemapname = cuberun->getCubeMapTextureName();
 	
-	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
+	if(attachToTexUnit)
+		pass->getTextureUnitState(texID)->setTextureName(cubemapname);
+	if(getMinMax)
+	{
+		if(minVariableName != "")
+			pass->getFragmentProgramParameters()->setNamedConstant(minVariableName, cuberun->getMin());
+		if(maxVariableName != "")
+			pass->getFragmentProgramParameters()->setNamedConstant(maxVariableName, cuberun->getMax());
+	}
 }
 
@@ -69,4 +86,5 @@
 												selfMaterial,
 												environmentMaterial,
+												getMinMax,
 												cubemapLayer);
 }
@@ -169,8 +187,32 @@
 		f->environmentMaterial =  params;
 	}
+
+	void parseMinVarName(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->minVariableName =  params;
+	}
+	void parseMaxVarName(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->maxVariableName =  params;
+	}
+
 	void parseLayer(String& params, RenderTechniqueFactory* factory)
 	{
 		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
 		f->layer =  StringConverter::parseInt(params);
+	}
+
+	void parseGetMinMax(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->getMinMax =  StringConverter::parseBool(params);
+	}
+
+	void parseAttachTexUnit(String& params, RenderTechniqueFactory* factory)
+	{
+		OgreCubeMapRenderTechniqueFactory* f = (OgreCubeMapRenderTechniqueFactory*) factory;
+		f->attachToTexUnit =  StringConverter::parseBool(params);
 	}
 
@@ -196,4 +238,8 @@
 	this->attributeParsers.insert(AttribParserList::value_type("env_material", (ILLUM_ATTRIBUTE_PARSER) parseEnvMaterial));
 	this->attributeParsers.insert(AttribParserList::value_type("layer", (ILLUM_ATTRIBUTE_PARSER) parseLayer));
+	this->attributeParsers.insert(AttribParserList::value_type("get_minmax", (ILLUM_ATTRIBUTE_PARSER) parseGetMinMax));
+	this->attributeParsers.insert(AttribParserList::value_type("attach_to_texture_unit", (ILLUM_ATTRIBUTE_PARSER) parseAttachTexUnit));
+	this->attributeParsers.insert(AttribParserList::value_type("min_var_name", (ILLUM_ATTRIBUTE_PARSER) parseMinVarName));
+	this->attributeParsers.insert(AttribParserList::value_type("max_var_name", (ILLUM_ATTRIBUTE_PARSER) parseMaxVarName));
 
 }
@@ -215,4 +261,9 @@
 	environmentMaterial = "";
 	layer = 0;
+	getMinMax = false;
+	attachToTexUnit = true;
+	minVariableName = "";
+	maxVariableName = "";
+
 }
 
@@ -241,4 +292,8 @@
 												environmentMaterial,
 												layer,
+												getMinMax,
+												attachToTexUnit,
+												minVariableName,
+												maxVariableName,
 												pass,
 												parentRenderable,
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreCausticCasterRenderTechnique.cpp	(revision 1886)
@@ -132,4 +132,5 @@
 										true,
 										"",
+										false,
 										"GameTools/DistanceShader",
 										ILLUMRUN_DISTANCE_CUBEMAP);
Index: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp
===================================================================
--- GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp	(revision 1725)
+++ GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderTechniques/OgreDistanceCubeMapRenderTechnique.cpp	(revision 1886)
@@ -17,9 +17,13 @@
 														String environmentMaterial,
 														int layer,
+														bool getMinMax,
+														bool attachToTexUnit,
+														String minVariableName,
+														String maxVariableName,
 														Pass* pass,
 														OgreRenderable* parentRenderable,
 														OgreTechniqueGroup* parentTechniqueGroup)
 							:
-							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, pass, parentRenderable, parentTechniqueGroup),
+							OgreCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, texID, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, selfMaterial, environmentMaterial, layer, getMinMax, attachToTexUnit, minVariableName, maxVariableName, pass, parentRenderable, parentTechniqueGroup),
 							CubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
 							DistanceCubeMapRenderTechnique(startFrame, cubeMapUpdateInterval, cubeMapResolution, useDistCalc, useFaceAngleCalc, distTolerance, angleTolerance, updateAllFace, renderSelf, renderEnvironment, layer, parentRenderable, parentTechniqueGroup),
@@ -69,8 +73,9 @@
 void OgreDistanceCubeMapRenderTechnique::distanceCubeMapRunChanged(RenderingRun* run)
 {
-	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
+	OgreCubeMapRenderTechnique::cubeMapRunChanged(run);
+/*	OgreCubeMapRenderingRun* cuberun =(OgreCubeMapRenderingRun*) (run->asOgreRenderingRun());
 	String cubemapname = cuberun->getCubeMapTextureName();
 	
-	pass->getTextureUnitState(texID)->setTextureName(cubemapname);
+	pass->getTextureUnitState(texID)->setTextureName(cubemapname);*/
 }
 
@@ -118,4 +123,8 @@
 												environmentMaterial,
 												layer,
+												getMinMax,
+												attachToTexUnit,
+												minVariableName,
+												maxVariableName,
 												pass,
 												parentRenderable,
