1#ifndef _BBM_BECKMANN_NDF_H_
2#define _BBM_BECKMANN_NDF_H_
55 if(bbm::none(mask))
return 0;
60 Value D = bbm::exp( -bbm::squared_norm(
vec::xy(
halfway) / alpha) / cosTheta2 ) / (
vec::u(alpha) *
vec::v(alpha) * cosTheta2 * cosTheta2);
62 if constexpr (Normalize) D *= Constants::InvPi();
76 Vec3d
sample(
const Vec3d& view,
const Vec2d& xi, Mask mask=
true)
const
79 mask &= (xi[0] >= 0) && (xi[1] >= 0) && (xi[0] <= 1) && (xi[1] <= 1);
82 if(bbm::none(mask))
return 0.0;
85 if constexpr (SampleVisible)
95 Value maxval = bbm::erf(bbm::rcp(tanTheta));
96 Vec2d xic = bbm::clamp(xi, 10e-6, 1.0-10e-6);
97 Value x = maxval - (maxval + 1) * bbm::erf(bbm::sqrt(-bbm::log(xic[0])));
99 xic[0] *= 1.0 + maxval + Constants::InvSqrtPi() * tanTheta * bbm::exp(-
spherical::cosTheta2(view_s));
101 for(
size_t i=0; i < 3; ++i)
103 Value slope = bbm::erfinv(x);
104 Value val = 1.0 + x + Constants::InvSqrtPi() * tanTheta * bbm::exp(-slope*slope) - xic[0];
105 Value derivative = 1.0 - slope * tanTheta;
106 x -= val / derivative;
109 Vec2d slope =
bbm::select(x > -1.0 && x < +1.0, bbm::erfinv(Vec2d(x, 2.0*xic[1] - 1.0)), 0);
121 Vec2d csp = bbm::cossin( Constants::Pi(2) * xi[0] );
127 normalization = bbm::squared_norm(csp);
128 csp *= bbm::rsqrt(normalization);
133 Value cosTheta = bbm::rsqrt(1.0 - normalization*bbm::log(xi[1]));
134 Value sinTheta = bbm::safe_sqrt(1.0 - cosTheta*cosTheta);
149 Value
pdf(
const Vec3d& view,
const Vec3d& m, Mask mask=
true)
const
155 if(bbm::none(mask))
return 0;
160 if constexpr (SampleVisible)
180 Value
G1(
const Vec3d& v,
const Vec3d& m, Mask mask=
true)
const
183 mask &= (
vec::z(v) > 0) && (bbm::dot(v, m) > 0);
186 if(bbm::none(mask))
return 0;
197 Value g =
bbm::select (a < 1.6, (3.535*a + 2.181*a*a) / (1 + 2.276*a + 2.577*a*a), 1.0);
All includes and helpers needed for declaring new ndfs.
config concept
Definition: config.h:31
ndf concept
Definition: ndf.h:29
#define BBM_CHECK_CONCEPT(CONCEPTNAME, CLASSNAME,...)
Check a class for a concept with bbm::concepts::archetypes in the namespace.
Definition: macro.h:35
vec2d< T > cossinPhi(const vec2d< T > &v)
Definition: spherical.h:153
T cosTheta(const vec2d< T > &v)
Definition: spherical.h:109
T tanTheta(const vec2d< T > &v)
Definition: spherical.h:177
bbm::value_t< V > cosTheta2(const V &v)
Definition: spherical.h:115
constexpr decltype(auto) u(bbm::vec2d< T > &v)
Definition: vec.h:37
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 decltype(auto) v(bbm::vec2d< T > &v)
Definition: vec.h:40
constexpr const vec2d< T > xy(const vec3d< T > &v)
Definition: vec.h:47
Definition: aggregatebsdf.h:29
symmetry_v
symmetry variants.
Definition: bsdf_symmetry.h:19
constexpr auto select(MASK &&mask, const A &a, const A &b)
Definition: backbone.h:255
mat2d< std::decay_t< T > > rotation2d(const vec2d< T > &cossin)
2D rotation matrix
Definition: transform.h:101
vec3d< T > halfway(const vec3d< T > &a, const vec3d< T > &b)
Halfway vector (3D)
Definition: vec_transform.h:77
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
Base declaration of attribute; further specialized below.
Definition: attribute.h:26
The Beckman Microfacet distribution.
Definition: beckmann.h:38
Value G1(const Vec3d &v, const Vec3d &m, Mask mask=true) const
Monodirectional shadowing and masking term.
Definition: beckmann.h:180
Value pdf(const Vec3d &view, const Vec3d &m, Mask mask=true) const
PDF of sampling the NDF.
Definition: beckmann.h:149
Value eval(const Vec3d &halfway, Mask mask=true) const
Evaluate the NDF.
Definition: beckmann.h:49
BBM_DEFAULT_CONSTRUCTOR(beckmann)
Default constructor.
Definition: beckmann.h:212
Vec3d sample(const Vec3d &view, const Vec2d &xi, Mask mask=true) const
Sample the NDF.
Definition: beckmann.h:76
BBM_ATTRIBUTES(roughness)
specular_roughness< symmetry_t< Symmetry, Value > > roughness
Definition: beckmann.h:206
static constexpr string_literal name
Definition: beckmann.h:40
Definition: string_literal.h:16