56 if(bbm::none(mask))
return 0;
60 Value alpha2 = bbm::hprod(alpha);
61 Value D = bbm::rcp( Constants::Pi() * alpha2 * bbm::pow( bbm::squared_norm(
vec::xy(
halfway) / alpha) + bbm::pow(
vec::z(
halfway), 2), 2.0 ) );
75 Vec3d
sample(
const Vec3d& view,
const Vec2d& xi, Mask mask=
true)
const
78 mask &= (xi[0] >= 0) && (xi[1] >= 0) && (xi[0] <= 1) && (xi[1] <= 1);
81 if(bbm::none(mask))
return 0;
84 if constexpr (SampleVisible)
96 Value a = bbm::rcp(1.0 +
vec::z(view_s));
97 Value r = bbm::sqrt(xi[0]);
98 Value phi =
bbm::select(xi[1] < a, xi[1]/a, 1.0 + (xi[1]-a) / (1.0-a)) * Constants::Pi();
99 Vec2d csp = bbm::cossin(phi);
104 Vec3d normal = P1*T1 + P2*T2 + bbm::safe_sqrt(1.0 - P1*P1 - P2*P2)*view_s;
113 Vec2d csp = bbm::cossin( Constants::Pi(2) * xi[0] );
119 normalization = bbm::squared_norm(csp);
120 csp *= bbm::rsqrt(normalization);
125 Value tanTheta2 = normalization * (xi[1] / (1-xi[1]));
126 Value cosTheta = bbm::rsqrt(1.0 + tanTheta2);
127 Value sinTheta = bbm::safe_sqrt(1.0 - cosTheta*cosTheta);
142 Value
pdf(
const Vec3d& view,
const Vec3d& m, Mask mask=
true)
const
148 if(bbm::none(mask))
return 0;
153 if constexpr (SampleVisible)
173 Value
G1(
const Vec3d& v,
const Vec3d& m, Mask mask=
true)
const
176 mask &= (
vec::z(v) > 0) && (bbm::dot(v, m) > 0);
179 if(bbm::none(mask))
return 0;
183 Value roughness2 = bbm::hprod(r);
185 Value denom = 1.0 + bbm::sqrt(1.0 + roughness2*tanTheta2);
All includes and helpers needed for declaring new ndfs.
The GGX Microfacet distribution.
Definition: ggx.h:38
Value G1(const Vec3d &v, const Vec3d &m, Mask mask=true) const
Monodirectional shadowing and masking term.
Definition: ggx.h:173
Value pdf(const Vec3d &view, const Vec3d &m, Mask mask=true) const
PDF of sampling the NDF.
Definition: ggx.h:142
Value eval(const Vec3d &halfway, Mask mask=true) const
Evaluate the NDF.
Definition: ggx.h:50
Vec3d sample(const Vec3d &view, const Vec2d &xi, Mask mask=true) const
Sample the NDF.
Definition: ggx.h:75
BBM_ATTRIBUTES(roughness)
specular_roughness< symmetry_t< Symmetry, Value > > roughness
Definition: ggx.h:194
BBM_DEFAULT_CONSTRUCTOR(ggx)
Default constructor.
Definition: ggx.h:200
static constexpr string_literal name
Definition: ggx.h:41
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
T tanTheta2(const vec2d< T > &v)
Definition: spherical.h:183
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
symmetry_v
symmetry variants.
Definition: bsdf_symmetry.h:19
constexpr auto select(MASK &&mask, const A &a, const A &b)
Definition: backbone.h:255
vec3d< T > halfway(const vec3d< T > &a, const vec3d< T > &b)
Halfway vector (3D)
Definition: vec_transform.h:77
constexpr vec3d< T > cross(const vec3d< T > &a, const vec3d< T > &b)
Cross product of two 3D vectors.
Definition: vec_transform.h:62
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
Definition: string_literal.h:16