Commit c0f15e40 authored by Laurent Belcour's avatar Laurent Belcour
Browse files

Updating the Schlick Fresnel to have parameters boundaries

parent 2bb701f5
......@@ -11,7 +11,7 @@
ALTA_DLL_EXPORT function* provide_function()
{
return new schlick();
return new schlick();
}
//! Load function specific files
......@@ -19,56 +19,64 @@ void schlick::load(std::istream& in)
{
fresnel::load(in);
// Parse line until the next comment
while(in.peek() != '#')
{
char line[256];
in.getline(line, 256);
}
// Parse line until the next comment
while(in.peek() != '#')
{
char line[256];
in.getline(line, 256);
}
// Checking for the comment line #FUNC nonlinear_fresnel_schlick
std::string token;
in >> token;
if(token != "#FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
// Checking for the comment line #FUNC nonlinear_fresnel_schlick
std::string token;
in >> token;
if(token != "#FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
in >> token;
if(token != "nonlinear_fresnel_schlick") { std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl; }
in >> token;
if(token != "nonlinear_fresnel_schlick") { std::cerr << "<<ERROR>> parsing the stream. function name is not the next token." << std::endl; }
// R [double]
in >> token >> R;
// R [double]
in >> token >> R;
}
void schlick::save_call(std::ostream& out, const arguments& args) const
{
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 << ")";
}
bool is_alta = !args.is_defined("export") || args["export"] == "alta";
if(is_alta)
{
out << "("; f->save_call(out, args); out << ")";
}
else
{
f->save_call(out, args);
}
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;
}
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;
}
}
......@@ -127,5 +135,5 @@ vec schlick::getFresnelParametersJacobian(const vec& x) const
void schlick::fresnelBootstrap(const data* d, const arguments& args)
{
R = 0.5;
R = 0.5;
}
......@@ -36,10 +36,26 @@ class schlick : public fresnel
//! \brief Update the vector of parameters for the function
virtual void setFresnelParameters(const vec& p) ;
//! Get the vector of min parameters for the function
virtual vec getFresnelParametersMin() const
{
vec m(1);
m[0] = 0.0;
return m;
}
//! Get the vector of min parameters for the function
virtual vec getFresnelParametersMax() const
{
vec M(1);
M[0] = 1.0;
return M;
}
//! \brief Obtain the derivatives of the function with respect to the
//! parameters.
virtual vec getFresnelParametersJacobian(const vec& x) const ;
//! \brief Boostrap the function by defining the diffuse term
virtual void fresnelBootstrap(const data* d, const arguments& args);
......
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