Maj terminée. Pour consulter la release notes associée voici le lien :
https://about.gitlab.com/releases/2021/07/07/critical-security-release-gitlab-14-0-4-released/

function.cpp 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "function.h"

#include <string>
#include <iostream>
#include <fstream>
#include <limits>
#include <algorithm>
#include <cmath>

#include <core/common.h>

ALTA_DLL_EXPORT function* provide_function()
{
    return new schlick();
}

17
//! Load function specific files
Laurent Belcour's avatar
Laurent Belcour committed
18
void schlick::load(std::istream& in)
19
{
20 21
	fresnel::load(in);

Laurent Belcour's avatar
Laurent Belcour committed
22 23 24 25 26 27 28 29 30 31
    // 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;
32
    if(token != "#FUNC") { std::cerr << "<<ERROR>> parsing the stream. The #FUNC is not the next line defined." << std::endl; }
Laurent Belcour's avatar
Laurent Belcour committed
33 34 35 36 37 38

    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;
39
}
40 41 42
		
void schlick::save_call(std::ostream& out, const arguments& args) const
{
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    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;
    }
72 73

}
74

75

76
vec schlick::fresnelValue(const vec& x) const
77
{
Laurent Belcour's avatar
Laurent Belcour committed
78 79 80
	double xp[2];
	params::convert(&x[0], input_parametrization(), params::COS_TH_TD, xp);

81 82 83
	vec res(_nY);
	for(int i=0; i<_nY; ++i)
	{
Laurent Belcour's avatar
Laurent Belcour committed
84
		res[i] = R + (1.0 - R) * pow(1.0 - clamp(xp[1], 0.0, 1.0), 5.0);
85 86 87 88 89
	}

	return res;
}

90 91
//! \brief Number of parameters to this non-linear function
int schlick::nbFresnelParameters() const 
92
{
Laurent Belcour's avatar
Laurent Belcour committed
93
	return 1;
94 95
}

96 97
//! \brief Get the vector of parameters for the function
vec schlick::getFresnelParameters() const 
98
{
99 100 101
	vec p(1);
	p[0] = R;
	return p;
102 103
}

104 105
//! \brief Update the vector of parameters for the function
void schlick::setFresnelParameters(const vec& p) 
106
{
107
	R = p[0];
108 109
}

110
//! \brief Obtain the derivatives of the function with respect to the
111
//! parameters. 
112
vec schlick::getFresnelParametersJacobian(const vec& x) const 
113
{
114
	const int nY = dimY();
Laurent Belcour's avatar
Laurent Belcour committed
115 116
	double xp[2];
	params::convert(&x[0], input_parametrization(), params::COS_TH_TD, xp);
117 118 119 120

	vec jac(nY);
	for(int i=0; i<nY; ++i)
	{
Laurent Belcour's avatar
Laurent Belcour committed
121
		jac[i] = 1.0 - pow(1.0 - clamp(xp[1], 0.0, 1.0), 5.0);
122 123 124
	}

	return jac;
125 126 127
}


Laurent Belcour's avatar
Laurent Belcour committed
128
void schlick::fresnelBootstrap(const data* d, const arguments& args)
129
{
130
    R = 0.5;
131
}