diff --git a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o
index 3ef87b8eedcb54cd508c46d473c701cb1b8b0ead..4431f8128689c72f9e8966ddd3c7e7d29264c483 100644
Binary files a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o and b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o differ
diff --git a/apps/specular_estimation/src/Ceres.h b/apps/specular_estimation/src/Ceres.h
index 63d02ba811b0fe70447b3f0e218e6283cde0c23f..e2b5d0d8e7bb9767856a42c29854f1b213d39c2e 100644
--- a/apps/specular_estimation/src/Ceres.h
+++ b/apps/specular_estimation/src/Ceres.h
@@ -17,25 +17,27 @@ using ceres::Problem;
 using ceres::Solver;
 using ceres::Solve;*/
 
-void specularMinimisation(double& SpecularIntensity, double& SpecularPower, double& Gain, double& Bias, std::string imageName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, double width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages);
+void specularMinimisation(double& SpecularIntensity, double& SpecularPower, double& Gain, double& Bias, std::string imageName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, double width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint DistancePowerID, GLuint LightPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages);
 void outputToFile(std::string outputFileName, double specularIntensity, double specularPower, double gain, double bias, double resiudal);
 
 class MyScalarCostFunctor {
 	public:
-		MyScalarCostFunctor(std::string outputFileName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages):outputFileName_(outputFileName), residualValue_(residualValue), residual_(residual), totalResidual_(totalResidual), residualImage_(residualImage), depthProjectionMatrix_(depthProjectionMatrix), depthViewMatrix_(depthViewMatrix), width_(width), height_(height), numberOfLights_(numberOfLights), SpecularIntensityID_(SpecularIntensityID), SpecularPowerID_(SpecularPowerID), programID_(programID), ModelMatrixID_(ModelMatrixID), ViewMatrixID_(ViewMatrixID), DepthBiasID_(DepthBiasID), lightInvDirID_(lightInvDirID), Texture_(Texture), TextureID_(TextureID), depthTexture_(depthTexture), ShadowMapID_(ShadowMapID), vertexbuffer_(vertexbuffer), uvbuffer_(uvbuffer), normalbuffer_(normalbuffer), elementbuffer_(elementbuffer), indices_(indices), MatrixID_(MatrixID), ModelMatrix_(ModelMatrix), MVP_(MVP), ViewMatrix_(ViewMatrix), depthBiasMVP_(depthBiasMVP), lightInvDirs_(lightInvDirs), textureImages_(textureImages){}
+		MyScalarCostFunctor(std::string outputFileName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint DistanceID, GLuint LightPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages):outputFileName_(outputFileName), residualValue_(residualValue), residual_(residual), totalResidual_(totalResidual), residualImage_(residualImage), depthProjectionMatrix_(depthProjectionMatrix), depthViewMatrix_(depthViewMatrix), width_(width), height_(height), numberOfLights_(numberOfLights), SpecularIntensityID_(SpecularIntensityID), SpecularPowerID_(SpecularPowerID), DistanceID_(DistanceID), LightPowerID_(LightPowerID), programID_(programID), ModelMatrixID_(ModelMatrixID), ViewMatrixID_(ViewMatrixID), DepthBiasID_(DepthBiasID), lightInvDirID_(lightInvDirID), Texture_(Texture), TextureID_(TextureID), depthTexture_(depthTexture), ShadowMapID_(ShadowMapID), vertexbuffer_(vertexbuffer), uvbuffer_(uvbuffer), normalbuffer_(normalbuffer), elementbuffer_(elementbuffer), indices_(indices), MatrixID_(MatrixID), ModelMatrix_(ModelMatrix), MVP_(MVP), ViewMatrix_(ViewMatrix), depthBiasMVP_(depthBiasMVP), lightInvDirs_(lightInvDirs), textureImages_(textureImages){}
 
 		bool operator()(const double* const SpecularIntensity, const double* const SpecularPower, const double* const Gain, const double* const Bias, double* residualValue) const {
 			
 			double specularIntensity = double(SpecularIntensity[0]);
 			double specularPower     = double(SpecularPower[0]);
-			double gain 			 = double(Gain[0]);
-			double bias     		 = double(Bias[0]);
+			double distance 	     = double(Gain[0]);
+			double lightPower     	 = double(Bias[0]);
+			double gain 	         = 1.0;
+			double bias     	     = 0.0;
 			
 			double sum = 0;
 			
 			for (int i = 0; i < numberOfLights_; i++) {
 				// Render the polygons
-				renderPolygons(width_, height_, programID_, lightInvDirs_[i], MatrixID_, ModelMatrixID_, ViewMatrixID_, DepthBiasID_, lightInvDirID_, Texture_, TextureID_, depthTexture_, ShadowMapID_, vertexbuffer_, uvbuffer_, normalbuffer_, elementbuffer_, indices_, MVP_, ModelMatrix_, ViewMatrix_, depthBiasMVP_, SpecularIntensityID_, specularIntensity, SpecularPowerID_, specularPower);
+				renderPolygons(width_, height_, programID_, lightInvDirs_[i], MatrixID_, ModelMatrixID_, ViewMatrixID_, DepthBiasID_, lightInvDirID_, Texture_, TextureID_, depthTexture_, ShadowMapID_, vertexbuffer_, uvbuffer_, normalbuffer_, elementbuffer_, indices_, MVP_, ModelMatrix_, ViewMatrix_, depthBiasMVP_, SpecularIntensityID_, specularIntensity, SpecularPowerID_, specularPower, DistanceID_, distance, LightPowerID_, lightPower);
 				
 				// Calculate the residual
 				meanSquaredError(i, height_, width_, textureImages_, sum, gain, bias);
@@ -80,6 +82,8 @@ class MyScalarCostFunctor {
 		glm::mat4 depthBiasMVP_;
 		GLuint SpecularIntensityID_;
 		GLuint SpecularPowerID_;
+		GLuint DistanceID_;
+		GLuint LightPowerID_;
 		
 		double residualValue_;
 		cv::Vec3d residual_;
@@ -94,7 +98,7 @@ class MyScalarCostFunctor {
 		std::string outputFileName_;
 };
 
-void specularMinimisation(double& SpecularIntensity, double& SpecularPower, double& Gain, double& Bias, std::string imageName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages) {
+void specularMinimisation(double& SpecularIntensity, double& SpecularPower, double& Gain, double& Bias, std::string imageName, double residualValue, cv::Vec3d residual, double totalResidual, cv::Mat residualImage, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, int numberOfLights, GLuint SpecularIntensityID, GLuint SpecularPowerID, GLuint DistanceID, GLuint LightPowerID, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, glm::mat4 ModelMatrix, glm::mat4 MVP, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, std::vector<glm::vec3> lightInvDirs, std::vector<cv::Mat> textureImages) {
 	
 	// The variable to solve for with its initial value. It will be mutated in place by the solver.
 	const double initialSpecularIntensity = SpecularIntensity;
@@ -114,22 +118,24 @@ void specularMinimisation(double& SpecularIntensity, double& SpecularPower, doub
 
 	// Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian).
 	// AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)>
-	ceres::CostFunction* cost_function = new NumericDiffCostFunction<MyScalarCostFunctor, CENTRAL, 1, 1, 1, 1, 1>(new MyScalarCostFunctor(outputFileName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages));
+	ceres::CostFunction* cost_function = new NumericDiffCostFunction<MyScalarCostFunctor, CENTRAL, 1, 1, 1, 1, 1>(new MyScalarCostFunctor(outputFileName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages));
 	std::vector<ceres::ResidualBlockId> residual_block_ids;
 	ceres::ResidualBlockId block_id = problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower, &Gain, &Bias);
 	residual_block_ids.push_back(block_id);
 
 	problem.SetParameterLowerBound(&SpecularIntensity, 0, 0);
 	problem.SetParameterUpperBound(&SpecularIntensity, 0, 1);
-	problem.SetParameterLowerBound(&SpecularPower, 0, 0.01);
-	problem.SetParameterLowerBound(&Gain, 0, 0);
-	problem.SetParameterUpperBound(&Gain, 0, 2);
+	problem.SetParameterLowerBound(&SpecularPower, 0, 0);
+	problem.SetParameterUpperBound(&SpecularPower, 0, 1);
+	//problem.SetParameterLowerBound(&SpecularPower, 0, 0.01);
+	//problem.SetParameterLowerBound(&Gain, 0, 0);
+	//problem.SetParameterUpperBound(&Gain, 0, 2);
 	//problem.SetParameterBlockConstant(&Gain);
 	//problem.SetParameterBlockConstant(&Bias);
-	/*problem.SetParameterLowerBound(&Gain, 0, 0);
-	problem.SetParameterUpperBound(&Gain, 0, 2);
-	problem.SetParameterLowerBound(&Bias, 0, -1);
-	problem.SetParameterUpperBound(&Bias, 0, 1);*/
+	problem.SetParameterLowerBound(&Gain, 0, 0);
+	//problem.SetParameterUpperBound(&Gain, 0, 2);
+	problem.SetParameterLowerBound(&Bias, 0, 0);
+	//problem.SetParameterUpperBound(&Bias, 0, 1);
 	
 	// Run the solver
 	Solver::Options options;
diff --git a/apps/specular_estimation/src/OpenGL.h b/apps/specular_estimation/src/OpenGL.h
index e963baa050f6727c5c81def5809493247dbf4a15..88fc0d7560c51cd9faa94c81f64b10536048598b 100644
--- a/apps/specular_estimation/src/OpenGL.h
+++ b/apps/specular_estimation/src/OpenGL.h
@@ -40,34 +40,28 @@ using ceres::Problem;
 using ceres::Solver;
 using ceres::Solve;
 
-void computeMatricesFromInputs(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, float mouseSpeed, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, bool& shadowControl, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, bool& calculateResidual);
-void computeMatricesFromLights(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, cv::Mat lightDirections, int& lightNumber, int numberOfLights, bool& calculateResidual, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower);
+void computeMatricesFromInputs(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, float mouseSpeed, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, bool& shadowControl, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, bool& calculateResidual);
+void computeMatricesFromLights(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, cv::Mat lightDirections, int& lightNumber, int numberOfLights, bool& calculateResidual, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
 void createSphere(int lats, int longs);
 void createMesh(cv::Mat Z, cv::Mat normals, std::vector<glm::vec3>& out_vertices, std::vector<glm::vec2> & out_uvs, std::vector<glm::vec3> & out_normals, std::vector<unsigned int> & out_indices);
 GLuint loadMat(cv::Mat cv_texture);
-void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix);
-//void openGL(int& lightNumber, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector< cv::Mat > textureImages, GLuint programID, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint depthProgramID, GLuint quad_programID, GLuint FramebufferName, GLuint quad_vertexbuffer, GLuint VertexArrayID, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, bool& calculateResidual);
+void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix);
+//void openGL(int& lightNumber, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector< cv::Mat > textureImages, GLuint programID, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint depthProgramID, GLuint quad_programID, GLuint FramebufferName, GLuint quad_vertexbuffer, GLuint VertexArrayID, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, bool& calculateResidual);
 void terminateOpenGL(GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, GLuint programID, GLuint depthProgramID, GLuint quad_programID, GLuint Texture, GLuint FramebufferName, GLuint depthTexture, GLuint quad_vertexbuffer, GLuint VertexArrayID);
-void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower);
+void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower, GLuint DistanceID, double Distance, GLuint LightPowerID, double LightPower);
 void renderShadows(GLuint FramebufferName, int shadowResolution, GLuint depthProgramID, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, GLuint depthMatrixID, GLuint vertexbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 depthModelMatrix, glm::mat4 depthMVP);
 void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, GLuint quad_vertexbuffer);
-//void meanSquaredError(int imageNumber, int windowHeight, int windowWidth, std::string modelPath, std::vector < cv::Mat > textureImages, cv::Mat& residual, cv::Vec3d& residuals, double& sum, double SpecularIntensity, double SpecularPower);
+//void meanSquaredError(int imageNumber, int windowHeight, int windowWidth, std::string modelPath, std::vector < cv::Mat > textureImages, cv::Mat& residual, cv::Vec3d& residuals, double& sum, double SpecularIntensity, double SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
 void meanSquaredError(int imageNumber, int windowHeight, int windowWidth, std::vector<cv::Mat> textureImages, double& sum, double gain, double bias);
 void structuralSimilarityIndex(int imageNumber, int windowHeight, int windowWidth, std::vector<cv::Mat> textureImages, double& sum, double gain, int bias);
-double returnResidual(int imageNumber, int windowHeight, int windowWidth, std::vector<cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double SpecularIntensity, double SpecularPower);
-//void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
-void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
-void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
+double returnResidual(int imageNumber, int windowHeight, int windowWidth, std::vector<cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double SpecularIntensity, double SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
+//void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
+void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
+void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
 void checkForErrors(std::string stage, bool printIfOK);
 void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture);
 
-void initialiseOpenGLCT(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix);
-void renderPolygonsCT(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower);
-void terminateOpenGLCT(GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, GLuint programID, GLuint depthProgramID, GLuint quad_programID, GLuint Texture, GLuint FramebufferName, GLuint depthTexture, GLuint quad_vertexbuffer, GLuint VertexArrayID);
-void viewModelCT(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
-void RenderSyntheticCT(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath);
-
-void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix) {
+void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix) {
 	// Initialise the GLFW library first
 	if (!glfwInit()) {
 		std::cerr << "Failed to initialise GLFW.\n";
@@ -240,6 +234,8 @@ void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture,
 	
 	SpecularIntensityID = glGetUniformLocation(programID, "specularIntensity");
 	SpecularPowerID = glGetUniformLocation(programID, "specularPower");
+	DistanceID = glGetUniformLocation(programID, "distance");
+	LightPowerID = glGetUniformLocation(programID, "lightPower");
 
 	// Get a handle for the "MVP" uniform
 	MatrixID = glGetUniformLocation(programID, "MVP");
@@ -272,7 +268,7 @@ void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture,
 	int lightNumber = 0;
 
 	// Compute the MVP matrix
-	computeMatricesFromLights(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+	computeMatricesFromLights(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 	
 	MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
 	depthBiasMVP = biasMatrix * depthMVP;
@@ -375,7 +371,7 @@ void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, G
 	glDisableVertexAttribArray(0);
 }
 
-void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower) {
+void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower, GLuint DistanceID, double Distance, GLuint LightPowerID, double LightPower) {
 
 	// Render to the screen
 	glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -398,6 +394,8 @@ void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::ve
 	
 	glUniform1f(SpecularIntensityID, SpecularIntensity);
 	glUniform1f(SpecularPowerID,     SpecularPower);
+	glUniform1f(DistanceID,          Distance);
+	glUniform1f(LightPowerID,        LightPower);
 
 	glUniform3f(lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z);
 
@@ -497,7 +495,7 @@ void renderPolygons(int windowWidth, int windowHeight, GLuint programID, glm::ve
 	}
 }*/
 
-/*void meanSquaredError(int imageNumber, int windowHeight, int windowWidth, std::string modelPath, std::vector <cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double& sum, double SpecularIntensity, double SpecularPower) {
+/*void meanSquaredError(int imageNumber, int windowHeight, int windowWidth, std::string modelPath, std::vector <cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double& sum, double SpecularIntensity, double SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower) {
 	
 	// Create an empty Mat the same size as the image
 	cv::Mat temp = cv::Mat(windowHeight, windowWidth, CV_8UC3);
@@ -615,7 +613,7 @@ void structuralSimilarityIndex(int imageNumber, int windowHeight, int windowWidt
 	sum += 3 - getMSSIM(temp, textureImages[imageNumber]);
 }
 
-double returnResidual(int imageNumber, int windowHeight, int windowWidth, std::vector <cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double SpecularIntensity, double SpecularPower) {
+double returnResidual(int imageNumber, int windowHeight, int windowWidth, std::vector <cv::Mat> textureImages, cv::Mat& residual, cv::Vec3d& residuals, double SpecularIntensity, double SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower) {
 		
 	// Create an empty Mat the same size as the image
 	cv::Mat temp = cv::Mat(windowHeight, windowWidth, CV_8UC3);
@@ -655,7 +653,7 @@ double returnResidual(int imageNumber, int windowHeight, int windowWidth, std::v
 	return sum;
 }
 /*
-void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector< cv::Mat > textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
+void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector< cv::Mat > textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, , GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPowerGLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
 	do {
 		// Render the shadows
 		glm::mat4 depthModelMatrix = glm::mat4(1.0);
@@ -666,8 +664,8 @@ void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals,
 		glm::mat4 ModelMatrix = glm::mat4(1.0);
 		glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix;
 		bool perspectiveProjection, shadowControl;
-		//computeMatricesFromInputs(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection = false, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		//computeMatricesFromInputs(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
+		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection = false, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
 		MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
 
 		glm::mat4 biasMatrix(
@@ -681,21 +679,21 @@ void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals,
 		
 			
 		// Render the polygons
-		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
 		
 		// Optionally render the shadowmap (for debug only)
 		//void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, GLuint quad_vertexbuffer);
 		
 		
 		
-		//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower);
-		meanSquaredError(lightNumber, height, width, modelPath, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower);
+		//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
+		meanSquaredError(lightNumber, height, width, modelPath, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower);
 		residuals.push_back(residual);
 		
 		// Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian).
 		// AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)>
 		//CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 2>(new CostFunctor);
-		//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower);
+		//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower, &Distance, &LightPower);
 		
 		// Swap buffers
 		glfwSwapBuffers(window);
@@ -716,7 +714,7 @@ void computeResiduals(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals,
 	lightNumber = 0;
 }
 */
-void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
+void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
 	do {
 		// Render the shadows
 		glm::mat4 depthModelMatrix = glm::mat4(1.0);
@@ -728,8 +726,8 @@ void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImag
 		glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix;
 		bool perspectiveProjection = false, shadowControl;
 		//float mouseSpeed = 0.005f;
-		//computeMatricesFromInputs(width, height, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, calculateResidual);
-		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		//computeMatricesFromInputs(width, height, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPowercalculateResidual);
+		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 		MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
 
 		glm::mat4 biasMatrix(
@@ -743,7 +741,7 @@ void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImag
 		
 			
 		// Render the polygons
-		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 		
 		// Optionally render the shadowmap (for debug only)
 		//void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, GLuint quad_vertexbuffer);
@@ -752,7 +750,7 @@ void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImag
 			double sum = 0, gain = 0;
 			int bias = 0;
 			meanSquaredError(lightNumber, height, width, textureImages, sum, gain, bias);
-			//computeResiduals(residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+			//computeResiduals(residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 			std::cout << "Light number: " << lightNumber << ", per-pixel residual = " << totalResidual << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl;
 		}
 		
@@ -762,21 +760,21 @@ void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImag
 		if (calculateResidual) {
 			// Compute the residual image and sum of differences
 			cv::Mat residualImage;
-			meanSquaredError(lightNumber, height, width, textureImages, residualImage, residuals, residual, SpecularIntensity, SpecularPower);
+			meanSquaredError(lightNumber, height, width, textureImages, residualImage, residuals, residual, SpecularIntensity, SpecularPower, Distance, LightPower);
 			
-			specularMinimisation(SpecularIntensity, SpecularPower, residual);
+			specularMinimisation(SpecularIntensity, SpecularPower, Distance, LightPower, residual);
 			calculateResidual = false;
 		}
 		*/
 		
-		//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower);
-		//meanSquaredError(lightNumber, height, width, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower);
+		//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower, Distance, LightPower);
+		//meanSquaredError(lightNumber, height, width, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower, Distance, LightPower);
 		//residuals.push_back(residual);
 		
 		// Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian).
 		// AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)>
 		//CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 2>(new CostFunctor);
-		//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower);
+		//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower, &Distance, &LightPower);
 		
 		// Swap buffers
 		glfwSwapBuffers(window);
@@ -784,7 +782,7 @@ void viewModel(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImag
 	} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
 }
 
-void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
+void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
 	for(int lightNumber = 0; lightNumber < numberOfLights; lightNumber++) {
 		// Render the shadows
 		glm::mat4 depthModelMatrix = glm::mat4(1.0);
@@ -794,7 +792,7 @@ void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix,
 		glm::mat4 ModelMatrix = glm::mat4(1.0);
 		glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix;
 		bool perspectiveProjection = false, shadowControl, calculateResidual = false;
-		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 		MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
 
 		glm::mat4 biasMatrix(
@@ -807,7 +805,7 @@ void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix,
 		depthBiasMVP = biasMatrix * depthMVP;
 		
 		// Render the polygons
-		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 		
 		// Create an empty Mat the same size as the image
 		cv::Mat temp = cv::Mat(height, width, CV_8UC3);
@@ -822,15 +820,19 @@ void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix,
 		temp = AddGaussianNoise_Opencv(temp, 0, 0.001);
 		textureImages.push_back(temp);
 
-		std::ostringstream a, b, c;
+		std::ostringstream a, b, c, d, e;
 		a << lightNumber;
 		b << SpecularIntensity;
 		c << SpecularPower;
+		d << Distance;
+		e << LightPower;
 		std::string imageNumber = a.str();
 		std::string specularIntensity = b.str();
 		std::string specularPower = c.str();
+		std::string distance = d.str();
+		std::string lightPower = e.str();
 
-		//cv::imwrite(modelPath + "Intensity" + specularIntensity + "Power" + specularPower + imageNumber + ".png", temp);
+		//cv::imwrite(modelPath + "Intensity " + specularIntensity + " Power " + specularPower + " Distance " + distance + " Light Power " + lightPower + " " + imageNumber + ".png", temp);
 		cv::imwrite(modelPath + imageNumber + ".png", temp);
 
 		// Swap buffers
@@ -839,7 +841,7 @@ void RenderSynthetic(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix,
 	} //while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
 }
 
-void computeMatricesFromLights(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, cv::Mat lightDirections, int& lightNumber, int numberOfLights, bool& calculateResidual, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower) {
+void computeMatricesFromLights(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, cv::Mat lightDirections, int& lightNumber, int numberOfLights, bool& calculateResidual, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower) {
 	
 	calculateResidual = false;
 	
@@ -967,7 +969,7 @@ void computeMatricesFromLights(int windowWidth, int windowHeight, glm::vec3& pos
 	}*/
 }
 
-void computeMatricesFromInputs(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, float mouseSpeed, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, bool& shadowControl, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, bool& calculateResidual) {
+void computeMatricesFromInputs(int windowWidth, int windowHeight, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, float mouseSpeed, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::vec3& lightInvDir, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, bool& perspectiveProjection, bool& shadowControl, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint& DistanceID, double& Distance, GLuint& LightPowerID, double& LightPower, bool& calculateResidual) {
 
 	calculateResidual = false;
 
@@ -1509,6 +1511,8 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) {
 	
 	GLuint SpecularIntensityID = glGetUniformLocation(programID, "specularIntensity");
 	GLuint SpecularPowerID = glGetUniformLocation(programID, "specularPower");
+	GLuint DistanceID = glGetUniformLocation(programID, "distance");
+	GLuint LightPowerID = glGetUniformLocation(programID, "lightPower");
 	
 	// Get a handle for our "MVP" uniform
 	GLuint MatrixID = glGetUniformLocation(programID, "MVP");
@@ -1541,7 +1545,7 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) {
 
 	glm::mat4 ViewMatrix, ProjectionMatrix;
 
-	double SpecularIntensity = 0.5, SpecularPower = 2;
+	double SpecularIntensity = 0.5, SpecularPower = 2, Distance = 1.0, LightPower = 1.0;
 
 	do {
 		// Render to our framebuffer
@@ -1620,10 +1624,10 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) {
 		
 
 		// Compute the MVP matrix from keyboard and mouse input
-		computeMatricesFromInputs(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, calculateResidual);
+		computeMatricesFromInputs(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, calculateResidual);
 		//glm::mat4 ProjectionMatrix = getProjectionMatrix();
 		//glm::mat4 ViewMatrix = getViewMatrix();
-		//computeMatricesFromLights(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+		//computeMatricesFromLights(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 		//ViewMatrix = glm::lookAt(glm::vec3(14,6,4), glm::vec3(0,1,0), glm::vec3(0,1,0));
 		glm::mat4 ModelMatrix = glm::mat4(1.0);
 		glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
@@ -1646,6 +1650,8 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) {
 
 		glUniform1f(SpecularIntensityID, SpecularIntensity);
 		glUniform1f(SpecularPowerID,     SpecularPower);
+		glUniform1f(DistanceID,          Distance);
+		glUniform1f(LightPowerID,        LightPower);
 
 		glUniform3f(lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z);
 
@@ -1769,1217 +1775,4 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) {
 	glfwTerminate();
 }
 
-/*
-class OpenGL {
-	public:		
-		OpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, std::vector<cv::Mat> textureImages, int windowWidth, int windowHeight, const std::string modelPath, const std::string sourcePath) {
-			// Initialise the GLFW library first
-			if (!glfwInit()) {
-				std::cerr << "Failed to initialise GLFW.\n";
-				getchar();
-				return;
-			}
-			std::cout << "Initialised GLFW.\n";
-			
-			glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
-			glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
-			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // OpenGL 3.3
-			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
-			glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Only needed for macOS
-			glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Disable old OpenGL
-			
-			// Set the shadow resolution to 4096x4096
-			int shadowResolution = 4096;
-
-			// Open a window and create its OpenGL context
-			window = glfwCreateWindow(windowWidth, windowHeight, "Window", NULL, NULL);
-			if (window == NULL) {
-				std::cerr << "Failed to open GLFW window. Older Intel GPUs are not OpenGL 3.3 compatible.\n";
-				getchar();
-				glfwTerminate();
-				return;
-			}
-			glfwMakeContextCurrent(window);
-			std::cout << "Opened GLFW window.\n";
-
-			// On macOS with a retina screen it will be windowWidth*2 and windowHeight*2, so the actual framebuffer size is:
-			glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
-
-			// Initialize GLEW
-			glewExperimental = true; // Needed for core profile
-			if (glewInit() != GLEW_OK) {
-				std::cerr << "Failed to initialise GLEW.\n";
-				getchar();
-				glfwTerminate();
-				return;
-			}
-			std::cout << "Initialised GLEW.\n";
-
-			// Ensure that the escape key being pressed can be captured
-			glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
-			// Hide the mouse and enable unlimited movement
-			glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
-
-			// Set the mouse at the center of the screen
-			glfwPollEvents();
-			//glfwSetCursorPos(window, windowWidth / 2, windowHeight / 2);
-
-			// Dark blue background
-			glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
-
-			// Enable depth test, which stores fragments in the Z-buffer
-			glEnable(GL_DEPTH_TEST);
-
-			checkForErrors("Depth Test Enabled", true);
-
-			// Accept fragment if it is closer to the camera than the former one
-			glDepthFunc(GL_LESS);
-
-			// Cull triangles which do not have a normal facing towards the camera
-			glEnable(GL_CULL_FACE);
-
-			// Create a Vertex Array Object (VAO) and set it as the current one
-			//GLuint VertexArrayID;
-			glGenVertexArrays(1, &VertexArrayID);
-			glBindVertexArray(VertexArrayID);
-
-			// Create and compile the GLSL program from the shaders
-			//const std::string depthRTTVertexShaderPath = sourcePath + "DepthRTT.vertexshader";
-			//const std::string depthRTTFragmentShaderPath = sourcePath + "DepthRTT.fragmentshader";
-			//depthProgramID = LoadShaders(depthRTTVertexShaderPath, depthRTTFragmentShaderPath);
-			depthProgramID = LoadShaders("/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/DepthRTT.vertexshader", "/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/DepthRTT.fragmentshader");
-
-			// Get a handle for the "MVP" uniform
-			GLuint depthMatrixID = glGetUniformLocation(depthProgramID, "depthMVP");
-
-			// Load the texture
-			//GLuint Texture = loadDDS("C:/Users/tdwal/Documents/repos/OpenGLTutorials/tutorial16_shadowmaps/uvmap.DDS");
-			Texture = loadMat();
-			std::cout << "Texture loaded.\n\n";
-
-			// Read the .obj file
-			//bool res = loadOBJ("C:/Users/tdwal/Documents/repos/OpenGLTutorials/tutorial16_shadowmaps/room_thickwalls.obj", vertices, uvs, normals);
-			createMesh(cv_normals, cv_depth);
-			std::cout << "Model created.\n\n";
-
-			// Load it into a VBO
-			//GLuint vertexbuffer; // This will identify the vertex buffer
-			glGenBuffers(1, &vertexbuffer); // Generate 1 buffer, and put the resulting identifier in vertexbuffer
-			glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // The following commands will talk about our 'vertexbuffer' buffer
-			glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW); // Give the vertices to OpenGL
-
-			//GLuint uvbuffer;
-			glGenBuffers(1, &uvbuffer);
-			glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
-			glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
-
-			//GLuint normalbuffer;
-			glGenBuffers(1, &normalbuffer);
-			glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
-			glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);
-
-			// Generate a buffer for the indices as well
-			//GLuint elementbuffer;
-			glGenBuffers(1, &elementbuffer);
-			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
-			glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
-
-			
-			// ---------------------------------------------
-			// Render to Texture - specific code begins here
-			// ---------------------------------------------
-
-			// The framebuffer, which regroups 0, 1 or more textures, and 0 or 1 depth buffers
-			FramebufferName = 0;
-			glGenFramebuffers(1, &FramebufferName);
-			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
-
-			// Depth texture. Slower than a depth buffer, but can be sampled later in the shader
-			//GLuint depthTexture;
-			glGenTextures(1, &depthTexture);
-			glBindTexture(GL_TEXTURE_2D, depthTexture);
-			glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowResolution, shadowResolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
-
-			glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0);
-
-			// No colour output in the bound framebuffer, only depth.
-			glDrawBuffer(GL_NONE);
-
-			// Always check if there are any errors in the framebuffer
-			if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-				return;
-
-			// The quad's FBO. Used only for visualising the shadowmap.
-			static const GLfloat g_quad_vertex_buffer_data[] = {
-				-1.0f, -1.0f, 0.0f,
-				 1.0f, -1.0f, 0.0f,
-				-1.0f,  1.0f, 0.0f,
-				-1.0f,  1.0f, 0.0f,
-				 1.0f, -1.0f, 0.0f,
-				 1.0f,  1.0f, 0.0f,
-			};
-
-			//GLuint quad_vertexbuffer;
-			glGenBuffers(1, &quad_vertexbuffer);
-			glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
-			glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW);
-			
-			// Create and compile the GLSL program from the shaders
-			quad_programID = LoadShaders("/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/Passthrough.vertexshader", "/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/SimpleTexture.fragmentshader");
-			//std::cout << "Shaders loaded.\n";
-			texID = glGetUniformLocation(quad_programID, "myTexture");
-			//std::cout << "Uniform Location of texture found.\n";
-			
-			// Create and compile the GLSL program from the shaders
-			//const std::string shadowMappingVertexShaderPath = sourcePath + "ShadowMapping.vertexshader";
-			//const std::string shadowMappingFragmentShaderPath = sourcePath + "ShadowMapping.fragmentshader";
-			//programID = LoadShaders(shadowMappingVertexShaderPath, shadowMappingFragmentShaderPath);
-			programID = LoadShaders("/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/ShadowMapping.vertexshader", "/user/HS222/tw00275/PhD/Minimisation/apps/specular_estimation/src/ShadowMapping.fragmentshader");
-			
-			// Get a handle for the "myTextureSampler" uniform
-			TextureID = glGetUniformLocation(programID, "myTextureSampler");
-			//SpecularID = glGetUniformLocation(programID, "mySpecularSampler");
-			
-			SpecularIntensityID = glGetUniformLocation(programID, "specularIntensity");
-			SpecularPowerID = glGetUniformLocation(programID, "specularPower");
-
-			// Get a handle for the "MVP" uniform
-			MatrixID = glGetUniformLocation(programID, "MVP");
-			ViewMatrixID = glGetUniformLocation(programID, "V");
-			ModelMatrixID = glGetUniformLocation(programID, "M");
-			DepthBiasID = glGetUniformLocation(programID, "DepthBiasMVP");
-			ShadowMapID = glGetUniformLocation(programID, "shadowMap");
-
-			// Get a handle for the "LightPosition" uniform
-			lightInvDirID = glGetUniformLocation(programID, "LightInvDirection_worldspace");
-
-			// Compute the MVP matrix from the light's point of view
-			lightInvDir = glm::vec3(0, 0, 1);
-			//lightInvDir = glm::vec3(lightDirections.at<float>(0, 1), -lightDirections.at<float>(0, 0), lightDirections.at<float>(0, 2));
-			depthProjectionMatrix = glm::perspective<float>(45.0f, 1.0f, 1.0f, 100.0f);
-			depthViewMatrix = glm::lookAt(lightInvDir, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
-
-			// Initial position: on +Z
-			position = glm::vec3(0, 0, 1);
-			// Initial horizontal angle: toward -Z
-			horizontalAngle = M_PI;
-			// Initial vertical angle: none
-			verticalAngle = 0.0f;
-			// Initial Field of View
-			FoV = 60.0f;
-			
-			std::cout << "Initialised OpenGL\n";
-		}
-		
-		~OpenGL() {
-			// Cleanup VBO and shader
-			glDeleteBuffers(1, &vertexbuffer);
-			glDeleteBuffers(1, &uvbuffer);
-			glDeleteBuffers(1, &normalbuffer);
-			glDeleteBuffers(1, &elementbuffer);
-			glDeleteProgram(programID);
-			glDeleteProgram(depthProgramID);
-			glDeleteProgram(quad_programID);
-			glDeleteTextures(1, &Texture);
-
-			glDeleteFramebuffers(1, &FramebufferName);
-			glDeleteTextures(1, &depthTexture);
-			glDeleteBuffers(1, &quad_vertexbuffer);
-			glDeleteVertexArrays(1, &VertexArrayID);
-
-			// Close OpenGL window and terminate GLFW
-			glfwTerminate();
-		}
-	
-		void renderPolygons(double SpecularIntensity, double SpecularPower) {
-			
-			//std::cout << "Rendering polygons...\n";
-			
-			// Render to the screen
-			glBindFramebuffer(GL_FRAMEBUFFER, 0);
-			glViewport(0, 0, windowWidth, windowHeight); // Render on the whole framebuffer, complete from the lower left corner to the upper right
-
-			glEnable(GL_CULL_FACE);
-			glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
-
-			// Clear the screen
-			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-			// Use the shader
-			glUseProgram(programID);
-			
-			// Send the transformation to the currently bound shader, in the "MVP" uniform
-			glUniformMatrix4fv(MatrixID,      1, GL_FALSE, &MVP[0][0]);
-			glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
-			glUniformMatrix4fv(ViewMatrixID,  1, GL_FALSE, &ViewMatrix[0][0]);
-			glUniformMatrix4fv(DepthBiasID,   1, GL_FALSE, &depthBiasMVP[0][0]);
-			
-			glUniform1f(SpecularIntensityID, SpecularIntensity);
-			glUniform1f(SpecularPowerID,     SpecularPower);
-
-			glUniform3f(lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z);
-
-			// Bind the texture in Texture Unit 0
-			glActiveTexture(GL_TEXTURE0);
-			glBindTexture(GL_TEXTURE_2D, Texture);
-			// Set the "myTextureSampler" sampler to use Texture Unit 0
-			glUniform1i(TextureID, 0);
-
-			glActiveTexture(GL_TEXTURE1);
-			glBindTexture(GL_TEXTURE_2D, depthTexture);
-			glUniform1i(ShadowMapID, 1);
-
-			// 1st attribute buffer: vertices
-			glEnableVertexAttribArray(0);
-			glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
-			glVertexAttribPointer(
-				0,			// attribute
-				3,			// size
-				GL_FLOAT,	// type
-				GL_FALSE,	// normalized?
-				0,			// stride
-				(void*)0	// array buffer offset
-			);
-
-			// 2nd attribute buffer: UVs
-			glEnableVertexAttribArray(1);
-			glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
-			glVertexAttribPointer(
-				1,			// attribute
-				2,			// size
-				GL_FLOAT,	// type
-				GL_FALSE,	// normalized?
-				0,			// stride
-				(void*)0	// array buffer offset
-			);
-
-			// 3rd attribute buffer: normals
-			glEnableVertexAttribArray(2);
-			glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
-			glVertexAttribPointer(
-				2,			// attribute
-				3,			// size
-				GL_FLOAT,	// type
-				GL_FALSE,	// normalized?
-				0,			// stride
-				(void*)0	// array buffer offset
-			);
-
-			// Index buffer
-			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
-
-			// Draw the triangles
-			glDrawElements(
-				GL_TRIANGLES,				// mode
-				GLsizei(indices.size()),	// count
-				GL_UNSIGNED_INT,			// type
-				(void*)0					// element array buffer offset
-			);
-
-			glDisableVertexAttribArray(0);
-			glDisableVertexAttribArray(1);
-			glDisableVertexAttribArray(2);
-		}
-		
-		void createMesh(cv::Mat cv_normals, cv::Mat cv_depth) {
-			std::cout << "Creating " << cv_normals.cols << "x" << cv_normals.rows << " mesh from depth map and normals... ";
-
-			flip(cv_normals, cv_normals, 0);
-			flip(cv_depth, cv_depth, 0);
-
-			for (int y = 0; y <= cv_normals.rows; y++) {
-				for (int x = 0; x <= cv_normals.cols; x++) {
-					vertices.push_back(glm::vec3(float(x - (cv_normals.cols / 2)) / cv_normals.rows, float(y - (cv_normals.rows / 2)) / cv_normals.rows, 0));
-					//vertices.push_back(glm::vec3(float(x - (cv_normals.cols / 2)) / cv_normals.rows, float(y - (cv_normals.rows / 2)) / cv_normals.rows, -cv_depth.at<float>(y, x) / (cv_normals.rows * 10)));
-					uvs.push_back(glm::vec2(float(x) / cv_normals.cols, 1.0f - (float(y) / cv_normals.rows)));
-					
-					if (y == cv_normals.rows) {
-						normals.push_back(glm::vec3(cv_normals.at<cv::Vec3f>(y-1, x)[1], -cv_normals.at<cv::Vec3f>(y-1, x)[0], cv_normals.at<cv::Vec3f>(y-1, x)[2]));
-					} else if (x == cv_normals.cols) {
-						normals.push_back(glm::vec3(cv_normals.at<cv::Vec3f>(y, x-1)[1], -cv_normals.at<cv::Vec3f>(y, x-1)[0], cv_normals.at<cv::Vec3f>(y, x-1)[2]));
-					} else if (y == cv_normals.rows && x == cv_normals.cols) {
-						normals.push_back(glm::vec3(cv_normals.at<cv::Vec3f>(y-1, x-1)[1], -cv_normals.at<cv::Vec3f>(y-1, x-1)[0], cv_normals.at<cv::Vec3f>(y-1, x-1)[2]));
-					} else {
-						normals.push_back(glm::vec3(cv_normals.at<cv::Vec3f>(y, x)[1], -cv_normals.at<cv::Vec3f>(y, x)[0], cv_normals.at<cv::Vec3f>(y, x)[2]));
-						//normals.push_back(glm::vec3(0, 0, 1));
-					}
-				}
-			}
-
-			std::cout << "Mesh created with " << cv_normals.cols * cv_normals.rows * 2 << " polygons.\n";
-
-			std::cout << "Indexing vertices... ";
-
-			for (int y = 0; y < cv_normals.rows; y++) {
-				for (int x = 0; x < cv_normals.cols; x++) {
-					indices.push_back(int((y * cv_normals.cols) + x));
-					indices.push_back(int((y * cv_normals.cols) + x + 1));
-					indices.push_back(int(((y + 1) * cv_normals.cols) + x + 1));
-
-					indices.push_back(int(((y + 1) * cv_normals.cols) + x + 1));
-					indices.push_back(int(((y + 1) * cv_normals.cols) + x));
-					indices.push_back(int((y * cv_normals.cols) + x));
-				}
-			}
-
-			std::cout << "Vertices indexed.\n\n";
-		}
-		
-		void computeMatricesFromLights(int lightNumber, std::vector<glm::vec3> lightInvDirVector) {
-			//calculateResidual = false;
-			
-			// Set the base movement speed
-			float speed = 1.0f; // 1 unit per second
-
-			// Mouse Speed
-			float mouseSpeed = 0.005f;
-
-			// glfwGetTime is called only once, the first time this function is called
-			static double lastTime = glfwGetTime();
-
-			// Compute time difference between current and last frame
-			double currentTime = glfwGetTime();
-			float deltaTime = float(currentTime - lastTime);
-
-			// Get the mouse position
-			double xpos, ypos;
-			glfwGetCursorPos(window, &xpos, &ypos);
-
-			// Reset the mouse position to the centre of the window for the next frame
-			glfwSetCursorPos(window, windowWidth / 2, windowHeight / 2);
-
-			// Compute new orientation
-			horizontalAngle += mouseSpeed * float(windowWidth  / 2 - xpos);
-			verticalAngle   += mouseSpeed * float(windowHeight / 2 - ypos);
-			
-			
-			
-			// Direction: Convert Spherical coordinates to Cartesian coordinates
-			glm::vec3 direction(
-				cos(verticalAngle) * sin(horizontalAngle),
-				sin(verticalAngle),
-				cos(verticalAngle) * cos(horizontalAngle)
-			);
-			
-			// Right vector
-			glm::vec3 right = glm::vec3(
-				sin(horizontalAngle - M_PI / 2.0f),
-				0,
-				cos(horizontalAngle - M_PI / 2.0f)
-			);
-
-			// Up vector
-			glm::vec3 up = glm::cross(right, direction);
-			//std::cout << "Calculated vectors\n";
-			
-			// Get a handle for the "LightPosition" uniform
-			//lightInvDirID = glGetUniformLocation(programID, "LightInvDirection_worldspace");
-			//std::cout << lightDirections.at<float>(0, 1) << " " << -lightDirections.at<float>(0, 0) << " " << lightDirections.at<float>(0, 2);
-			lightInvDir = lightInvDirVector[lightNumber];
-			//lightInvDir = glm::vec3(lightDirections.at<float>(lightNumber, 1), -lightDirections.at<float>(lightNumber, 0), lightDirections.at<float>(lightNumber, 2));
-			//std::cout << lightInvDir[0] << " " << lightInvDir[1] << " " << lightInvDir[2] << std::endl;
-			//lightInvDir = glm::vec3(0,0,1);
-			//std::cout << "Calculated light directions\n";
-			
-			
-			
-			
-			
-			
-			if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS) {
-				if (glfwGetKey(window, GLFW_KEY_1) == GLFW_RELEASE) {
-					if (lightNumber > 0) {
-						lightNumber--;
-					}
-					else {
-						lightNumber = numberOfLights - 1;
-					}
-					lightInvDir = lightInvDirVector[lightNumber];
-				}
-			}
-			else if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS) {
-				if (glfwGetKey(window, GLFW_KEY_2) == GLFW_RELEASE) {
-					if (lightNumber < numberOfLights - 1) {
-						lightNumber++;
-					}
-					else {
-						lightNumber = 0;
-					}
-					lightInvDir = lightInvDirVector[lightNumber];
-				}
-			}
-
-			if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
-				perspectiveProjection = true;
-			}
-			else if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) {
-				perspectiveProjection = false;
-			}
-			
-			// Speed up movement
-			if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) {
-				speed *= 2.5;
-			}
-
-			if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) {			// Move forward
-				position += direction * deltaTime * speed;
-			}
-			else if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) {	// Move backward
-				position -= direction * deltaTime * speed;
-			}
-
-			if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {			// Strafe right
-				position += right * deltaTime * speed;
-			}
-			else if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {	// Strafe left
-				position -= right * deltaTime * speed;
-			}
-
-			if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {		// Move upward
-				position += glm::vec3(0, 1, 0) * deltaTime * speed;
-			}
-			else if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) { // Move downward
-				position -= glm::vec3(0, 1, 0) * deltaTime * speed;
-			}
-
-			// Change the FoV
-			if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS) {
-				FoV -= 1;
-			} else if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS) {
-				FoV += 1;
-			} else if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS) {
-				FoV = 60.0f;
-			}
-
-			
-			
-			
-
-			
-			float aspectRatio = float(windowWidth) / float(windowHeight);
-
-			if (perspectiveProjection) // Projection matrix: 60° Field of View, 16:9 aspect ratio, display range: 0.1 units <-> 100 units
-				ProjectionMatrix = glm::perspective(glm::radians(FoV), aspectRatio, 0.1f, 100.0f);
-			else
-				ProjectionMatrix = glm::ortho(-0.5f * aspectRatio, 0.5f * aspectRatio, -0.5f, 0.5f, 0.0f, 10.0f); // In world coordinates
-
-			// Camera matrix
-			ViewMatrix = glm::lookAt(
-				position,				// Camera is here
-				position + direction,	// and looks here: at the same position, plus "direction"
-				up						// Head is up (set to 0, -1, 0 to look upside-down)
-			);
-		}
-	
-		GLuint loadMat() {
-			// Actual RGB data
-			unsigned char * data = cv_texture.data;
-			unsigned int width  = cv_texture.cols;
-			unsigned int height = cv_texture.rows;
-
-			// Create one OpenGL texture
-			GLuint textureID;
-			glGenTextures(1, &textureID);
-
-			// "Bind" the newly created texture: all future texture functions will modify this texture
-			glBindTexture(GL_TEXTURE_2D, textureID);
-
-			// Give the image to OpenGL
-			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);
-
-			// OpenGL has now copied the data. Free this version
-			//delete[] data;
-
-			// Nearest neighbour filtering
-			//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-			//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
-
-			// Trilinear filtering
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-			// This requires mipmaps. Generate them automatically.
-			glGenerateMipmap(GL_TEXTURE_2D);
-
-			// Return the ID of the texture we just created
-			return textureID;
-		}
-	
-		void meanSquaredError(double SpecularIntensity, double SpecularPower) {
-			// Create an empty Mat the same size as the image
-			cv::Mat temp = cv::Mat(windowHeight, windowWidth, CV_8UC3);
-			cv::Mat sumOfSquaredDifferences = cv::Mat(windowHeight, windowWidth, CV_16UC3);
-			
-			// Read the image into the Mat as an 8-bit colour image
-			glReadPixels(0, 0, windowWidth, windowHeight, GL_BGR, GL_UNSIGNED_BYTE, temp.data);
-			
-			// 3D models have the origin in the bottom-left corner, while images have the origin in the top-left corner. The image is flipped to convert between the two.
-			cv::flip(temp, temp, 0);
-			
-			//temp = temp(cv::Rect(1, 1, windowWidth-2, windowHeight-2));
-			//copyMakeBorder(temp, temp, 1, 1, 1, 1, cv::BORDER_REPLICATE);
-			
-			// Calculate the absolute differences between the model and the photograph
-			cv::absdiff(temp, textureImages[imageNumber], residual);
-			
-			sumOfSquaredDifferences = residual;
-			
-			// Square each element
-			multiply(sumOfSquaredDifferences, sumOfSquaredDifferences, sumOfSquaredDifferences);
-			
-			std::ostringstream stm;
-			stm << imageNumber;
-			std::string number = stm.str();
-			
-			// Display the residual
-			//cv::namedWindow("Model", CV_WINDOW_NORMAL);
-			//cv::imshow("Model", temp);
-			//cv::namedWindow("Sum of Squared Differences", CV_WINDOW_NORMAL);
-			//cv::imshow("Sum of Squared Differences", sumOfSquaredDifferences);
-			cv::imwrite(modelPath + "model." + number + ".png", temp);
-			cv::imwrite(modelPath + "residual." + number + ".png", residual);
-			
-			// Crop a 1-pixel border around the residual
-			sumOfSquaredDifferences = sumOfSquaredDifferences(cv::Rect(1, 1, windowWidth-2, windowHeight-2));
-			
-			//sum = (cv::sum(sumOfSquaredDifferences)[0] + cv::sum(sumOfSquaredDifferences)[1] + cv::sum(sumOfSquaredDifferences)[2])/(windowHeight-2 * windowWidth-2);
-			sum = (cv::sum(sumOfSquaredDifferences)[0] + cv::sum(sumOfSquaredDifferences)[1] + cv::sum(sumOfSquaredDifferences)[2]);
-			//residuals = cv::Vec3d(cv::sum(sumOfSquaredDifferences)[0], cv::sum(sumOfSquaredDifferences)[1], cv::sum(sumOfSquaredDifferences)[2]);
-			
-			
-			// Use the matchTemplate function to calculate the sum of squared differences
-			//matchTemplate(temp, textureImages[imageNumber], residual, 1);
-			
-			//sum = cv::sum(residual)[0];
-			
-			std::cout << "Image " << imageNumber << ", SSD per pixel: R = " << cv::sum(sumOfSquaredDifferences)[2]/(windowHeight * windowWidth) << ", G = " << cv::sum(sumOfSquaredDifferences)[1]/(windowHeight * windowWidth) << ", B = " << cv::sum(sumOfSquaredDifferences)[0]/(windowHeight * windowWidth) << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl;
-			//std::cout << "Image " << imageNumber << ", average sum of squared differences: R = " << sum << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl;
-		}
-		
-		void computeResiduals(std::vector<cv::Mat> textureImages, int numberOfLights, double SpecularIntensity, double SpecularPower, std::string modelPath, cv::Mat lightDirections, std::vector<glm::vec3> lightInvDirVector) {
-			
-			lightNumber = 0;
-			
-			do {
-				// Render the shadows
-				depthModelMatrix = glm::mat4(1.0);
-				depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;
-				//renderShadows(FramebufferName, shadowResolution, depthProgramID, depthProjectionMatrix, depthViewMatrix, depthMatrixID, vertexbuffer, elementbuffer, indices, depthModelMatrix, depthMVP);
-
-				// Compute the MVP matrix from keyboard and mouse input
-				ModelMatrix = glm::mat4(1.0);
-				
-				//computeMatricesFromInputs(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, calculateResidual);
-				computeMatricesFromLights(lightNumber, lightInvDirVector);
-				MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
-
-				biasMatrix = glm::mat4(
-					0.5, 0.0, 0.0, 0.0,
-					0.0, 0.5, 0.0, 0.0,
-					0.0, 0.0, 0.5, 0.0,
-					0.5, 0.5, 0.5, 1.0
-				);
-
-				depthBiasMVP = biasMatrix * depthMVP;
-				
-					
-				// Render the polygons
-				renderPolygons(SpecularIntensity, SpecularPower);
-				
-				// Optionally render the shadowmap (for debug only)
-				//void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, GLuint quad_vertexbuffer);
-				
-				
-				
-				//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower);
-				
-				//meanSquaredError(SpecularIntensity, SpecularPower);
-				//residuals.push_back(residual);
-				
-				// Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian).
-				// AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)>
-				//CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 2>(new CostFunctor);
-				//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower);
-				
-				// Swap buffers
-				glfwSwapBuffers(window);
-				glfwPollEvents();
-				
-				
-				
-				//TODO: Save model image and residual
-				
-				
-				//lightNumber++;
-			//} while (lightNumber < numberOfLights);
-			} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
-			
-			//lightNumber = 0;
-		}
-	
-		double SpecularIntensity;
-		double SpecularPower;
-	
-	private:
-		cv::Mat lightDirections;
-		glm::vec3 lightInvDir;
-		cv::Mat cv_depth;
-		cv::Mat cv_normals;
-		cv::Mat cv_texture;
-		std::vector<cv::Mat> textureImages;
-		cv::Mat residualImage;
-		bool calculateResidual;
-		int windowWidth;
-		int windowHeight;
-		int lightNumber;
-		int imageNumber;
-		int numberOfLights;
-		std::vector<unsigned int> indices;
-		cv::Vec3d residual;
-		std::vector<cv::Vec3d> residuals;
-		const std::string modelPath;
-		
-		glm::mat4 depthProjectionMatrix;
-		glm::mat4 depthViewMatrix;
-		glm::vec3 position;
-		float horizontalAngle;
-		float verticalAngle;
-		float FoV;
-		GLuint programID;
-		GLuint MatrixID;
-		GLuint ModelMatrixID;
-		GLuint ViewMatrixID;
-		GLuint DepthBiasID;
-		GLuint lightInvDirID;
-		GLuint Texture;
-		GLuint TextureID;
-		GLuint depthTexture;
-		GLuint ShadowMapID;
-		GLuint vertexbuffer;
-		GLuint uvbuffer;
-		GLuint normalbuffer;
-		GLuint elementbuffer;
-		GLuint depthProgramID;
-		GLuint quad_programID;
-		GLuint FramebufferName;
-		GLuint quad_vertexbuffer;
-		GLuint VertexArrayID;
-		GLuint texID;
-		
-		glm::mat4 depthModelMatrix;
-		glm::mat4 depthMVP;
-		glm::mat4 ModelMatrix;
-		glm::mat4 MVP;
-		glm::mat4 ViewMatrix;
-		glm::mat4 depthBiasMVP;
-		glm::mat4 ProjectionMatrix;
-		glm::mat4 biasMatrix;
-		bool perspectiveProjection = false;
-		bool shadowControl;
-		//glm::mat4 biasMatrix;
-		
-		std::vector<glm::vec3> vertices;
-		std::vector<glm::vec2> uvs;
-		std::vector<glm::vec3> normals;
-		//std::vector<unsigned int> indices;
-		std::vector<glm::vec3> lightInvDirVector;
-		
-		double sum;
-		double totalResidual;
-		
-		GLuint SpecularIntensityID;
-		GLuint SpecularPowerID;	
-};
-*/
-
-
-
-
-
-
-// From https://codeyarns.com/2015/06/16/how-to-rotate-point-in-opencv/ 
-/*cv::Mat rotatePoints(cv::Mat point, cv::Vec3d rvec) {
-	cv::Mat rotatedPoints, pointsTransposed;
-
-	cv::Mat rx = (cv::Mat_<float>(3, 3) << 1, 0, 0, 0, cos(rvec[0]), -sin(rvec[0]), 0, sin(rvec[0]), cos(rvec[0]));
-	cv::Mat ry = (cv::Mat_<float>(3, 3) << cos(rvec[0]), 0, sin(rvec[0]), 0, 1, 0, -sin(rvec[0]), 0, cos(rvec[0]));
-	cv::Mat rz = (cv::Mat_<float>(3, 3) << cos(rvec[0]), -sin(rvec[0]), 0, sin(rvec[0]), cos(rvec[0]), 0, 0, 0, 1);
-
-	cv::transpose(point, pointsTransposed);
-
-	rotatedPoints = rx * ry * rz * pointsTransposed;
-
-	cv::transpose(rotatedPoints, point);
-
-	return point;
-}*/
-
-// From https://codeyarns.com/2015/06/16/how-to-rotate-point-in-opencv/
-/*cv::Point3f rotatePoint(const cv::Point3f& cen_pt, const cv::Point3f& p, float rad)
-{
-	const cv::Point3f trans_pt = p - cen_pt;
-	const cv::Point3f rot_pt = RotatePoint(trans_pt, rad);
-	const cv::Point3f fin_pt = rot_pt + cen_pt;
-
-	return fin_pt;
-}*/
-
-
-void initialiseOpenGLCT(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, cv::Mat lightDirections, int& windowWidth, int& windowHeight, glm::mat4& depthProjectionMatrix, glm::mat4& depthViewMatrix, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, GLuint& programID, GLuint& MatrixID, GLuint& ModelMatrixID, GLuint& ViewMatrixID, GLuint& DepthBiasID, GLuint& lightInvDirID, GLuint& Texture, GLuint& TextureID, GLuint& depthTexture, GLuint& ShadowMapID, GLuint& vertexbuffer, GLuint& uvbuffer, GLuint& normalbuffer, GLuint& elementbuffer, std::vector<unsigned int> & indices, GLuint& depthProgramID, GLuint& quad_programID, GLuint& FramebufferName, GLuint& quad_vertexbuffer, GLuint& VertexArrayID, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, int numberOfLights, bool calculateResidual, glm::mat4& depthMVP, glm::mat4& depthModelMatrix, glm::mat4& MVP, glm::mat4& ProjectionMatrix, glm::mat4& ViewMatrix, glm::mat4& ModelMatrix, glm::mat4& depthBiasMVP, glm::mat4& biasMatrix) {
-	// Initialise the GLFW library first
-	if (!glfwInit()) {
-		std::cerr << "Failed to initialise GLFW.\n";
-		getchar();
-		return;
-	}
-	std::cout << "Initialised GLFW.\n";
-
-	glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
-	glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
-	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // OpenGL 3.3
-	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
-	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Only needed for macOS
-	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Disable old OpenGL
-
-	// Set the shadow resolution to 4096x4096
-	int shadowResolution = 4096;
-
-	// Open a window and create its OpenGL context
-	window = glfwCreateWindow(windowWidth, windowHeight, "Window", NULL, NULL);
-	if (window == NULL) {
-		std::cerr << "Failed to open GLFW window. Older Intel GPUs are not OpenGL 3.3 compatible.\n";
-		getchar();
-		glfwTerminate();
-		return;
-	}
-	glfwMakeContextCurrent(window);
-	std::cout << "Opened GLFW window.\n";
-
-	// On macOS with a retina screen it will be windowWidth*2 and windowHeight*2, so the actual framebuffer size is:
-	glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
-
-	// Initialize GLEW
-	glewExperimental = true; // Needed for core profile
-	if (glewInit() != GLEW_OK) {
-		std::cerr << "Failed to initialise GLEW.\n";
-		getchar();
-		glfwTerminate();
-		return;
-	}
-	std::cout << "Initialised GLEW.\n";
-
-	// Ensure that the escape key being pressed can be captured
-	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
-	// Hide the mouse and enable unlimited mouvement
-	//glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
-
-	// Set the mouse at the center of the screen
-	glfwPollEvents();
-	//glfwSetCursorPos(window, windowWidth / 2, windowHeight / 2);
-
-	// Dark blue background
-	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
-
-	// Enable depth test, which stores fragments in the Z-buffer
-	glEnable(GL_DEPTH_TEST);
-
-	// Accept fragment if it is closer to the camera than the former one
-	glDepthFunc(GL_LESS);
-
-	// Cull triangles which do not have a normal facing towards the camera
-	glEnable(GL_CULL_FACE);
-
-	// Create a Vertex Array Object (VAO) and set it as the current one
-	//GLuint VertexArrayID;
-	glGenVertexArrays(1, &VertexArrayID);
-	glBindVertexArray(VertexArrayID);
-
-	// Create and compile the GLSL program from the shaders
-	depthProgramID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/DepthRTT.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/DepthRTT.fragmentshader");
-
-	// Get a handle for the "MVP" uniform
-	GLuint depthMatrixID = glGetUniformLocation(depthProgramID, "depthMVP");
-
-	// Load the texture
-	//GLuint Texture = loadDDS("C:/Users/tdwal/Documents/repos/OpenGLTutorials/tutorial16_shadowmaps/uvmap.DDS");
-	Texture = loadMat(cv_texture);
-	std::cout << "Texture loaded.\n\n";
-
-	// Read the .obj file
-	std::vector<glm::vec3> vertices;
-	std::vector<glm::vec2> uvs;
-	std::vector<glm::vec3> normals;
-	//std::vector<unsigned int> indices;
-	//bool res = loadOBJ("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/sphere.obj", vertices, uvs, normals);
-	createMesh(cv_depth, cv_normals, vertices, uvs, normals, indices);
-	//createSphere(100, 100);
-	std::cout << "\nModel created.\n\n";
-
-	// Load it into a VBO
-	//GLuint vertexbuffer; // This will identify the vertex buffer
-	glGenBuffers(1, &vertexbuffer); // Generate 1 buffer, and put the resulting identifier in vertexbuffer
-	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); // The following commands will talk about the 'vertexbuffer' buffer
-	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW); // Give the vertices to OpenGL
-
-	//GLuint uvbuffer;
-	glGenBuffers(1, &uvbuffer);
-	glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
-	glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
-
-	//GLuint normalbuffer;
-	glGenBuffers(1, &normalbuffer);
-	glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
-	glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW);
-
-	// Generate a buffer for the indices as well
-	//GLuint elementbuffer;
-	glGenBuffers(1, &elementbuffer);
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
-	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
-
-
-	// ---------------------------------------------
-	// Render to Texture - specific code begins here
-	// ---------------------------------------------
-
-	// The framebuffer, which regroups 0, 1 or more textures, and 0 or 1 depth buffers
-	FramebufferName = 0;
-	glGenFramebuffers(1, &FramebufferName);
-	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
-
-	// Depth texture. Slower than a depth buffer, but can be sampled later in the shader
-	//GLuint depthTexture;
-	glGenTextures(1, &depthTexture);
-	glBindTexture(GL_TEXTURE_2D, depthTexture);
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowResolution, shadowResolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
-
-	glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0);
-
-	// No colour output in the bound framebuffer, only depth.
-	glDrawBuffer(GL_NONE);
-
-	// Always check if there are any errors in the framebuffer
-	if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
-		return;
-
-	// The quad's FBO. Used only for visualising the shadowmap.
-	static const GLfloat g_quad_vertex_buffer_data[] = {
-		-1.0f, -1.0f, 0.0f,
-		 1.0f, -1.0f, 0.0f,
-		-1.0f,  1.0f, 0.0f,
-		-1.0f,  1.0f, 0.0f,
-		 1.0f, -1.0f, 0.0f,
-		 1.0f,  1.0f, 0.0f,
-	};
-
-	//GLuint quad_vertexbuffer;
-	glGenBuffers(1, &quad_vertexbuffer);
-	glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
-	glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW);
-
-	// Create and compile the GLSL program from the shaders
-	quad_programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/Passthrough.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/SimpleTexture.fragmentshader");
-	std::cout << "Shaders loaded.\n";
-	GLuint texID = glGetUniformLocation(quad_programID, "texture");
-	std::cout << "Uniform Location of texture found.\n";
-
-	// Create and compile the GLSL program from the shaders
-	programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/ShadowMapping.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/CookTorrance.fragmentshader");
-
-	// Get a handle for the "myTextureSampler" uniform
-	TextureID = glGetUniformLocation(programID, "myTextureSampler");
-	//SpecularID = glGetUniformLocation(programID, "mySpecularSampler");
-	
-	SpecularIntensityID = glGetUniformLocation(programID, "specularIntensity");
-	SpecularPowerID = glGetUniformLocation(programID, "specularPower");
-
-	// Get a handle for the "MVP" uniform
-	MatrixID = glGetUniformLocation(programID, "MVP");
-	ViewMatrixID = glGetUniformLocation(programID, "V");
-	ModelMatrixID = glGetUniformLocation(programID, "M");
-	DepthBiasID = glGetUniformLocation(programID, "DepthBiasMVP");
-	ShadowMapID = glGetUniformLocation(programID, "shadowMap");
-
-	// Get a handle for the "LightPosition" uniform
-	lightInvDirID = glGetUniformLocation(programID, "LightInvDirection_worldspace");
-
-	// Compute the MVP matrix from the light's point of view
-	//lightInvDir = glm::vec3(0, 0, 1);
-	depthProjectionMatrix = glm::perspective<float>(45.0f, 1.0f, 1.0f, 100.0f);
-	depthViewMatrix = glm::lookAt(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
-
-	// Initial position: on +Z
-	position = glm::vec3(0, 0, 1);
-	// Initial horizontal angle: toward -Z
-	horizontalAngle = M_PI;
-	// Initial vertical angle: none
-	verticalAngle = 0.0f;
-	// Initial Field of View
-	FoV = 60.0f;
-	// Mouse Speed
-	float mouseSpeed = 0.005f;
-	
-	depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;
-	bool perspectiveProjection = false;
-	int lightNumber = 0;
-
-	// Compute the MVP matrix
-	computeMatricesFromLights(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-	
-	MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
-	depthBiasMVP = biasMatrix * depthMVP;
-}
-
-
-void renderPolygonsCT(int windowWidth, int windowHeight, GLuint programID, glm::vec3 lightInvDir, GLuint MatrixID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, glm::mat4 MVP, glm::mat4 ModelMatrix, glm::mat4 ViewMatrix, glm::mat4 depthBiasMVP, GLuint SpecularIntensityID, double SpecularIntensity, GLuint SpecularPowerID, double SpecularPower) {
-
-	// Render to the screen
-	glBindFramebuffer(GL_FRAMEBUFFER, 0);
-	glViewport(0, 0, windowWidth, windowHeight); // Render on the whole framebuffer, complete from the lower left corner to the upper right
-
-	glEnable(GL_CULL_FACE);
-	glCullFace(GL_BACK); // Cull back-facing triangles -> draw only front-facing triangles
-
-	// Clear the screen
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-	// Use the shader
-	glUseProgram(programID);
-	
-	// Send the transformation to the currently bound shader, in the "MVP" uniform
-	glUniformMatrix4fv(MatrixID,      1, GL_FALSE, &MVP[0][0]);
-	glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
-	glUniformMatrix4fv(ViewMatrixID,  1, GL_FALSE, &ViewMatrix[0][0]);
-	glUniformMatrix4fv(DepthBiasID,   1, GL_FALSE, &depthBiasMVP[0][0]);
-	
-	glUniform1f(SpecularIntensityID, SpecularIntensity);
-	glUniform1f(SpecularPowerID,     SpecularPower);
-
-	glUniform3f(lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z);
-
-	// Bind the texture in Texture Unit 0
-	glActiveTexture(GL_TEXTURE0);
-	glBindTexture(GL_TEXTURE_2D, Texture);
-	// Set the "myTextureSampler" sampler to use Texture Unit 0
-	glUniform1i(TextureID, 0);
-
-	glActiveTexture(GL_TEXTURE1);
-	glBindTexture(GL_TEXTURE_2D, depthTexture);
-	glUniform1i(ShadowMapID, 1);
-
-	// 1st attribute buffer: vertices
-	glEnableVertexAttribArray(0);
-	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
-	glVertexAttribPointer(
-		0,			// attribute
-		3,			// size
-		GL_FLOAT,	// type
-		GL_FALSE,	// normalized?
-		0,			// stride
-		(void*)0	// array buffer offset
-	);
-
-	// 2nd attribute buffer: UVs
-	glEnableVertexAttribArray(1);
-	glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
-	glVertexAttribPointer(
-		1,			// attribute
-		2,			// size
-		GL_FLOAT,	// type
-		GL_FALSE,	// normalized?
-		0,			// stride
-		(void*)0	// array buffer offset
-	);
-
-	// 3rd attribute buffer: normals
-	glEnableVertexAttribArray(2);
-	glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
-	glVertexAttribPointer(
-		2,			// attribute
-		3,			// size
-		GL_FLOAT,	// type
-		GL_FALSE,	// normalized?
-		0,			// stride
-		(void*)0	// array buffer offset
-	);
-
-	// Index buffer
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
-
-	// Draw the triangles
-	glDrawElements(
-		GL_TRIANGLES,				// mode
-		GLsizei(indices.size()),	// count
-		GL_UNSIGNED_INT,			// type
-		(void*)0					// element array buffer offset
-	);
-
-	glDisableVertexAttribArray(0);
-	glDisableVertexAttribArray(1);
-	glDisableVertexAttribArray(2);
-
-}
-
-void terminateOpenGLCT(GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, GLuint programID, GLuint depthProgramID, GLuint quad_programID, GLuint Texture, GLuint FramebufferName, GLuint depthTexture, GLuint quad_vertexbuffer, GLuint VertexArrayID) {
-	
-	// Cleanup VBO and shader
-	glDeleteBuffers(1, &vertexbuffer);
-	glDeleteBuffers(1, &uvbuffer);
-	glDeleteBuffers(1, &normalbuffer);
-	glDeleteBuffers(1, &elementbuffer);
-	glDeleteProgram(programID);
-	glDeleteProgram(depthProgramID);
-	glDeleteProgram(quad_programID);
-	glDeleteTextures(1, &Texture);
-
-	glDeleteFramebuffers(1, &FramebufferName);
-	glDeleteTextures(1, &depthTexture);
-	glDeleteBuffers(1, &quad_vertexbuffer);
-	glDeleteVertexArrays(1, &VertexArrayID);
-
-	// Close OpenGL window and terminate GLFW
-	glfwTerminate();
-}
-
-void viewModelCT(cv::Vec3d& residual, double& totalResidual, cv::Mat& residualImage, bool calculateResidual, glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat> textureImages, int lightNumber, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
-	do {
-		// Render the shadows
-		glm::mat4 depthModelMatrix = glm::mat4(1.0);
-		glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;
-		//renderShadows(FramebufferName, shadowResolution, depthProgramID, depthProjectionMatrix, depthViewMatrix, depthMatrixID, vertexbuffer, elementbuffer, indices, depthModelMatrix, depthMVP);
-
-		// Compute the MVP matrix from keyboard and mouse input
-		glm::mat4 ModelMatrix = glm::mat4(1.0);
-		glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix;
-		bool perspectiveProjection = false, shadowControl;
-		//float mouseSpeed = 0.005f;
-		//computeMatricesFromInputs(width, height, position, horizontalAngle, verticalAngle, FoV, mouseSpeed, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, shadowControl, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, calculateResidual);
-		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-		MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
-
-		glm::mat4 biasMatrix(
-			0.5, 0.0, 0.0, 0.0,
-			0.0, 0.5, 0.0, 0.0,
-			0.0, 0.0, 0.5, 0.0,
-			0.5, 0.5, 0.5, 1.0
-		);
-
-		depthBiasMVP = biasMatrix * depthMVP;
-		
-			
-		// Render the polygons
-		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-		
-		// Optionally render the shadowmap (for debug only)
-		//void renderShadowMap(GLuint quad_programID, GLuint depthTexture, GLuint texID, GLuint quad_vertexbuffer);
-				
-		if (calculateResidual) {
-			double sum = 0, gain = 0;
-			int bias = 0;
-			meanSquaredError(lightNumber, height, width, textureImages, sum, gain, bias);
-			//computeResiduals(residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
-			std::cout << "Light number: " << lightNumber << ", per-pixel residual = " << totalResidual << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl;
-		}
-		
-		
-		/*
-		// TODO: Check if the viewpoint has been changed
-		if (calculateResidual) {
-			// Compute the residual image and sum of differences
-			cv::Mat residualImage;
-			meanSquaredError(lightNumber, height, width, textureImages, residualImage, residuals, residual, SpecularIntensity, SpecularPower);
-			
-			specularMinimisation(SpecularIntensity, SpecularPower, residual);
-			calculateResidual = false;
-		}
-		*/
-		
-		//totalResidual = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower);
-		//meanSquaredError(lightNumber, height, width, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower);
-		//residuals.push_back(residual);
-		
-		// Set up the only cost function (also known as residual). This uses auto-differentiation to obtain the derivative (jacobian).
-		// AutoDiffCostFunction<CostFunctor, (Dimensions of Residual), (Dimensions of Variables)>
-		//CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 2>(new CostFunctor);
-		//problem.AddResidualBlock(cost_function, NULL, &SpecularIntensity, &SpecularPower);
-		
-		// Swap buffers
-		glfwSwapBuffers(window);
-		glfwPollEvents();
-	} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
-}
-
-void RenderSyntheticCT(glm::mat4 depthProjectionMatrix, glm::mat4 depthViewMatrix, int width, int height, glm::vec3& position, float& horizontalAngle, float& verticalAngle, float& FoV, glm::vec3& lightInvDir, cv::Mat lightDirections, std::vector<cv::Mat>& textureImages, int numberOfLights, GLuint& SpecularIntensityID, double& SpecularIntensity, GLuint& SpecularPowerID, double& SpecularPower, GLuint programID, GLuint ModelMatrixID, GLuint ViewMatrixID, GLuint DepthBiasID, GLuint lightInvDirID, GLuint Texture, GLuint TextureID, GLuint depthTexture, GLuint ShadowMapID, GLuint vertexbuffer, GLuint uvbuffer, GLuint normalbuffer, GLuint elementbuffer, std::vector<unsigned int> indices, GLuint MatrixID, std::string modelPath) {
-	for(int lightNumber = 0; lightNumber < numberOfLights; lightNumber++) {
-		// Render the shadows
-		glm::mat4 depthModelMatrix = glm::mat4(1.0);
-		glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;
-		
-		// Compute the MVP matrix from keyboard and mouse input
-		glm::mat4 ModelMatrix = glm::mat4(1.0);
-		glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix;
-		bool perspectiveProjection = false, shadowControl, calculateResidual = false;
-		computeMatricesFromLights(width, height, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection, lightDirections, lightNumber, numberOfLights, calculateResidual, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-		MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
-
-		glm::mat4 biasMatrix(
-			0.5, 0.0, 0.0, 0.0,
-			0.0, 0.5, 0.0, 0.0,
-			0.0, 0.0, 0.5, 0.0,
-			0.5, 0.5, 0.5, 1.0
-		);
-
-		depthBiasMVP = biasMatrix * depthMVP;
-		
-		// Render the polygons
-		renderPolygons(width, height, programID, lightInvDir, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
-		
-		// Create an empty Mat the same size as the image
-		cv::Mat temp = cv::Mat(height, width, CV_8UC3);
-		
-		// Read the image into the Mat as an 8-bit colour image
-		glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, temp.data);
-		
-		// 3D models have the origin in the bottom-left corner, while images have the origin in the top-left corner. The image is flipped to convert between the two.
-		cv::flip(temp, temp, 0);
-
-		//temp = addNoise(temp, 0.1);
-		temp = AddGaussianNoise_Opencv(temp, 0, 0.001);
-		textureImages.push_back(temp);
-
-		std::ostringstream a, b, c;
-		a << lightNumber;
-		b << SpecularIntensity;
-		c << SpecularPower;
-		std::string imageNumber = a.str();
-		std::string specularIntensity = b.str();
-		std::string specularPower = c.str();
-
-		//cv::imwrite(modelPath + "Intensity" + specularIntensity + "Power" + specularPower + imageNumber + ".png", temp);
-		cv::imwrite(modelPath + imageNumber + ".png", temp);
-
-		// Swap buffers
-		glfwSwapBuffers(window);
-		glfwPollEvents();
-	} //while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
-}
-
-
-
-
-
-
 #endif
diff --git a/apps/specular_estimation/src/ShadowMapping.fragmentshader b/apps/specular_estimation/src/ShadowMapping.fragmentshader
index a2313c64026c6232fb9e3c81bc50c3e6d4422cac..9670034a8ca8b2750d1999ae5b1f34da7ed01b9a 100644
--- a/apps/specular_estimation/src/ShadowMapping.fragmentshader
+++ b/apps/specular_estimation/src/ShadowMapping.fragmentshader
@@ -3,9 +3,9 @@
 // Interpolated values from the vertex shaders
 in vec2 UV;
 in vec3 Normal_cameraspace;
-in vec3 Normal_worldspace;
+//in vec3 Normal_worldspace;
 in vec3 EyeDirection_cameraspace;
-in vec3 EyeDirection_worldspace;
+//in vec3 EyeDirection_worldspace;
 in vec3 LightDirection_cameraspace;
 in vec3 LightDirection_worldspace;
 in vec4 ShadowCoord;
@@ -25,6 +25,8 @@ uniform float specularIntensity;
 uniform float specularPower;
 //uniform float roughness;
 //uniform float metallic;
+uniform float distance;
+uniform float lightPower;
 
 const float PI = 3.14159265359;
 
@@ -119,9 +121,11 @@ void main() {
     // calculate per-light radiance
     vec3 L = normalize(LightDirection_worldspace - Position_worldspace);
     vec3 H = normalize(V + L);
-    float distance    = length(LightPosition_worldspace - Position_worldspace);
+    //float distance    = length(LightPosition_worldspace - Position_worldspace);
+    //float distance    = 0.5f;
     float attenuation = 1.0 / (distance * distance);
-	vec3 LightColor   = vec3(1, 1, 1);
+	//float lightPower = 1.0f;
+	vec3 LightColor   = vec3(lightPower, lightPower, lightPower);
     vec3 radiance     = LightColor * attenuation;
         
     // cook-torrance brdf
diff --git a/apps/specular_estimation/src/ShadowMapping.vertexshader b/apps/specular_estimation/src/ShadowMapping.vertexshader
index ead75821916de0fe7068b773679409f3c0739c59..d5c2d25da78e9ddf4d7b56901dc77dd76f6a26ba 100644
--- a/apps/specular_estimation/src/ShadowMapping.vertexshader
+++ b/apps/specular_estimation/src/ShadowMapping.vertexshader
@@ -40,7 +40,7 @@ void main() {
 	// Vector that goes from the vertex to the camera, in camera space.
 	// In camera space, the camera is at the origin (0,0,0).
 	EyeDirection_cameraspace = vec3(0,0,0) - ( V * M * vec4(vertexPosition_modelspace, 1)).xyz;
-	EyeDirection_worldspace  = vec3(0,0,0) - ( M * vec4(vertexPosition_modelspace, 1)).xyz;
+	//EyeDirection_worldspace  = vec3(0,0,0) - ( M * vec4(vertexPosition_modelspace, 1)).xyz;
 
 	// Vector that goes from the vertex to the light, in camera space
 	LightDirection_cameraspace = ( V * vec4(LightInvDirection_worldspace, 0)).xyz;
@@ -48,7 +48,7 @@ void main() {
 	
 	// Normal of the the vertex, in camera space
 	Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace, 0)).xyz; // Only correct if ModelMatrix does not scale the model. Use its inverse transpose if not.
-	Normal_worldspace  = ( M * vec4(vertexNormal_modelspace, 0)).xyz;
+	//Normal_worldspace  = ( M * vec4(vertexNormal_modelspace, 0)).xyz;
 	
 	// UV of the vertex. No special space for this one.
 	UV = vertexUV;
diff --git a/apps/specular_estimation/src/specular_estimation.cc b/apps/specular_estimation/src/specular_estimation.cc
index 0169ee6980cb14628445013fec4e57a8bce7abf3..f308fc625b0099641e3384e22a8841f38efc9ab3 100644
--- a/apps/specular_estimation/src/specular_estimation.cc
+++ b/apps/specular_estimation/src/specular_estimation.cc
@@ -16,12 +16,12 @@ SpecularEstimation::SpecularEstimation(std::string imageName, std::string calibr
 
 	populateLightInvDirs();
 
-	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
 	if (denseSample)
 		DenseSample();
 	else
-		specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
+		specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
 
 	terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
 }
@@ -34,14 +34,14 @@ SpecularEstimation::SpecularEstimation(std::string imageName, std::string calibr
 
 	populateLightInvDirs();
 
-	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
-	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensitySynthetic, SpecularPowerID, SpecularPowerSynthetic, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensitySynthetic, SpecularPowerID, SpecularPowerSynthetic, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 
 	if (denseSample)
 		DenseSample();
 	else
-		specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
+		specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
 
 	terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
 }
@@ -106,7 +106,7 @@ void SpecularEstimation::DenseSample() {
 			for(int i = 0; i < numberOfLights; i++) {
 
 				// Render the polygons
-				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
+				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower);
 						
 				meanSquaredError(i, height, width, textureImages, sum, Gain, Bias);
 						
@@ -193,7 +193,7 @@ int main(int argc, char** argv) {
 
 	//specularEstimation(imageName, calibration, imageScale, showTexture);
 
-	double SpecularIntensity = 0.5, SpecularPower = 2;
+	double SpecularIntensity = 0.5, SpecularPower = 2, Distance = 1.0, LightPower = 1.0;
 	bool denseSample = false;
 
 	if (argc >= 4) {
@@ -244,6 +244,8 @@ void renderSynthetic(std::string imageName, std::string calibration, double Spec
 	const std::string albedoPath      = modelPath + "albedo.png";
 	const std::string normalPath      = modelPath + "normal.png";
 
+	double Distance = 1.0, LightPower = 1.0;
+
 	const std::string calibrationPath2 = imagesPath + folderPath + "/" + calibration + "/" + calibration + ".";
 	int numberOfLights = 6, width = 1092, height = 728;
 
@@ -256,7 +258,7 @@ void renderSynthetic(std::string imageName, std::string calibration, double Spec
 		0.5, 0.5, 0.5, 1.0
 	);
 	float horizontalAngle, verticalAngle, FoV;
-	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
+	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID;
 	std::vector<unsigned int> indices;
 	cv::Vec3d residual;
 	int lightNumber = 0;
@@ -277,16 +279,16 @@ void renderSynthetic(std::string imageName, std::string calibration, double Spec
 	lightInvDir = glm::vec3(lightDirections.at<float>(0, 0), -lightDirections.at<float>(0, 2), lightDirections.at<float>(0, 1));
 	//lightInvDir = glm::vec3(0, 0, 1);
 
-	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
-	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensitySynthetic, SpecularPowerID, SpecularPowerSynthetic, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensitySynthetic, SpecularPowerID, SpecularPowerSynthetic, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 	
 	//SpecularIntensity = 0.5, SpecularPower = 2;
-	double Gain = 1.0, Bias = 0;
+	double Gain = 0.5, Bias = 0.5;
 
-	specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
+	specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
 
-	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 	
 	terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
 	
@@ -307,6 +309,8 @@ void specularEstimation(std::string imageName, std::string calibration, double S
 	const std::string macbethPath	  = imagesPath + folderPath + "/macbeth/macbeth.";
 	const std::string texturePath     = modelPath + "texture.png";
 
+	double Distance = 1.0, LightPower = 1.0;
+
 	/*
 	std::vector<double> macbethIntensity;
 
@@ -479,7 +483,7 @@ void specularEstimation(std::string imageName, std::string calibration, double S
 		0.5, 0.5, 0.5, 1.0
 	);
 	float horizontalAngle, verticalAngle, FoV;
-	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
+	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID;
 	std::vector<unsigned int> indices;
 	cv::Vec3d residual;
 	int lightNumber = 0;
@@ -505,13 +509,13 @@ void specularEstimation(std::string imageName, std::string calibration, double S
 	for (int i = 0; i < numberOfLights; i++)
 		lightInvDirs.push_back(glm::vec3(lightDirections.at<float>(i, 0), -lightDirections.at<float>(i, 2), lightDirections.at<float>(i, 1)));
 	
-	initialiseOpenGL(heightMap, normalMap, texture, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, texture, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
-	double Gain = 1.0, Bias = 0.0;
+	double Gain = 0.5, Bias = 0.5;
 
-	specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
+	specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
 
-	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 	
 	terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
 	
@@ -548,7 +552,7 @@ void denseRealSample(std::string imageName, std::string calibration, double Spec
 	const std::string macbethPath	  = imagesPath + folderPath + "/macbeth/macbeth.";
 	const std::string texturePath     = modelPath + "texture.png";
 
-
+	double Distance = 1.0, LightPower = 1.0;
 
 	const std::string calibrationPath2 = imagesPath + folderPath + "/" + calibration + "/" + calibration + ".";
 	int numberOfLights = 6;
@@ -602,12 +606,12 @@ void denseRealSample(std::string imageName, std::string calibration, double Spec
 		0.5, 0.5, 0.5, 1.0
 	);
 	float horizontalAngle, verticalAngle, FoV;
-	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
+	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID;
 	std::vector<unsigned int> indices;
 	cv::Vec3d residual;
 	int lightNumber = 0;
 	bool calculateResidual = false, perspectiveProjection, shadowControl;
-	double totalResidual, residualValue, gain = 1.0, bias = 0;
+	double totalResidual, residualValue, gain = 0.5, bias = 0.5;
 	cv::Mat residualImage;
 
 	//cv::Mat lightDirectionsInverted;
@@ -618,7 +622,7 @@ void denseRealSample(std::string imageName, std::string calibration, double Spec
 	for (int i = 0; i < numberOfLights; i++)
 		lightInvDirs.push_back(glm::vec3(lightDirections.at<float>(i, 0), -lightDirections.at<float>(i, 2), lightDirections.at<float>(i, 1)));
 	
-	initialiseOpenGL(heightMap, normalMap, texture, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, texture, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
 	std::string outputFileName = imageName + ".txt";
 	std::ofstream outputFile(outputFileName, std::ios::app);
@@ -633,7 +637,7 @@ void denseRealSample(std::string imageName, std::string calibration, double Spec
 			for(int i = 0; i < numberOfLights; i++) {
 
 				// Render the polygons
-				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, specularIntensity, SpecularPowerID, specularPower);
+				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, specularIntensity, SpecularPowerID, specularPower, DistanceID, Distance, LightPowerID, LightPower);
 				
 				meanSquaredError(i, height, width, textureImages, sum, gain, bias);
 				
@@ -680,6 +684,7 @@ void denseSyntheticSample(std::string imageName, std::string calibration, double
 	const std::string albedoPath      = modelPath + "albedo.png";
 	const std::string normalPath      = modelPath + "normal.png";
 
+	double Distance = 1.0, LightPower = 1.0;
 
 	const std::string calibrationPath2 = imagesPath + folderPath + "/" + calibration + "/" + calibration + ".";
 	int numberOfLights = 6, width = 1092, height = 728;
@@ -695,7 +700,7 @@ void denseSyntheticSample(std::string imageName, std::string calibration, double
 		0.5, 0.5, 0.5, 1.0
 	);
 	float horizontalAngle, verticalAngle, FoV;
-	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
+	GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID;
 	std::vector<unsigned int> indices;
 	cv::Vec3d residual;
 	int lightNumber = 0;
@@ -717,9 +722,9 @@ void denseSyntheticSample(std::string imageName, std::string calibration, double
 	
 	lightInvDir = glm::vec3(lightDirections.at<float>(0, 0), -lightDirections.at<float>(0, 2), lightDirections.at<float>(0, 1));
 
-	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
+	initialiseOpenGL(heightMap, normalMap, albedo, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, numberOfLights, calculateResidual, depthMVP, depthModelMatrix, MVP, ProjectionMatrix, ViewMatrix, ModelMatrix, depthBiasMVP, biasMatrix);
 	
-	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	RenderSynthetic(depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 
 	std::string outputFileName = imageName + ".txt";
 	std::ofstream outputFile(outputFileName, std::ios::app);
@@ -735,7 +740,7 @@ void denseSyntheticSample(std::string imageName, std::string calibration, double
 			for(int i = 0; i < numberOfLights; i++) {
 
 				// Render the polygons
-				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, specularIntensity, SpecularPowerID, specularPower);
+				renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, SpecularIntensityID, specularIntensity, SpecularPowerID, specularPower, DistanceID, Distance, LightPowerID, LightPower);
 				
 				meanSquaredError(i, height, width, textureImages, sum, gain, bias);
 				
@@ -755,9 +760,9 @@ void denseSyntheticSample(std::string imageName, std::string calibration, double
 
 	outputFile.close();
 
-	//specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
+	//specularMinimisation(SpecularIntensity, SpecularPower, Gain, Bias, imageName, residualValue, residual, totalResidual, residualImage, depthProjectionMatrix, depthViewMatrix, width, height, numberOfLights, SpecularIntensityID, SpecularPowerID, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, ModelMatrix, MVP, ViewMatrix, depthBiasMVP, lightInvDirs, textureImages);
 
-	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
+	//viewModel(residual, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, DistanceID, Distance, LightPowerID, LightPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID, modelPath);
 	
 	terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
 
diff --git a/apps/specular_estimation/src/specular_estimation.h b/apps/specular_estimation/src/specular_estimation.h
index 46a88b974573d3fb363e86c97bd802a70bb4e109..30169535a3086fbe169cebac8432bf9385b2a267 100644
--- a/apps/specular_estimation/src/specular_estimation.h
+++ b/apps/specular_estimation/src/specular_estimation.h
@@ -20,7 +20,7 @@ class SpecularEstimation {
 		// OpenCV
 		std::string imageName, modelPath, calibrationPath, calibration = "chrome", imagesPath = "/home/thomas/Documents/", folderPath = "2018-08-31", macbethPath = imagesPath + folderPath + "/macbeth/macbeth.", albedoPath = modelPath + "albedo.png", normalPath = modelPath + "normal.png", texturePath = modelPath + "texture.png";
 		int width = 1092, height = 728, numberOfLights = 6, lightNumber = 0;
-		double SpecularIntensity, SpecularPower, SpecularIntensitySynthetic, SpecularPowerSynthetic, totalResidual, residualValue, Gain = 1.0, Bias = 0.0;
+		double SpecularIntensity, SpecularPower, SpecularIntensitySynthetic, SpecularPowerSynthetic, Distance = 1.0, LightPower = 1.0, totalResidual, residualValue, Gain = 1.0, Bias = 0.0;
 		bool calculateResidual = false, perspectiveProjection = false, shadowControl = false, denseSample = false;
 		std::vector<unsigned int> indices;
 
@@ -37,7 +37,7 @@ class SpecularEstimation {
 		std::vector<glm::vec3> lightInvDirs;
 
 		// OpenGL
-		GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
+		GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID, DistanceID, LightPowerID;
 		glm::vec3 position, lightInvDir;
 		glm::mat4 depthProjectionMatrix, depthViewMatrix, depthModelMatrix = glm::mat4(1.0), depthMVP, ModelMatrix = glm::mat4(1.0), MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix, biasMatrix = glm::mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
 		float horizontalAngle, verticalAngle, FoV;
diff --git a/bin/specular_estimation b/bin/specular_estimation
index fd6d15cd7a36ea014421955acb65b0530e8c815f..5952f7d01b9844858582f7abf5cd7b8819adb673 100755
Binary files a/bin/specular_estimation and b/bin/specular_estimation differ
diff --git a/wood6 0.5 0.5 1 0.txt b/wood6 0.5 0.5 1 0.txt
new file mode 100644
index 0000000000000000000000000000000000000000..69dc6bad0823d9a216763b377248fd4c5773f974
--- /dev/null
+++ b/wood6 0.5 0.5 1 0.txt	
@@ -0,0 +1,11 @@
+Specular Intensity	Specular Power	Gain	Bias	Resiudal
+0.5	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.499999	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.5	0.499999	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
+0.5	0.5	1	0	12358.7
diff --git a/wood6 0.5 0.5 1 1.txt b/wood6 0.5 0.5 1 1.txt
new file mode 100644
index 0000000000000000000000000000000000000000..098e289f5f89ed730bc5887b6db2f2a7e74068bc
--- /dev/null
+++ b/wood6 0.5 0.5 1 1.txt	
@@ -0,0 +1,206 @@
+Specular Intensity	Specular Power	Gain	Bias	Resiudal
+0.5	0.5	1	0	9993.73
+0.5	0.5	1	0	9993.73
+0.499999	0.5	1	0	9993.73
+0.5	0.5	1	0	9993.73
+0.5	0.499999	1	0	9993.73
+0.5	0.5	1	0	9993.73
+0.5	0.5	1	0	9993.72
+0.5	0.5	1	0	9993.73
+0.5	0.5	1	0	9993.73
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.999999	0	1	0	12358.7
+1	1.49012e-08	1	0	12358.7
+1	-1.49012e-08	1	0	12358.7
+1	0	1	0	23815
+1	0	1	0	23815
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773643	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176871	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773643	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176871	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0.773644	0.176872	1	0	7592.52
+0	0	1	0	12011.7
+1.49012e-08	0	1	0	12011.7
+-1.49012e-08	0	1	0	12011.7
+0	1.49012e-08	1	0	12011.7
+0	-1.49012e-08	1	0	12011.7
+0	0	1	0	12011.7
+0	0	1	0	12011.7
+0	0	1	0	12011.7
+0	0	1	0	12011.7
+0.515168	0.0637104	1	0	7309.38
+0.515169	0.0637104	1	0	7309.37
+0.515167	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637103	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.37
+0.515168	0.0637104	1	0	7309.37
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515169	0.0637104	1	0	7309.37
+0.515167	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637103	1	0	7309.38
+0.515168	0.0637104	1	0	7309.38
+0.515168	0.0637104	1	0	7309.37
+0.515168	0.0637104	1	0	7309.37
+0.515168	0.0637104	1	0	7309.38
+0.864294	0	1	0	3059.56
+0.864295	0	1	0	3059.56
+0.864293	0	1	0	3059.57
+0.864294	1.49012e-08	1	0	3059.56
+0.864294	-1.49012e-08	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864295	0	1	0	3059.56
+0.864293	0	1	0	3059.57
+0.864294	1.49012e-08	1	0	3059.56
+0.864294	-1.49012e-08	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+0.864294	0	1	0	3059.56
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.999999	0	1	0	12358.7
+1	1.49012e-08	1	0	12358.7
+1	-1.49012e-08	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.868882	0	1	0	3012.8
+0.868883	0	1	0	3012.79
+0.868881	0	1	0	3012.8
+0.868882	1.49012e-08	1	0	3012.8
+0.868882	-1.49012e-08	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868883	0	1	0	3012.79
+0.868881	0	1	0	3012.8
+0.868882	1.49012e-08	1	0	3012.8
+0.868882	-1.49012e-08	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+0.868882	0	1	0	3012.8
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.999999	0	1	0	12358.7
+1	1.49012e-08	1	0	12358.7
+1	-1.49012e-08	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.874456	0	1	0	2980.11
+0.874457	0	1	0	2980.11
+0.874455	0	1	0	2980.12
+0.874456	1.49012e-08	1	0	2980.11
+0.874456	-1.49012e-08	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874457	0	1	0	2980.11
+0.874455	0	1	0	2980.12
+0.874456	1.49012e-08	1	0	2980.11
+0.874456	-1.49012e-08	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.999999	0	1	0	12358.7
+1	1.49012e-08	1	0	12358.7
+1	-1.49012e-08	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+1	0	1	0	12358.7
+0.880912	0	1	0	5688.02
+0.880913	0	1	0	5688.03
+0.880911	0	1	0	5688.02
+0.880912	1.49012e-08	1	0	5688.02
+0.880912	-1.49012e-08	1	0	5688.02
+0.880912	0	1	0	5688.03
+0.880912	0	1	0	5688.02
+0.880912	0	1	0	5688.02
+0.880912	0	1	0	5688.03
+0.874486	0	1	0	2980.77
+0.874487	0	1	0	2980.77
+0.874485	0	1	0	2980.77
+0.874486	1.49012e-08	1	0	2980.77
+0.874486	-1.49012e-08	1	0	2980.77
+0.874486	0	1	0	2980.77
+0.874486	0	1	0	2980.77
+0.874486	0	1	0	2980.77
+0.874486	0	1	0	2980.77
+0.874457	0	1	0	2980.14
+0.874458	0	1	0	2980.13
+0.874457	0	1	0	2980.14
+0.874457	1.49012e-08	1	0	2980.14
+0.874457	-1.49012e-08	1	0	2980.14
+0.874457	0	1	0	2980.14
+0.874457	0	1	0	2980.14
+0.874457	0	1	0	2980.14
+0.874457	0	1	0	2980.14
+0.874456	0	1	0	2980.12
+0.874457	0	1	0	2980.11
+0.874455	0	1	0	2980.12
+0.874456	1.49012e-08	1	0	2980.12
+0.874456	-1.49012e-08	1	0	2980.12
+0.874456	0	1	0	2980.12
+0.874456	0	1	0	2980.12
+0.874456	0	1	0	2980.12
+0.874456	0	1	0	2980.12
+0.874456	0	1	0	2980.11
+0.874457	0	1	0	2980.11
+0.874455	0	1	0	2980.12
+0.874456	1.49012e-08	1	0	2980.11
+0.874456	-1.49012e-08	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874457	0	1	0	2980.11
+0.874455	0	1	0	2980.12
+0.874456	1.49012e-08	1	0	2980.11
+0.874456	-1.49012e-08	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
+0.874456	0	1	0	2980.11
diff --git a/wood6 0.5 2 1 0.txt b/wood6 0.5 2 1 0.txt
deleted file mode 100644
index a06f2159019263a2cc66cb919566adb2ad574423..0000000000000000000000000000000000000000
--- a/wood6 0.5 2 1 0.txt	
+++ /dev/null
@@ -1,1118 +0,0 @@
-Specular Intensity	Specular Power	Gain	Bias	Resiudal
-0.5	2	1	0	12381.7
-0.5	2	1	0	12381.7
-0.499999	2	1	0	12381.7
-0.5	2	1	0	12381.7
-0.5	2	1	0	12381.7
-0.5	2	1	0	12381.7
-0.5	2	0.999999	0	12381.7
-0.5	2	1	1.49012e-08	12381.7
-0.5	2	1	-1.49012e-08	12381.7
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-0.999999	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.00999999	0	15.7241	9373.89
-1	0.01	1.49012e-08	15.7241	9373.89
-1	0.01	-1.49012e-08	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-0.999999	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.00999999	0	15.7241	9373.89
-1	0.01	1.49012e-08	15.7241	9373.89
-1	0.01	-1.49012e-08	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0	15.7241	9373.89
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-0.999999	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.00999999	0.750169	42.6439	3278.17
-1	0.01	0.75017	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6438	3278.18
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-0.999999	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.00999999	0.750169	42.6439	3278.17
-1	0.01	0.75017	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6439	3278.17
-1	0.01	0.750169	42.6438	3278.18
-0	0.01	1.35937	54.841	3974.9
-1.49012e-08	0.01	1.35937	54.841	3974.9
--1.49012e-08	0.01	1.35937	54.841	3974.9
-0	0.01	1.35937	54.841	3974.9
-0	0.00999999	1.35937	54.841	3974.9
-0	0.01	1.35938	54.841	3974.9
-0	0.01	1.35937	54.841	3974.9
-0	0.01	1.35937	54.841	3974.89
-0	0.01	1.35937	54.8409	3974.9
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777194	0.01	0.867631	44.9956	2985.03
-0.777192	0.01	0.867631	44.9956	2985.03
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777193	0.00999999	0.867631	44.9956	2985.03
-0.777193	0.01	0.867632	44.9956	2985.03
-0.777193	0.01	0.86763	44.9956	2985.03
-0.777193	0.01	0.867631	44.9957	2985.02
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777194	0.01	0.867631	44.9956	2985.03
-0.777192	0.01	0.867631	44.9956	2985.03
-0.777193	0.01	0.867631	44.9956	2985.03
-0.777193	0.00999999	0.867631	44.9956	2985.03
-0.777193	0.01	0.867632	44.9956	2985.03
-0.777193	0.01	0.86763	44.9956	2985.03
-0.777193	0.01	0.867631	44.9957	2985.02
-0.777193	0.01	0.867631	44.9956	2985.03
-1	0.01	2	61.4513	5471.16
-1	0.01	2	61.4513	5471.16
-0.999999	0.01	2	61.4513	5471.17
-1	0.01	2	61.4513	5471.16
-1	0.00999999	2	61.4513	5471.16
-1	0.01	2	61.4513	5471.17
-1	0.01	2	61.4513	5471.15
-1	0.01	2	61.4514	5471.17
-1	0.01	2	61.4513	5471.16
-1	0.01	2	52.39	5020.1
-1	0.01	2	52.39	5020.09
-0.999999	0.01	2	52.39	5020.1
-1	0.01	2	52.39	5020.1
-1	0.00999999	2	52.39	5020.1
-1	0.01	2	52.39	5020.1
-1	0.01	2	52.39	5020.09
-1	0.01	2	52.39	5020.1
-1	0.01	2	52.3899	5020.09
-1	0.01	1.48382	47.032	3318.92
-1	0.01	1.48382	47.032	3318.92
-0.999999	0.01	1.48382	47.032	3318.93
-1	0.01	1.48382	47.032	3318.92
-1	0.00999999	1.48382	47.032	3318.92
-1	0.01	1.48382	47.032	3318.93
-1	0.01	1.48382	47.032	3318.92
-1	0.01	1.48382	47.0321	3318.92
-1	0.01	1.48382	47.032	3318.92
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810725	0.01	0.935002	45.2183	2962.09
-0.810723	0.01	0.935002	45.2183	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810724	0.00999999	0.935002	45.2183	2962.09
-0.810724	0.01	0.935003	45.2183	2962.09
-0.810724	0.01	0.935001	45.2183	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810724	0.01	0.935002	45.2182	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810725	0.01	0.935002	45.2183	2962.09
-0.810723	0.01	0.935002	45.2183	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810724	0.00999999	0.935002	45.2183	2962.09
-0.810724	0.01	0.935003	45.2183	2962.09
-0.810724	0.01	0.935001	45.2183	2962.09
-0.810724	0.01	0.935002	45.2183	2962.09
-0.810724	0.01	0.935002	45.2182	2962.09
-1	0.01	0	63.4865	3339.74
-1	0.01	0	63.4865	3339.74
-0.999999	0.01	0	63.4865	3339.74
-1	0.01	0	63.4865	3339.74
-1	0.00999999	0	63.4865	3339.74
-1	0.01	1.49012e-08	63.4865	3339.74
-1	0.01	-1.49012e-08	63.4865	3339.74
-1	0.01	0	63.4866	3339.74
-1	0.01	0	63.4864	3339.75
-1	0.01	0	56.1792	3967.3
-1	0.01	0	56.1792	3967.3
-0.999999	0.01	0	56.1792	3967.3
-1	0.01	0	56.1792	3967.3
-1	0.00999999	0	56.1792	3967.3
-1	0.01	1.49012e-08	56.1792	3967.3
-1	0.01	-1.49012e-08	56.1792	3967.3
-1	0.01	0	56.1793	3967.3
-1	0.01	0	56.1792	3967.31
-1	0.01	0	50.5583	4522.71
-1	0.01	0	50.5583	4522.71
-0.999999	0.01	0	50.5583	4522.71
-1	0.01	0	50.5583	4522.71
-1	0.00999999	0	50.5583	4522.71
-1	0.01	1.49012e-08	50.5583	4522.71
-1	0.01	-1.49012e-08	50.5583	4522.71
-1	0.01	0	50.5584	4522.7
-1	0.01	0	50.5583	4522.71
-1	0.01	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6454	4361.32
-0.999999	0.01	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6454	4361.32
-1	0.00999999	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6454	4361.32
-1	0.01	0.126896	47.6453	4361.32
-0.918604	0.01	0.712715	45.8859	3062.93
-0.918605	0.01	0.712715	45.8859	3062.93
-0.918603	0.01	0.712715	45.8859	3062.93
-0.918604	0.01	0.712715	45.8859	3062.93
-0.918604	0.00999999	0.712715	45.8859	3062.93
-0.918604	0.01	0.712716	45.8859	3062.93
-0.918604	0.01	0.712715	45.8859	3062.93
-0.918604	0.01	0.712715	45.8859	3062.93
-0.918604	0.01	0.712715	45.8858	3062.94
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827019	0.01	0.901428	45.3191	2952.44
-0.827017	0.01	0.901428	45.3191	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827018	0.00999999	0.901428	45.3191	2952.44
-0.827018	0.01	0.901429	45.3191	2952.44
-0.827018	0.01	0.901427	45.3191	2952.44
-0.827018	0.01	0.901428	45.3192	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827019	0.01	0.901428	45.3191	2952.44
-0.827017	0.01	0.901428	45.3191	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-0.827018	0.00999999	0.901428	45.3191	2952.44
-0.827018	0.01	0.901429	45.3191	2952.44
-0.827018	0.01	0.901427	45.3191	2952.44
-0.827018	0.01	0.901428	45.3192	2952.44
-0.827018	0.01	0.901428	45.3191	2952.44
-1	0.73165	2	62.2557	3144.42
-1	0.73165	2	62.2557	3144.42
-0.999999	0.73165	2	62.2557	3144.43
-1	0.731651	2	62.2557	3144.42
-1	0.731649	2	62.2557	3144.43
-1	0.73165	2	62.2557	3144.43
-1	0.73165	2	62.2557	3144.42
-1	0.73165	2	62.2558	3144.42
-1	0.73165	2	62.2557	3144.42
-1	0.187529	2	49.4856	4450.6
-1	0.187529	2	49.4856	4450.6
-0.999999	0.187529	2	49.4856	4450.61
-1	0.187529	2	49.4856	4450.6
-1	0.187529	2	49.4856	4450.61
-1	0.187529	2	49.4856	4450.61
-1	0.187529	2	49.4856	4450.6
-1	0.187529	2	49.4856	4450.61
-1	0.187529	2	49.4855	4450.6
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867847	0.016632	0.974931	45.4748	2939.89
-0.867845	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974932	45.4748	2939.89
-0.867846	0.016632	0.97493	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4747	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867847	0.016632	0.974931	45.4748	2939.89
-0.867845	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974932	45.4748	2939.89
-0.867846	0.016632	0.97493	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4748	2939.89
-0.867846	0.016632	0.974931	45.4747	2939.89
-1	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-0.999999	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-1	0.016632	1.49012e-08	70.381	2845.54
-1	0.016632	-1.49012e-08	70.381	2845.54
-1	0.016632	0	70.3811	2845.54
-1	0.016632	0	70.3809	2845.55
-1	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-0.999999	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-1	0.016632	0	70.381	2845.54
-1	0.016632	1.49012e-08	70.381	2845.54
-1	0.016632	-1.49012e-08	70.381	2845.54
-1	0.016632	0	70.3811	2845.54
-1	0.016632	0	70.3809	2845.55
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.84
-0.999999	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598856	92.3325	2123.85
-1	0.016632	0.598854	92.3325	2123.84
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3324	2123.84
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.84
-0.999999	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598856	92.3325	2123.85
-1	0.016632	0.598854	92.3325	2123.84
-1	0.016632	0.598855	92.3325	2123.85
-1	0.016632	0.598855	92.3324	2123.84
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2128	3279.62
-0.999999	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.143998	59.2129	3279.61
-1	0.016632	0.143998	59.2128	3279.62
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-0.999999	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.44152	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8764	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-0.999999	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.44152	80.8765	1941.87
-1	0.016632	0.441521	80.8765	1941.87
-1	0.016632	0.441521	80.8764	1941.87
-1	0.016632	0	132.052	2653.49
-1	0.016632	0	132.052	2653.49
-0.999999	0.016632	0	132.052	2653.49
-1	0.016632	0	132.052	2653.49
-1	0.016632	0	132.052	2653.49
-1	0.016632	1.49012e-08	132.052	2653.49
-1	0.016632	-1.49012e-08	132.052	2653.49
-1	0.016632	0	132.052	2653.5
-1	0.016632	0	132.052	2653.48
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-0.999999	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.105504	84.1159	2018.2
-1	0.016632	0.105504	84.1158	2018.2
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-0.999999	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9014	1931.8
-1	0.016632	0.335215	81.9012	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-0.999999	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9013	1931.8
-1	0.016632	0.335215	81.9014	1931.8
-1	0.016632	0.335215	81.9012	1931.8
-0	0.016632	2	117.463	2065.64
-1.49012e-08	0.016632	2	117.463	2065.64
--1.49012e-08	0.016632	2	117.463	2065.64
-0	0.016632	2	117.463	2065.64
-0	0.016632	2	117.463	2065.64
-0	0.016632	2	117.463	2065.64
-0	0.016632	2	117.463	2065.64
-0	0.016632	2	117.463	2065.64
-0	0.016632	2	117.462	2065.63
-0	0.016632	1.46127	96.13	1821.7
-1.49012e-08	0.016632	1.46127	96.13	1821.7
--1.49012e-08	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.1301	1821.7
-0	0.016632	1.46127	96.1299	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-1.49012e-08	0.016632	1.46127	96.13	1821.7
--1.49012e-08	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.13	1821.7
-0	0.016632	1.46127	96.1301	1821.7
-0	0.016632	1.46127	96.1299	1821.7
-0	0.016632	2	181.436	8267.69
-1.49012e-08	0.016632	2	181.436	8267.69
--1.49012e-08	0.016632	2	181.436	8267.69
-0	0.016632	2	181.436	8267.69
-0	0.016632	2	181.436	8267.69
-0	0.016632	2	181.436	8267.69
-0	0.016632	2	181.436	8267.69
-0	0.016632	2	181.436	8267.72
-0	0.016632	2	181.436	8267.66
-0	0.016632	2	141.519	3437.59
-1.49012e-08	0.016632	2	141.519	3437.59
--1.49012e-08	0.016632	2	141.519	3437.59
-0	0.016632	2	141.519	3437.59
-0	0.016632	2	141.519	3437.59
-0	0.016632	2	141.519	3437.59
-0	0.016632	2	141.519	3437.59
-0	0.016632	2	141.519	3437.6
-0	0.016632	2	141.519	3437.58
-0	0.016632	2	117.469	2065.86
-1.49012e-08	0.016632	2	117.469	2065.86
--1.49012e-08	0.016632	2	117.469	2065.86
-0	0.016632	2	117.469	2065.86
-0	0.016632	2	117.469	2065.86
-0	0.016632	2	117.469	2065.86
-0	0.016632	2	117.469	2065.86
-0	0.016632	2	117.469	2065.87
-0	0.016632	2	117.469	2065.86
-0	0.016632	2	106.042	1819.49
-1.49012e-08	0.016632	2	106.042	1819.49
--1.49012e-08	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-1.49012e-08	0.016632	2	106.042	1819.49
--1.49012e-08	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	2	106.042	1819.49
-0	0.016632	0	16.561	9228.9
-1.49012e-08	0.016632	0	16.561	9228.9
--1.49012e-08	0.016632	0	16.561	9228.9
-0	0.016632	0	16.561	9228.9
-0	0.016632	0	16.561	9228.9
-0	0.016632	1.49012e-08	16.561	9228.9
-0	0.016632	-1.49012e-08	16.561	9228.9
-0	0.016632	0	16.561	9228.9
-0	0.016632	0	16.5609	9228.9
-0	0.016632	0	60.0184	3624.27
-1.49012e-08	0.016632	0	60.0184	3624.27
--1.49012e-08	0.016632	0	60.0184	3624.27
-0	0.016632	0	60.0184	3624.27
-0	0.016632	0	60.0184	3624.27
-0	0.016632	1.49012e-08	60.0184	3624.27
-0	0.016632	-1.49012e-08	60.0184	3624.27
-0	0.016632	0	60.0185	3624.26
-0	0.016632	0	60.0184	3624.27
-0	0.016632	0	84.6989	2122.95
-1.49012e-08	0.016632	0	84.6989	2122.95
--1.49012e-08	0.016632	0	84.6989	2122.95
-0	0.016632	0	84.6989	2122.95
-0	0.016632	0	84.6989	2122.95
-0	0.016632	1.49012e-08	84.6989	2122.95
-0	0.016632	-1.49012e-08	84.6989	2122.95
-0	0.016632	0	84.699	2122.95
-0	0.016632	0	84.6988	2122.96
-0	0.016632	0	96.4661	1836.04
-1.49012e-08	0.016632	0	96.4661	1836.04
--1.49012e-08	0.016632	0	96.4661	1836.04
-0	0.016632	0	96.4661	1836.04
-0	0.016632	0	96.4661	1836.04
-0	0.016632	1.49012e-08	96.4661	1836.04
-0	0.016632	-1.49012e-08	96.4661	1836.04
-0	0.016632	0	96.4662	1836.04
-0	0.016632	0	96.466	1836.04
-0	0.016632	0	101.459	1797.98
-1.49012e-08	0.016632	0	101.459	1797.98
--1.49012e-08	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	1.49012e-08	101.459	1797.98
-0	0.016632	-1.49012e-08	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-1.49012e-08	0.016632	0	101.459	1797.98
--1.49012e-08	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	1.49012e-08	101.459	1797.98
-0	0.016632	-1.49012e-08	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	0	101.459	1797.98
-0	0.016632	2	441.309	117621
-1.49012e-08	0.016632	2	441.309	117621
--1.49012e-08	0.016632	2	441.309	117621
-0	0.016632	2	441.309	117621
-0	0.016632	2	441.309	117621
-0	0.016632	2	441.309	117621
-0	0.016632	2	441.309	117621
-0	0.016632	2	441.31	117621
-0	0.016632	2	441.309	117621
-0	0.016632	2	260.374	27201.8
-1.49012e-08	0.016632	2	260.374	27201.8
--1.49012e-08	0.016632	2	260.374	27201.8
-0	0.016632	2	260.374	27201.8
-0	0.016632	2	260.374	27201.8
-0	0.016632	2	260.374	27201.8
-0	0.016632	2	260.374	27201.8
-0	0.016632	2	260.375	27201.9
-0	0.016632	2	260.374	27201.8
-0	0.016632	2	174.389	7183.31
-1.49012e-08	0.016632	2	174.389	7183.31
--1.49012e-08	0.016632	2	174.389	7183.31
-0	0.016632	2	174.389	7183.31
-0	0.016632	2	174.389	7183.31
-0	0.016632	2	174.389	7183.31
-0	0.016632	2	174.389	7183.31
-0	0.016632	2	174.389	7183.33
-0	0.016632	2	174.388	7183.28
-0	0.016632	2	132.912	2813.76
-1.49012e-08	0.016632	2	132.912	2813.76
--1.49012e-08	0.016632	2	132.912	2813.76
-0	0.016632	2	132.912	2813.76
-0	0.016632	2	132.912	2813.76
-0	0.016632	2	132.912	2813.76
-0	0.016632	2	132.912	2813.76
-0	0.016632	2	132.912	2813.77
-0	0.016632	2	132.912	2813.75
-0	0.016632	2	112.542	1927.61
-1.49012e-08	0.016632	2	112.542	1927.61
--1.49012e-08	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.61
-0	0.016632	2	112.542	1927.6
-0	0.016632	1.13897	104.315	1799.97
-1.49012e-08	0.016632	1.13897	104.315	1799.97
--1.49012e-08	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	1.13897	104.315	1799.97
-0	0.016632	0.505837	102.727	1794.67
-1.49012e-08	0.016632	0.505837	102.727	1794.67
--1.49012e-08	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505838	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.728	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-1.49012e-08	0.016632	0.505837	102.727	1794.67
--1.49012e-08	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505838	102.727	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	0.505837	102.728	1794.67
-0	0.016632	0.505837	102.727	1794.67
-0	0.016632	2	-982.171	1.175e+06
-1.49012e-08	0.016632	2	-982.171	1.175e+06
--1.49012e-08	0.016632	2	-982.171	1.175e+06
-0	0.016632	2	-982.171	1.175e+06
-0	0.016632	2	-982.171	1.175e+06
-0	0.016632	2	-982.171	1.175e+06
-0	0.016632	2	-982.171	1.175e+06
-0	0.016632	2	-982.17	1.175e+06
-0	0.016632	2	-982.172	1.175e+06
-0	0.016632	0.955822	101.643	1793.66
-1.49012e-08	0.016632	0.955822	101.643	1793.66
--1.49012e-08	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955823	101.643	1793.66
-0	0.016632	0.955821	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.642	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-1.49012e-08	0.016632	0.955822	101.643	1793.66
--1.49012e-08	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955823	101.643	1793.66
-0	0.016632	0.955821	101.643	1793.66
-0	0.016632	0.955822	101.643	1793.66
-0	0.016632	0.955822	101.642	1793.66
-0	0.016632	2	1712.77	2.59966e+06
-1.49012e-08	0.016632	2	1712.77	2.59966e+06
--1.49012e-08	0.016632	2	1712.77	2.59966e+06
-0	0.016632	2	1712.77	2.59966e+06
-0	0.016632	2	1712.77	2.59966e+06
-0	0.016632	2	1712.77	2.59966e+06
-0	0.016632	2	1712.77	2.59966e+06
-0	0.016632	2	1712.77	2.59967e+06
-0	0.016632	2	1712.76	2.59966e+06
-0	0.016632	2	824.415	525158
-1.49012e-08	0.016632	2	824.415	525158
--1.49012e-08	0.016632	2	824.415	525158
-0	0.016632	2	824.415	525158
-0	0.016632	2	824.415	525158
-0	0.016632	2	824.415	525158
-0	0.016632	2	824.415	525158
-0	0.016632	2	824.416	525159
-0	0.016632	2	824.414	525157
-0	0.016632	2	430.771	110559
-1.49012e-08	0.016632	2	430.771	110559
--1.49012e-08	0.016632	2	430.771	110559
-0	0.016632	2	430.771	110559
-0	0.016632	2	430.771	110559
-0	0.016632	2	430.771	110559
-0	0.016632	2	430.771	110559
-0	0.016632	2	430.772	110559
-0	0.016632	2	430.771	110559
-0	0.016632	2	250.716	24216
-1.49012e-08	0.016632	2	250.716	24216
--1.49012e-08	0.016632	2	250.716	24216
-0	0.016632	2	250.716	24216
-0	0.016632	2	250.716	24216
-0	0.016632	2	250.716	24216
-0	0.016632	2	250.716	24216
-0	0.016632	2	250.716	24216
-0	0.016632	2	250.715	24215.9
-0	0.016632	2	167.566	6228.12
-1.49012e-08	0.016632	2	167.566	6228.12
--1.49012e-08	0.016632	2	167.566	6228.12
-0	0.016632	2	167.566	6228.12
-0	0.016632	2	167.566	6228.12
-0	0.016632	2	167.566	6228.12
-0	0.016632	2	167.566	6228.12
-0	0.016632	2	167.566	6228.15
-0	0.016632	2	167.566	6228.1
-0	0.016632	2	127.88	2517.67
-1.49012e-08	0.016632	2	127.88	2517.67
--1.49012e-08	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.67
-0	0.016632	2	127.88	2517.66
-0	0.016632	2	108.613	1852.15
-1.49012e-08	0.016632	2	108.613	1852.15
--1.49012e-08	0.016632	2	108.613	1852.15
-0	0.016632	2	108.613	1852.15
-0	0.016632	2	108.613	1852.15
-0	0.016632	2	108.613	1852.15
-0	0.016632	2	108.613	1852.15
-0	0.016632	2	108.614	1852.16
-0	0.016632	2	108.613	1852.15
-0	0.016632	1.16544	102.352	1793.76
-1.49012e-08	0.016632	1.16544	102.352	1793.76
--1.49012e-08	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.16544	102.352	1793.77
-0	0.016632	1.16544	102.352	1793.76
-0	0.016632	1.04854	101.957	1793.49
-1.49012e-08	0.016632	1.04854	101.957	1793.49
--1.49012e-08	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	1.04854	101.956	1793.49
-0	0.016632	1.04854	101.957	1793.49
-0	0.016632	2	1675.41	2.48063e+06
-1.49012e-08	0.016632	2	1675.41	2.48063e+06
--1.49012e-08	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	1675.41	2.48064e+06
-0	0.016632	2	1675.41	2.48063e+06
-0	0.016632	2	807.637	501164
-1.49012e-08	0.016632	2	807.637	501164
--1.49012e-08	0.016632	2	807.637	501164
-0	0.016632	2	807.637	501164
-0	0.016632	2	807.637	501164
-0	0.016632	2	807.637	501164
-0	0.016632	2	807.637	501164
-0	0.016632	2	807.638	501165
-0	0.016632	2	807.636	501163
-0	0.016632	2	423.113	105566
-1.49012e-08	0.016632	2	423.113	105566
--1.49012e-08	0.016632	2	423.113	105566
-0	0.016632	2	423.113	105566
-0	0.016632	2	423.113	105566
-0	0.016632	2	423.113	105566
-0	0.016632	2	423.113	105566
-0	0.016632	2	423.113	105567
-0	0.016632	2	423.113	105566
-0	0.016632	2	247.201	23175.7
-1.49012e-08	0.016632	2	247.201	23175.7
--1.49012e-08	0.016632	2	247.201	23175.7
-0	0.016632	2	247.201	23175.7
-0	0.016632	2	247.201	23175.7
-0	0.016632	2	247.201	23175.7
-0	0.016632	2	247.201	23175.7
-0	0.016632	2	247.201	23175.8
-0	0.016632	2	247.201	23175.6
-0	0.016632	2	165.92	6011.64
-1.49012e-08	0.016632	2	165.92	6011.64
--1.49012e-08	0.016632	2	165.92	6011.64
-0	0.016632	2	165.92	6011.64
-0	0.016632	2	165.92	6011.64
-0	0.016632	2	165.92	6011.64
-0	0.016632	2	165.92	6011.64
-0	0.016632	2	165.92	6011.66
-0	0.016632	2	165.92	6011.62
-0	0.016632	2	127.072	2474.83
-1.49012e-08	0.016632	2	127.072	2474.83
--1.49012e-08	0.016632	2	127.072	2474.83
-0	0.016632	2	127.072	2474.83
-0	0.016632	2	127.072	2474.83
-0	0.016632	2	127.072	2474.83
-0	0.016632	2	127.072	2474.83
-0	0.016632	2	127.072	2474.84
-0	0.016632	2	127.072	2474.83
-0	0.016632	2	108.254	1846.79
-1.49012e-08	0.016632	2	108.254	1846.79
--1.49012e-08	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	2	108.254	1846.79
-0	0.016632	1.15202	102.307	1793.71
-1.49012e-08	0.016632	1.15202	102.307	1793.71
--1.49012e-08	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.15202	102.307	1793.71
-0	0.016632	1.0485	101.956	1793.49
-1.49012e-08	0.016632	1.0485	101.956	1793.49
--1.49012e-08	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.04851	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	1.0485	101.956	1793.49
-0	0.016632	2	1483.2	1.91235e+06
-1.49012e-08	0.016632	2	1483.2	1.91235e+06
--1.49012e-08	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	1483.21	1.91236e+06
-0	0.016632	2	1483.2	1.91235e+06
-0	0.016632	2	721.284	386576
-1.49012e-08	0.016632	2	721.284	386576
--1.49012e-08	0.016632	2	721.284	386576
-0	0.016632	2	721.284	386576
-0	0.016632	2	721.284	386576
-0	0.016632	2	721.284	386576
-0	0.016632	2	721.284	386576
-0	0.016632	2	721.284	386577
-0	0.016632	2	721.283	386575
-0	0.016632	2	383.667	81708.5
-1.49012e-08	0.016632	2	383.667	81708.5
--1.49012e-08	0.016632	2	383.667	81708.5
-0	0.016632	2	383.667	81708.5
-0	0.016632	2	383.667	81708.5
-0	0.016632	2	383.667	81708.5
-0	0.016632	2	383.667	81708.5
-0	0.016632	2	383.668	81708.7
-0	0.016632	2	383.667	81708.3
-0	0.016632	2	229.084	18205.7
-1.49012e-08	0.016632	2	229.084	18205.7
--1.49012e-08	0.016632	2	229.084	18205.7
-0	0.016632	2	229.084	18205.7
-0	0.016632	2	229.084	18205.7
-0	0.016632	2	229.084	18205.7
-0	0.016632	2	229.084	18205.7
-0	0.016632	2	229.085	18205.8
-0	0.016632	2	229.084	18205.7
-0	0.016632	2	157.407	4978.35
-1.49012e-08	0.016632	2	157.407	4978.35
--1.49012e-08	0.016632	2	157.407	4978.35
-0	0.016632	2	157.407	4978.35
-0	0.016632	2	157.407	4978.35
-0	0.016632	2	157.407	4978.35
-0	0.016632	2	157.407	4978.35
-0	0.016632	2	157.407	4978.37
-0	0.016632	2	157.407	4978.34
-0	0.016632	2	122.879	2273.58
-1.49012e-08	0.016632	2	122.879	2273.58
--1.49012e-08	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.58
-0	0.016632	2	122.879	2273.57
-0	0.016632	2	106.46	1823.9
-1.49012e-08	0.016632	2	106.46	1823.9
--1.49012e-08	0.016632	2	106.46	1823.9
-0	0.016632	2	106.46	1823.9
-0	0.016632	2	106.46	1823.9
-0	0.016632	2	106.46	1823.9
-0	0.016632	2	106.46	1823.9
-0	0.016632	2	106.461	1823.9
-0	0.016632	2	106.46	1823.9
-0	0.016632	1.09277	102.106	1793.53
-1.49012e-08	0.016632	1.09277	102.106	1793.53
--1.49012e-08	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	1.09277	102.106	1793.53
-0	0.016632	2	747.269	419489
-1.49012e-08	0.016632	2	747.269	419489
--1.49012e-08	0.016632	2	747.269	419489
-0	0.016632	2	747.269	419489
-0	0.016632	2	747.269	419489
-0	0.016632	2	747.269	419489
-0	0.016632	2	747.269	419489
-0	0.016632	2	747.269	419490
-0	0.016632	2	747.268	419488
-0	0.016632	2	390.341	85526.3
-1.49012e-08	0.016632	2	390.341	85526.3
--1.49012e-08	0.016632	2	390.341	85526.3
-0	0.016632	2	390.341	85526.3
-0	0.016632	2	390.341	85526.3
-0	0.016632	2	390.341	85526.3
-0	0.016632	2	390.341	85526.3
-0	0.016632	2	390.342	85526.6
-0	0.016632	2	390.341	85526.1
-0	0.016632	2	232.16	19003.1
-1.49012e-08	0.016632	2	232.16	19003.1
--1.49012e-08	0.016632	2	232.16	19003.1
-0	0.016632	2	232.16	19003.1
-0	0.016632	2	232.16	19003.1
-0	0.016632	2	232.16	19003.1
-0	0.016632	2	232.16	19003.1
-0	0.016632	2	232.16	19003.2
-0	0.016632	2	232.159	19003.1
-0	0.016632	2	158.856	5144.01
-1.49012e-08	0.016632	2	158.856	5144.01
--1.49012e-08	0.016632	2	158.856	5144.01
-0	0.016632	2	158.856	5144.01
-0	0.016632	2	158.856	5144.01
-0	0.016632	2	158.856	5144.01
-0	0.016632	2	158.856	5144.01
-0	0.016632	2	158.856	5144.03
-0	0.016632	2	158.856	5143.99
-0	0.016632	2	123.594	2305.4
-1.49012e-08	0.016632	2	123.594	2305.4
--1.49012e-08	0.016632	2	123.594	2305.4
-0	0.016632	2	123.594	2305.4
-0	0.016632	2	123.594	2305.4
-0	0.016632	2	123.594	2305.4
-0	0.016632	2	123.594	2305.4
-0	0.016632	2	123.594	2305.41
-0	0.016632	2	123.594	2305.4
-0	0.016632	2	106.756	1827.23
-1.49012e-08	0.016632	2	106.756	1827.23
--1.49012e-08	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	2	106.756	1827.23
-0	0.016632	1.10183	102.137	1793.55
-1.49012e-08	0.016632	1.10183	102.137	1793.55
--1.49012e-08	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	1.10183	102.137	1793.55
-0	0.016632	2	165.366	5939.94
-1.49012e-08	0.016632	2	165.366	5939.94
--1.49012e-08	0.016632	2	165.366	5939.94
-0	0.016632	2	165.366	5939.94
-0	0.016632	2	165.366	5939.94
-0	0.016632	2	165.366	5939.94
-0	0.016632	2	165.366	5939.94
-0	0.016632	2	165.366	5939.96
-0	0.016632	2	165.366	5939.91
-0	0.016632	2	121.302	2206.97
-1.49012e-08	0.016632	2	121.302	2206.97
--1.49012e-08	0.016632	2	121.302	2206.97
-0	0.016632	2	121.302	2206.97
-0	0.016632	2	121.302	2206.97
-0	0.016632	2	121.302	2206.97
-0	0.016632	2	121.302	2206.97
-0	0.016632	2	121.302	2206.97
-0	0.016632	2	121.301	2206.96
-0	0.016632	1.9457	104.994	1809.48
-1.49012e-08	0.016632	1.9457	104.994	1809.48
--1.49012e-08	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.9457	104.994	1809.48
-0	0.016632	1.05332	101.973	1793.49
-1.49012e-08	0.016632	1.05332	101.973	1793.49
--1.49012e-08	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-1.49012e-08	0.016632	1.05332	101.973	1793.49
--1.49012e-08	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	1.05332	101.973	1793.49
-0	0.016632	2	41.0852	5380.66
-1.49012e-08	0.016632	2	41.0852	5380.66
--1.49012e-08	0.016632	2	41.0852	5380.66
-0	0.016632	2	41.0852	5380.66
-0	0.016632	2	41.0852	5380.66
-0	0.016632	2	41.0852	5380.66
-0	0.016632	2	41.0852	5380.66
-0	0.016632	2	41.0852	5380.65
-0	0.016632	2	41.0851	5380.66
-0	0.016632	1.11162	101.814	1793.42
-1.49012e-08	0.016632	1.11162	101.814	1793.42
--1.49012e-08	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.813	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-1.49012e-08	0.016632	1.11162	101.814	1793.42
--1.49012e-08	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.814	1793.42
-0	0.016632	1.11162	101.813	1793.42
-0	0.016632	2	83.56	2097.11
-1.49012e-08	0.016632	2	83.56	2097.11
--1.49012e-08	0.016632	2	83.56	2097.11
-0	0.016632	2	83.56	2097.11
-0	0.016632	2	83.56	2097.11
-0	0.016632	2	83.56	2097.11
-0	0.016632	2	83.56	2097.11
-0	0.016632	2	83.5601	2097.11
-0	0.016632	2	83.5599	2097.12
-0	0.016632	1.20223	101.665	1793.35
-1.49012e-08	0.016632	1.20223	101.665	1793.35
--1.49012e-08	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-1.49012e-08	0.016632	1.20223	101.665	1793.35
--1.49012e-08	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	1.20223	101.665	1793.35
-0	0.016632	2	108.161	1845.45
-1.49012e-08	0.016632	2	108.161	1845.45
--1.49012e-08	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	108.161	1845.45
-0	0.016632	2	103.647	1800.95
-1.49012e-08	0.016632	2	103.647	1800.95
--1.49012e-08	0.016632	2	103.647	1800.95
-0	0.016632	2	103.647	1800.95
-0	0.016632	2	103.647	1800.95
-0	0.016632	2	103.647	1800.95
-0	0.016632	2	103.647	1800.95
-0	0.016632	2	103.647	1800.95
-0	0.016632	2	103.646	1800.95
-0	0.016632	1.89743	102.309	1795.19
-1.49012e-08	0.016632	1.89743	102.309	1795.19
--1.49012e-08	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.89743	102.309	1795.19
-0	0.016632	1.31297	101.768	1793.33
-1.49012e-08	0.016632	1.31297	101.768	1793.33
--1.49012e-08	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-1.49012e-08	0.016632	1.31297	101.768	1793.33
--1.49012e-08	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.31297	101.768	1793.33
-0	0.016632	1.04481	95.0353	1839.71
-1.49012e-08	0.016632	1.04481	95.0353	1839.71
--1.49012e-08	0.016632	1.04481	95.0353	1839.71
-0	0.016632	1.04481	95.0353	1839.71
-0	0.016632	1.04481	95.0353	1839.71
-0	0.016632	1.04481	95.0353	1839.71
-0	0.016632	1.04481	95.0353	1839.71
-0	0.016632	1.04481	95.0354	1839.71
-0	0.016632	1.04481	95.0352	1839.71
-0	0.016632	1.30639	101.603	1793.3
-1.49012e-08	0.016632	1.30639	101.603	1793.3
--1.49012e-08	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-1.49012e-08	0.016632	1.30639	101.603	1793.3
--1.49012e-08	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	1.30639	101.603	1793.3
-0	0.016632	2	101.378	1793.98
-1.49012e-08	0.016632	2	101.378	1793.98
--1.49012e-08	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	2	101.378	1793.98
-0	0.016632	1.71946	101.525	1793.52
-1.49012e-08	0.016632	1.71946	101.525	1793.52
--1.49012e-08	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.525	1793.52
-0	0.016632	1.71946	101.524	1793.52
-0	0.016632	1.40884	101.583	1793.29
-1.49012e-08	0.016632	1.40884	101.583	1793.29
--1.49012e-08	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-1.49012e-08	0.016632	1.40884	101.583	1793.29
--1.49012e-08	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.40884	101.583	1793.29
-0	0.016632	1.09188	99.0121	1801.16
-1.49012e-08	0.016632	1.09188	99.0121	1801.16
--1.49012e-08	0.016632	1.09188	99.0121	1801.16
-0	0.016632	1.09188	99.0121	1801.16
-0	0.016632	1.09188	99.0121	1801.16
-0	0.016632	1.09188	99.0121	1801.16
-0	0.016632	1.09188	99.0121	1801.16
-0	0.016632	1.09188	99.0122	1801.16
-0	0.016632	1.09188	99.012	1801.16
-0	0.016632	1.40046	101.515	1793.29
-1.49012e-08	0.016632	1.40046	101.515	1793.29
--1.49012e-08	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40045	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-1.49012e-08	0.016632	1.40046	101.515	1793.29
--1.49012e-08	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40045	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.40046	101.515	1793.29
-0	0.016632	1.41885	101.501	1793.29
-1.49012e-08	0.016632	1.41885	101.501	1793.29
--1.49012e-08	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.41885	101.501	1793.29
-0	0.016632	1.40607	101.511	1793.29
-1.49012e-08	0.016632	1.40607	101.511	1793.29
--1.49012e-08	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40606	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40607	101.511	1793.29
-0	0.016632	1.40046	101.515	1793.29