diff --git a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o
index 2093a391c910169bfeb9ec48481543c2d3bc26d9..9d994abfba9f9c03429638c438913de47fb1cd6a 100644
Binary files a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o and b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o differ
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 7536ca0838313e2c78786a1afa3cf058c11a3603..6fd00b40bff01b48fa6b89750836a4e8966c23e2 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 cb259dd10e324fa69fc040a84c74c7d425db390d..36bd3faf392c99327bc641a647e2f4c63177000c 100644
--- a/apps/specular_estimation/src/Ceres.h
+++ b/apps/specular_estimation/src/Ceres.h
@@ -37,11 +37,13 @@ class MyScalarCostFunctor {
 				
 				// 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_, RoughnessID_, roughness, MetallicID_, metallic, LightDistanceID_, lightDistance_, LightIntensityID_, lightIntensity_);
+				//renderPolygons(width_, height_, programID_, lightInvDirs_[i], MatrixID_, ModelMatrixID_, ViewMatrixID_, DepthBiasID_, lightInvDirID_, Texture_, TextureID_, depthTexture_, ShadowMapID_, vertexbuffer_, uvbuffer_, normalbuffer_, elementbuffer_, indices_, MVP_, ModelMatrix_, ViewMatrix_, depthBiasMVP_, RoughnessID_, roughness, MetallicID_, metallic, LightDistanceID_, gain, LightIntensityID_, bias);
 				
 				cv::Mat model = readPixels(height_, width_);
 				cv::Mat photograph = textureImages_[i];
 				
 				model.convertTo(model, CV_64FC3, gain, bias);
+				//model.convertTo(model, CV_64FC3);
 				photograph.convertTo(photograph, CV_64FC3);
 				
 				// Calculate the residual
@@ -140,8 +142,8 @@ void specularMinimisation(double& Roughness, double& Metallic, double& Gain, dou
 	//problem.SetParameterLowerBound(&Bias, 0, 0);
 	//problem.SetParameterBlockConstant(&Roughness);
 	//problem.SetParameterBlockConstant(&Metallic);
-	problem.SetParameterBlockConstant(&Gain);
-	problem.SetParameterBlockConstant(&Bias);
+	//problem.SetParameterBlockConstant(&Gain);
+	//problem.SetParameterBlockConstant(&Bias);
 
 	/*problem.SetParameterLowerBound(&Roughness, 0, 0);
 	problem.SetParameterUpperBound(&Roughness, 0, 1);
@@ -150,8 +152,8 @@ void specularMinimisation(double& Roughness, double& Metallic, double& Gain, dou
 	//problem.SetParameterLowerBound(&Bias, 0, 0);
 	//problem.SetParameterBlockConstant(&Roughness);
 	//problem.SetParameterBlockConstant(&Metallic);
-	problem.SetParameterBlockConstant(&Gain);
-	problem.SetParameterBlockConstant(&Bias);*/
+	//problem.SetParameterBlockConstant(&Gain);
+	//problem.SetParameterBlockConstant(&Bias);*/
 	
 	// Run the solver
 	Solver::Options options;
@@ -212,9 +214,11 @@ void specularMinimisation(double& Roughness, double& Metallic, double& Gain, dou
 		std::string outputImageName = stm2.str();
 
 		renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, RoughnessID, Roughness, MetallicID, Metallic, LightDistanceID, LightDistance, LightIntensityID, LightIntensity);
+		//renderPolygons(width, height, programID, lightInvDirs[i], MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MVP, ModelMatrix, ViewMatrix, depthBiasMVP, RoughnessID, Roughness, MetallicID, Metallic, LightDistanceID, Gain, LightIntensityID, Bias);
 
 		cv::Mat model = readPixels(height, width);
 		model.convertTo(model, CV_8UC3, Gain, Bias);
+		//model.convertTo(model, CV_8UC3);
 
 		cv::imwrite(outputImageName, model);
 
diff --git a/apps/specular_estimation/src/PhotometricStereo.cc b/apps/specular_estimation/src/PhotometricStereo.cc
index 80e475f17f805909a8205597d2050e64059ea13b..e575547876a22a46c1f65b286c2101cbd0788e8a 100755
--- a/apps/specular_estimation/src/PhotometricStereo.cc
+++ b/apps/specular_estimation/src/PhotometricStereo.cc
@@ -726,7 +726,8 @@ cv::Mat photometryStero::outputNormalImage(int objectIndex) {
             double rootsquareSum = sqrt(nx * nx + ny * ny + nz * nz);
             float nxf = (1 + nx / rootsquareSum) / 2;
             float nyf = (1 + ny / rootsquareSum) / 2;
-            float nzf = (1 + nz / rootsquareSum) / 2;
+            //float nzf = (1 + nz / rootsquareSum) / 2;
+            float nzf = sqrt(1.0f - pow(nxf, 2.0f) - pow(nyf, 2.0f));
             result.at<cv::Vec3f>(mObjectY[i], mObjectX[i])[0] = nxf;
             result.at<cv::Vec3f>(mObjectY[i], mObjectX[i])[1] = nyf;
             result.at<cv::Vec3f>(mObjectY[i], mObjectX[i])[2] = nzf;
diff --git a/apps/specular_estimation/src/ShadowMapping.fragmentshader b/apps/specular_estimation/src/ShadowMapping.fragmentshader
index 7b3787b4b93553a13ed06642273b42438d3d9475..c88d388c7997bc2b7281c9e443c8a28edfea2dfa 100644
--- a/apps/specular_estimation/src/ShadowMapping.fragmentshader
+++ b/apps/specular_estimation/src/ShadowMapping.fragmentshader
@@ -153,6 +153,8 @@ void main() {
 	
     color = color / (color + vec3(1.0));
     color = pow(color, vec3(1.0/2.2));
+
+	//color = (color * distance) + (lightPower * 255);
    
     //FragColor = vec4(color, 1.0);
 }
@@ -249,9 +251,11 @@ void main2() {
 		// Ambient: simulates indirect lighting
 		//MaterialAmbientColor +
 		// Diffuse: "colour" of the object
-		attenuation * MaterialDiffuseColor  * LightColor * lightPower * cosTheta +
-		//((visibility * MaterialDiffuseColor * LightColor * lightPower * cosTheta) / 3.1415926535897932384626433832795 ) +
+		attenuation * MaterialDiffuseColor  * LightColor * cosTheta +
+		//((visibility * MaterialDiffuseColor * LightColor * cosTheta) / 3.1415926535897932384626433832795 ) +
 		// Specular: reflective highlight, like a mirror
-		attenuation * MaterialSpecularColor * LightColor * lightPower * pow(cosAlpha, specularPower);
-		//visibility * MaterialSpecularColor * LightColor * lightPower * ((specularPower + 2)/(6.283185307179586476925286766559)) * pow(cosAlpha, specularPower);
+		attenuation * MaterialSpecularColor * LightColor * pow(cosAlpha, specularPower);
+		//visibility * MaterialSpecularColor * LightColor * ((specularPower + 2)/(6.283185307179586476925286766559)) * pow(cosAlpha, specularPower);
+
+	//color = (color * distance) + (lightPower * 255);
 }
\ No newline at end of file
diff --git a/apps/specular_estimation/src/specular_estimation.cc b/apps/specular_estimation/src/specular_estimation.cc
index 23a0d700c91235c582490490a4ba2cb41362f9d0..26908c2a2e708d8c5e135cef4a8c5b3ead6a248d 100644
--- a/apps/specular_estimation/src/specular_estimation.cc
+++ b/apps/specular_estimation/src/specular_estimation.cc
@@ -143,14 +143,14 @@ void specularEstimation(std::string imageName, std::string calibration, double R
 	double totalResidual, residualValue;
 
 	//cv::Mat lightDirectionsInverted;
-	//cv::Mat lightDirections = (cv::Mat_<float>(6,3) << 0.447712, 0.138562, 0.883377, 0.228758, -0.106536, 0.967636, 0.1, 0.0705882, 0.99248, 0.000653595, -0.0718954, 0.997412, -0.139216, -0.12549, 0.982279, -0.494771, 0.115033, 0.861376);
-	cv::Mat lightDirections = (cv::Mat_<float>(6,3) << -0.57735, -0.57735, 0.57735, 
+	cv::Mat lightDirections = (cv::Mat_<float>(6,3) << 0.447712, 0.138562, 0.883377, 0.228758, -0.106536, 0.967636, 0.1, 0.0705882, 0.99248, 0.000653595, -0.0718954, 0.997412, -0.139216, -0.12549, 0.982279, -0.494771, 0.115033, 0.861376);
+	/*cv::Mat lightDirections = (cv::Mat_<float>(6,3) << -0.57735, -0.57735, 0.57735, 
 	0, 0.7071, 0.7071,
 	0, -0.7071, 0.7071,
 	0.7071, 0, 0.7071,
 	-0.7071, 0, 0.7071,
 	0.57735, 0.57735, 0.57735
-	);
+	);*/
 	//cv::invert(lightDirections, lightDirectionsInverted, cv::DECOMP_SVD);
 
 
diff --git a/bin/specular_estimation b/bin/specular_estimation
index 03d5c4c6634524aa503b2cd0ca6d46ec6bc651f7..6753db0c8483b45bcea9a837d8f45fb785ab3745 100755
Binary files a/bin/specular_estimation and b/bin/specular_estimation differ