1#ifndef _BBM_LOW_SMOOTH_H_
2#define _BBM_LOW_SMOOTH_H_
17 template<
typename CONF, string_literal NAME=
"LowSmooth">
requires concepts::config<CONF>
44 if(bbm::none(mask))
return Spectrum(0);
51 Value Dp2 = bbm::squared_norm(Ip + Op);
52 Value cosThetaD = bbm::safe_sqrt(1 - 0.25*bbm::squared_norm(Ip-Op));
55 Value S = bbm::pow(1.0 +
B*Dp2, -
C);
80 mask &= (xi[0] >= 0) && (xi[1] >= 0) && (xi[0] <= 1) && (xi[1] <= 1);
83 if(bbm::none(mask))
return sample;
89 Value temp = 1.0 + (2*
B*(1.0 + ro2)) + bbm::pow(
B*(1-ro2), 2);
90 temp = -bbm::log(2.0) + bbm::log(1 +
B*(1-ro2) + bbm::safe_sqrt(temp));
91 Value MdPi =
B * bbm::rcp(temp);
94 Value E = 2.0 * bbm::exp( xi[0] *
B * bbm::rcp(MdPi) );
97 Value ri = bbm::safe_sqrt( (E-2)*(E + 2*
B*ro2) / (2*E*
B) );
100 Value ro = bbm::sqrt(ro2);
101 Value scale = bbm::sqrt( (1.0 +
B*bbm::pow(ri + ro, 2.0)) / (1.0 +
B*bbm::pow(ri - ro, 2.0)) );
102 Value phi_i = 2.0 * bbm::atan( bbm::tan(xi[1] * Constants::Pi()) * scale ) +
spherical::phi(out);
132 if(bbm::none(mask))
return 0;
138 Value temp = 1.0 + (2*
B*(1.0 + ro2)) + bbm::pow(
B*(1.0-ro2), 2);
139 temp = -bbm::log(Value(2)) + bbm::log(1 +
B*(1-ro2) + bbm::safe_sqrt(temp));
140 Value Md =
B * Constants::InvPi() * bbm::rcp(temp);
164 mask &= (
vec::z(out) > 0);
167 if(bbm::none(mask))
return 0;
172 Value factor =
bbm::select( bbm::abs(
C-1) < Constants::Epsilon(), bbm::log(
B + 1) / (2*
B), (1.0 - bbm::pow(
B+1, 1-
C)) / (2*
B*(
C-1)));
175 Value R0 = bbm::pow((
eta - 1) / (
eta + 1), 2);
178 return bbm::select(mask, Constants::Pi(2)*
A*factor*R0, 0);
All includes and helpers needed for declaring new bsdfmodels.
#define BBM_EXPORT_BSDFMODEL(BsdfModel)
Definition: bbm_fromstring.h:49
Definition: lowsmooth.h:19
bsdf_parameter< Value, bsdf_attr::SpecularParameter > B
Definition: lowsmooth.h:185
Spectrum eval(const Vec3d &in, const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t=unit_t::Radiance, Mask mask=true) const
Evaluate the BSDF for a given in and out direction.
Definition: lowsmooth.h:35
BsdfSample sample(const Vec3d &out, const Vec2d &xi, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const
Sample the BSDF given a direction and two random variables.
Definition: lowsmooth.h:72
bsdf_parameter< Spectrum, bsdf_attr::SpecularParameter > A
Definition: lowsmooth.h:184
fresnel_parameter< ior::ior< Value > > eta
Definition: lowsmooth.h:187
BBM_BSDF_FORWARD
Definition: lowsmooth.h:23
BBM_DEFAULT_CONSTRUCTOR(lowsmooth)
Default constructor.
Definition: lowsmooth.h:193
bsdf_parameter< Value, bsdf_attr::SpecularParameter > C
Definition: lowsmooth.h:186
Spectrum reflectance(const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t=unit_t::Radiance, Mask mask=true) const
Return the (approximate) hemispherical reflectance of the BSDF.
Definition: lowsmooth.h:158
Value pdf(const Vec3d &in, const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t=unit_t::Radiance, Mask mask=true) const
Compute the pdf given an in and out direction.
Definition: lowsmooth.h:123
static constexpr string_literal name
Definition: lowsmooth.h:22
BBM_ATTRIBUTES(A, B, C, eta)
bsdfmodel concept
Definition: bsdfmodel.h:33
#define BBM_CHECK_CONCEPT(CONCEPTNAME, CLASSNAME,...)
Check a class for a concept with bbm::concepts::archetypes in the namespace.
Definition: macro.h:35
T & phi(vec2d< T > &v)
Definition: spherical.h:39
T sinTheta2(const vec2d< T > &v)
Definition: spherical.h:77
T cosTheta(const vec2d< T > &v)
Definition: spherical.h:109
constexpr const vec3d< T > expand(const vec2d< T > &v, V &&a)
Definition: vec.h:55
constexpr decltype(auto) z(bbm::vec3d< T > &v)
Definition: vec.h:26
constexpr const vec2d< T > xy(const vec3d< T > &v)
Definition: vec.h:47
Definition: aggregatebsdf.h:29
constexpr auto select(MASK &&mask, const A &a, const A &b)
Definition: backbone.h:255
constexpr auto is_set(const FLAGNAME &a, const FLAG &flag)
Check if all in 'flag' are also set in 'a'; compatible with packet types.
Definition: flags.h:100
unit_t
Light Unit.
Definition: unit.h:21
Base declaration of attribute; further specialized below.
Definition: attribute.h:26
static constexpr std::decay_t< parameter_type >::type eval(const parameter_type ¶m, const Value &cosTheta, Mask mask=true)
Evaluate Fresnel reflectance.
Definition: fresnel_cook.h:41
Definition: string_literal.h:16