Commit 4b5817ba authored by Laurent Belcour's avatar Laurent Belcour

BRDFExplorer export of Shlick's Fresnel

parent 385f2ad7
......@@ -168,7 +168,7 @@ bool nonlinear_fitter_nlopt::fit_data(const data* d, function* fit, const argume
{
algorithm = NLOPT_LN_PRAXIS;
}
else if(optimizerName == "Nelder-Mead Simplex")
else if(optimizerName == "Nelder-Mead")
{
algorithm = NLOPT_LN_NELDERMEAD;
}
......
......@@ -40,13 +40,39 @@ void schlick::load(std::istream& in)
void schlick::save_call(std::ostream& out, const arguments& args) const
{
f->save_call(out, args);
out << "("; f->save_call(out, args); out << ")";
bool is_alta = !args.is_defined("export") || args["export"] == "alta";
if(is_alta)
{
out << "#FUNC nonlinear_fresnel_schlick" << std::endl ;
out << "R " << R << std::endl;
out << std::endl;
}
else
{
out << " * schlick_fresnel(L, V, N, X, Y, " << R << ")";
}
}
void schlick::save_body(std::ostream& out, const arguments& args) const
{
f->save_body(out, args);
bool is_shader = args["export"] == "shader" || args["export"] == "explorer";
if(is_shader)
{
out << std::endl;
out << "vec3 schlick_fresnel(vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y, float R)" << std::endl;
out << "{" << std::endl;
out << "\tvec3 H = normalize(L + V);" << std::endl;
out << "\treturn vec3(R + (1.0f - R) * pow(1.0f - clamp(dot(H,L), 0.0f, 1.0f), 5));" << std::endl;
out << "}" << std::endl;
}
out << "#FUNC nonlinear_fresnel_schlick" << std::endl ;
out << "R " << R << std::endl;
out << std::endl;
}
vec schlick::fresnelValue(const vec& x) const
{
double xp[2];
......@@ -101,5 +127,5 @@ vec schlick::getFresnelParametersJacobian(const vec& x) const
void schlick::fresnelBootstrap(const data* d, const arguments& args)
{
R = 1.0;
R = 0.1;
}
......@@ -21,7 +21,7 @@ class schlick : public fresnel
virtual void load(std::istream& in) ;
virtual void save_call(std::ostream& out, const arguments& args) const;
virtual void save_body(std::ostream& out, const arguments& args) const
protected: // methods
......
......@@ -33,7 +33,11 @@ vec isotropic_lafortune_function::value(const vec& x) const
// For each color channel
for(int i=0; i<dimY(); ++i)
{
#ifdef WITH_DIFFUSE
res[i] = _kd[i];
#else
res[i] = 0.0;
#endif
// For each lobe
for(int n=0; n<_n; ++n)
......@@ -52,6 +56,7 @@ vec isotropic_lafortune_function::value(const vec& x) const
if(isnan(res[i]) || res[i] == std::numeric_limits<double>::infinity())
{
std::cout << "<<ERROR>> invalid value for input: " << x << std::endl;
std::cout << " invalid value for parameter: " << parameters() << std::endl;
}
#endif
}
......@@ -76,7 +81,11 @@ vec isotropic_lafortune_function::value(const vec& x, const vec& p) const
for(int i=0; i<dimY(); ++i)
{
// Start with the diffuse term
res[i] = _kd[i];
#ifdef WITH_DIFFUSE
res[i] = _kd[i];
#else
res[i] = 0.0;
#endif
// For each lobe
for(int n=0; n<_n; ++n)
......@@ -116,10 +125,12 @@ void isotropic_lafortune_function::setDimY(int nY)
// Update the length of the vectors
_C.resize(_n*_nY*2) ;
_N.resize(_n*_nY) ;
#ifdef USE_DIFFUSE
_kd.resize(_nY);
for(int i=0; i<nY; ++i)
_kd[i] = 0.0;
#endif
}
//! Number of parameters to this non-linear function
......@@ -227,6 +238,7 @@ void isotropic_lafortune_function::bootstrap(const data* d, const arguments& arg
// Check the arguments for the number of lobes
this->setNbLobes(args.get_int("lobes", 1));
#ifdef USE_DIFFUSE
// Set the diffuse component
vec x0 = d->get(0);
for(int i=0; i<d->dimY(); ++i)
......@@ -239,7 +251,7 @@ void isotropic_lafortune_function::bootstrap(const data* d, const arguments& arg
_kd[j] = std::min(xi[d->dimX() + j], _kd[j]);
}
std::cout << "<<INFO>> found diffuse: " << _kd << std::endl;
#endif
// Upon user request, the starting position of the lobe can be either load
// from a file, a distribution beetwen forward backward and dot directions,
// etc.
......@@ -425,9 +437,14 @@ void isotropic_lafortune_function::save_call(std::ostream& out, const arguments&
void isotropic_lafortune_function::save_body(std::ostream& out, const arguments& args) const
{
out << "vec3 lafortune(vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y, vec3 Cx, vec3 Cz, vec3 Nl)" << std::endl;
out << "{" << std::endl;
out << "\tvec3 ext_dot = Cx * (dot(L,X)*dot(V,X) + dot(L,Y)*dot(V,Y)) + Cz * dot(L,N)*dot(V,N);" << std::endl;
out << "\treturn pow(max(ext_dot, vec3(0,0,0)), Nl);" << std::endl;
out << "}" << std::endl;
bool is_shader = args["export"] == "shader" || args["export"] == "explorer";
if(is_shader)
{
out << "vec3 lafortune(vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y, vec3 Cx, vec3 Cz, vec3 Nl)" << std::endl;
out << "{" << std::endl;
out << "\tvec3 ext_dot = Cx * (dot(L,X)*dot(V,X) + dot(L,Y)*dot(V,Y)) + Cz * dot(L,N)*dot(V,N);" << std::endl;
out << "\treturn pow(max(ext_dot, vec3(0,0,0)), Nl);" << std::endl;
out << "}" << std::endl;
}
}
......@@ -100,6 +100,8 @@ class isotropic_lafortune_function : public nonlinear_function
//! \brief The isotropic_lafortune lobe data
int _n; // Number of lobes
vec _N, _C; // Lobes data
#ifdef WITH_DIFFUSE
vec _kd; // Diffuse term
#endif
} ;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment