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 2428848c59b758eb062b70652ea7aedcc06192a1..fa6f9e0b31cd577b79c890f400d4113f80cc14b8 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 32f8a27e66572ad49fa1d013f24214c39fe4c6bb..74ce3afda99b2ce5e7625c0cad7c5a00dac81ff5 100644 --- a/apps/specular_estimation/src/Ceres.h +++ b/apps/specular_estimation/src/Ceres.h @@ -47,7 +47,7 @@ class MyScalarCostFunctor { } //std::cout << "Specular Intensity = " << specularIntensity << ", Specular Power = " << specularPower << ", Residual = " << (sum/numberOfLights_) << ", SSD = " << (sum/numberOfLights_)*(sum/numberOfLights_) << std::endl; - std::cout << specularIntensity << "\t" << specularPower << "\t" << gain << "\t" << bias << "\t" << (sum/numberOfLights_) << std::endl; + //std::cout << specularIntensity << "\t" << specularPower << "\t" << gain << "\t" << bias << "\t" << (sum/numberOfLights_) << std::endl; //outputToFile(specularIntensity, specularPower, (sum/numberOfLights_)); @@ -113,11 +113,11 @@ void specularMinimisation(double& SpecularIntensity, double& SpecularPower, doub problem.SetParameterLowerBound(&SpecularIntensity, 0, 0); problem.SetParameterUpperBound(&SpecularIntensity, 0, 1); - problem.SetParameterLowerBound(&SpecularPower, 0, 1); + problem.SetParameterLowerBound(&SpecularPower, 0, 0.01); problem.SetParameterLowerBound(&Gain, 0, 0); problem.SetParameterUpperBound(&Gain, 0, 2); - problem.SetParameterLowerBound(&Bias, 0, -255); - problem.SetParameterUpperBound(&Bias, 0, 255); + problem.SetParameterLowerBound(&Bias, 0, -1); + problem.SetParameterUpperBound(&Bias, 0, 1); // Run the solver! Solver::Options options; diff --git a/apps/specular_estimation/src/OpenCV.h b/apps/specular_estimation/src/OpenCV.h index f7d645c66911b2d3e71953cf436b11a8ca7c0e8b..0f65b8d6d9241f1d97535b277ca0d4e7982bc829 100644 --- a/apps/specular_estimation/src/OpenCV.h +++ b/apps/specular_estimation/src/OpenCV.h @@ -53,7 +53,7 @@ cv::Mat contrastBrightness(cv::Mat image, double gain = 1.0, double bias = 0.0) for ( int y = 0; y < image.rows; y++ ) { for ( int x = 0; x < image.cols; x++ ) { for ( int c = 0; c < image.channels(); c++ ) { - new_image.at<cv::Vec3b>(y,x)[c] = cv::saturate_cast<uchar>( gain*image.at<cv::Vec3b>(y,x)[c] + bias ); + new_image.at<cv::Vec3b>(y,x)[c] = cv::saturate_cast<uchar>( gain*image.at<cv::Vec3b>(y,x)[c] + bias*255 ); } } } diff --git a/apps/specular_estimation/src/ShadowMapping.fragmentshader b/apps/specular_estimation/src/ShadowMapping.fragmentshader index 17a335c3258e6fa7bf8ce7fcb8e84b460a696494..006a36ae9393b66fd18ca5a05c1534dbae033785 100644 --- a/apps/specular_estimation/src/ShadowMapping.fragmentshader +++ b/apps/specular_estimation/src/ShadowMapping.fragmentshader @@ -46,6 +46,13 @@ float random(vec3 seed, int i) { return fract(sin(dot_product) * 43758.5453); } +float clampSpecular(float diffuse, float specular) { + if ((diffuse + specular) > 1) { + specular = 1 - diffuse; + } + return specular; +} + void main() { // Light emission properties @@ -58,8 +65,11 @@ void main() { float ambientPower = 0.0f; vec3 MaterialDiffuseColor = texture( myTextureSampler, UV ).rgb; vec3 MaterialAmbientColor = vec3(ambientPower, ambientPower, ambientPower) * MaterialDiffuseColor; - - vec3 MaterialSpecularColor = vec3(specularIntensity, specularIntensity, specularIntensity); + + //vec3 MaterialSpecularColor = vec3(clampSpecular(length(MaterialDiffuseColor), specularIntensity), clampSpecular(length(MaterialDiffuseColor), specularIntensity), clampSpecular(length(MaterialDiffuseColor), specularIntensity)); + vec3 MaterialSpecularColor = vec3(clampSpecular(texture(myTextureSampler, UV).r, specularIntensity), clampSpecular(texture(myTextureSampler, UV).g, specularIntensity), clampSpecular(texture(myTextureSampler, UV).b, specularIntensity)); + + //vec3 MaterialSpecularColor = vec3(specularIntensity, specularIntensity, specularIntensity); //vec3 MaterialSpecularColor = texture( myTextureSampler, UV ).rgb; // Distance to the light @@ -124,11 +134,19 @@ void main() { // if ( texture( shadowMap, (ShadowCoord.xy/ShadowCoord.w) ).z < (ShadowCoord.z-bias)/ShadowCoord.w ) // if ( textureProj( shadowMap, ShadowCoord.xyw ).z < (ShadowCoord.z-bias)/ShadowCoord.w ) + //color = + // Ambient: simulates indirect lighting + //MaterialAmbientColor + + // Diffuse: "colour" of the object + //visibility * MaterialDiffuseColor * LightColor * LightPower * cosTheta + + // Specular: reflective highlight, like a mirror + //visibility * MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha, specularPower); + color = // Ambient: simulates indirect lighting - MaterialAmbientColor + + //MaterialAmbientColor + // Diffuse: "colour" of the object - visibility * MaterialDiffuseColor * LightColor * LightPower * cosTheta + + ((visibility * MaterialDiffuseColor * LightColor * LightPower * cosTheta) / 3.1415926535897932384626433832795 ) + // Specular: reflective highlight, like a mirror - visibility * MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha, specularPower); + visibility * MaterialSpecularColor * LightColor * LightPower * ((specularPower + 2)/(6.283185307179586476925286766559)) * pow(cosAlpha, specularPower); } diff --git a/bin/specular_estimation b/bin/specular_estimation index 9dc1995e964149367f6fcc9341e2a26af1b92226..a9cb25ef4cac05d8498c40700f31d56ea2d97020 100755 Binary files a/bin/specular_estimation and b/bin/specular_estimation differ