Commit c0f15e40 authored by Laurent Belcour's avatar Laurent Belcour

Updating the Schlick Fresnel to have parameters boundaries

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