Commit 3d3bb949 authored by Laurent Belcour's avatar Laurent Belcour

BrdfExplorer and shader export for Lafortune

parent 23db4725
......@@ -4,6 +4,11 @@
void function::save(const std::string& filename, const arguments& args) const
{
bool is_cpp = args["export"] == "C++";
bool is_explorer = args["export"] == "explorer";
bool is_shader = args["export"] == "shader" || is_explorer;
bool is_matlab = args["export"] == "matlab";
// Open the file
std::ofstream file(filename);
if(!file.is_open())
......@@ -11,14 +16,62 @@ void function::save(const std::string& filename, const arguments& args) const
std::cerr << "<<ERROR>> unable to open output file for writing" << std::endl;
}
if(is_explorer)
{
file << "analytic" << std::endl;
file << std::endl;
file << "::begin shader" << std::endl;
}
// Save common header
save_header(file, args);
file << std::endl;
// Save function definition
save_body(file, args);
file << std::endl;
if(is_cpp)
{
file << "vec brdf(const vec& in, const vec& file)" << std::endl;
file << "{" << std::endl;
file << "\tvec res(" << dimY() << ");" << std::endl;
file << "\t";
}
else if(is_matlab)
{
file << "function res = brdf(in, file)" << std::endl;
file << "{" << std::endl;
file << "\tres = zeros(" << dimY() << ");" << std::endl;
file << "\t";
}
else if(is_shader)
{
file << "vec3 BRDF(vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y)" << std::endl;
file << "{" << std::endl;
file << "\tvec3 res = ";
}
// Save fit data
save_call(file, args);
save_call(file, args);
if(is_cpp || is_shader)
{
file << ";" << std::endl;
file << "\treturn res;" << std::endl;
file << "}" << std::endl;
}
else if(is_matlab)
{
file << ";" << std::endl;
file << "\treturn res;" << std::endl;
file << "endfunction" << std::endl;
}
file << std::endl;
if(is_explorer)
{
file << "::end shader" << std::endl;
}
}
//! \brief save the header of the output function file. The header should
......@@ -43,26 +96,8 @@ void function::save_header(std::ostream& out, const arguments& args) const
//! defining function calls that are common to all the plugins.
void function::save_body(std::ostream& out, const arguments& args) const
{
bool is_cpp = args["export"] == "C++";
bool is_shader = args["export"] == "shader";
bool is_matlab = args["export"] == "matlab";
if(is_cpp)
{
out << "vec brdf(const vec& in, const vec& out)" << std::endl;
out << "{" << std::endl;
out << "\tvec res(" << dimY() << ");" << std::endl;
}
else if(is_matlab)
{
out << "function res = brdf(in, out)" << std::endl;
out << "\tres = zeros(" << dimY() << ");" << std::endl;
}
else if(is_shader)
{
out << "vec3 brdf(vec3 in, vec3 out)" << std::endl;
out << "\tvec3 res = vec3(0.0f);" << std::endl;
}
}
//! \brief save object specific information. For an ALTA export the
......@@ -70,19 +105,7 @@ void function::save_body(std::ostream& out, const arguments& args) const
//! to the associated function will be done.
void function::save_call(std::ostream& out, const arguments& args) const
{
bool is_cpp = args["export"] == "C++";
bool is_shader = args["export"] == "shader";
bool is_matlab = args["export"] == "matlab";
if(is_cpp || is_shader)
{
out << "\treturn res;" << std::endl;
out << "}" << std::endl;
}
else if(is_matlab)
{
out << "endfunction" << std::endl;
}
}
//! \brief L2 norm to data.
......
......@@ -200,6 +200,8 @@ class nonlinear_function: public function
}
out << std::endl;
}
function::save_call(out, args);
}
};
......
......@@ -3,7 +3,7 @@
struct param_info
{
param_info(std::string n, int d, std::string i) :
name(n), dimension(d), info(i) { };
name(n), dimension(d), info(i) { }
std::string name;
int dimension;
......
......@@ -47,7 +47,7 @@ class params
CARTESIAN, /*!< Light and View vectors represented in cartesian coordinates */
UNKNOWN_INPUT
UNKNOWN_INPUT /*!< Default behaviour. Only use this is you do not fit BRDF data */
};
//! \brief list of all supported parametrization for the output space.
......
......@@ -354,19 +354,65 @@ void isotropic_lafortune_function::load(std::istream& in)
void isotropic_lafortune_function::save_call(std::ostream& out, const arguments& args) const
{
out << "#FUNC nonlinear_function_lafortune" << std::endl ;
out << "#NB_LOBES " << _n << std::endl ;
bool is_alta = !args.is_defined("export") || args["export"] == "alta";
for(int n=0; n<_n; ++n)
{
for(int i=0; i<_nY; ++i)
{
out << "Cxy " << _C[(n*_nY + i)*2 + 0] << std::endl;
out << "Cz " << _C[(n*_nY + i)*2 + 1] << std::endl;
out << "N " << _N[n*_nY + i] << std::endl;
}
}
out << std::endl;
if(is_alta)
{
out << "#FUNC nonlinear_function_lafortune" << std::endl ;
out << "#NB_LOBES " << _n << std::endl ;
for(int n=0; n<_n; ++n)
{
for(int i=0; i<_nY; ++i)
{
out << "Cxy " << _C[(n*_nY + i)*2 + 0] << std::endl;
out << "Cz " << _C[(n*_nY + i)*2 + 1] << std::endl;
out << "N " << _N[n*_nY + i] << std::endl;
}
out << std::endl;
}
}
else
{
for(int n=0; n<_n; ++n)
{
out << "lafortune(L, V, N, X, Y, vec3(";
for(int i=0; i<_nY; ++i)
{
out << _C[(n*_nY + i)*2 + 0];
if(i < _nY-1) { out << ", "; }
}
out << "), vec3(";
for(int i=0; i<_nY; ++i)
{
out << _C[(n*_nY + i)*2 + 1];
if(i < _nY-1) { out << ", "; }
}
out << "), vec3(";
for(int i=0; i<_nY; ++i)
{
out << _N[n*_nY + i];
if(i < _nY-1) { out << ", "; }
}
// For multiple lobes, add a sum sign
out << "))";
if(n < _n-1) { out << " + "; }
}
}
}
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;
}
......@@ -48,6 +48,7 @@ class isotropic_lafortune_function : public nonlinear_function
//! \brief Export function
virtual void save_call(std::ostream& out, const arguments& args) const;
virtual void save_body(std::ostream& out, const arguments& args) const;
//! \brief Boostrap the function by defining the diffuse term
//!
......
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