1#ifndef _BBM_NDF_IMPORTANCE_SAMPLER_H_
2#define _BBM_NDF_IMPORTANCE_SAMPLER_H_
23 template<
typename BSDFMODEL,
size_t samplesTheta=90,
size_t samplesPhi=1,
string_literal NAME=BSDFMODEL::name>
requires concepts::bsdfmodel<BSDFMODEL>
44 Vec3d
sample(
const Vec3d& view,
const Vec2d& xi, Mask mask=
true)
const;
45 Value
pdf(
const Vec3d& view,
const Vec3d& m, Mask mask=
true)
const;
46 Value
G1(
const Vec3d& v,
const Vec3d& m, Mask mask=
true)
const;
62 template<
typename... Ts>
requires std::constructible_from<BSDFMODEL, Ts...>
66 using BSDFMODEL::eval;
67 using BSDFMODEL::reflectance;
84 mask &= (xi[0] >= 0) && (xi[1] >= 0) && (xi[0] <= 1) && (xi[1] <= 1);
90 if(bbm::none(mask))
return sample;
95 for(
auto u : bbm::reflection::enum_v<unit_t>)
96 for(
auto c : bbm::reflection::enum_v<bsdf_flag>)
98 auto sample_mask = mask && bbm::eq(component, c) && bbm::eq(unit, u);
99 if(bbm::any(sample_mask))
134 if(bbm::none(mask))
return 0;
140 for(
auto u : bbm::reflection::enum_v<unit_t>)
141 for(
auto c : bbm::reflection::enum_v<bsdf_flag>)
143 auto pdf_mask = mask && bbm::eq(component, c) && bbm::eq(unit, u);
144 if(bbm::any(pdf_mask))
155 return bbm::select(mask,
pdf / bbm::abs(4.0 * bbm::dot(out, h)), 0);
Replace an NDFs sample and pdf method with a data-driven numerical approximation.
Definition: sampler.h:36
Definition: ndf_sampler.h:25
BBM_CHECK_RAW_CONCEPT(concepts::ndf, backscatter)
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 diffuse BSDF given a direction and two random variables.
Definition: ndf_sampler.h:79
BBM_BSDF_FORWARD
Definition: ndf_sampler.h:59
Value pdf(const Vec3d &in, const Vec3d &out, BsdfFlag component=bsdf_flag::All, unit_t unit=unit_t::Radiance, Mask mask=true) const
Compute the pdf given an in and out direction.
Definition: ndf_sampler.h:128
BBM_IMPORT_CONFIG(BSDFMODEL)
std::map< std::pair< bsdf_flag, unit_t >, ndf::sampler< backscatter, samplesTheta, samplesPhi > > _samplers
Definition: ndf_sampler.h:162
ndf_sampler(Ts &&... ts)
forward to parent constructor, with empty _sampler (due to reference to *this)
Definition: ndf_sampler.h:63
static constexpr string_literal name
Definition: ndf_sampler.h:58
ndf concept
Definition: ndf.h:29
constexpr decltype(auto) attributes(T &&t)
Definition: reflection.h:200
constexpr decltype(auto) z(bbm::vec3d< T > &v)
Definition: vec.h:26
Definition: aggregatebsdf.h:29
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
bsdf_flag
Reflectance Component Evaluation Flags.
Definition: bsdf_flag.h:22
vec3d< T > reflect(const vec3d< T > &v, const vec3d< T > &normal)
Reflects a 3D vector.
Definition: vec_transform.h:44
unit_t
Light Unit.
Definition: unit.h:21
Assignable reference with wrapper support for rvalues.
Replace an NDF's sample and pdf method by a data-driven version. Monitors the NDF and update the inte...
Helper Class: Backscatter NDF passthrough.
Definition: ndf_sampler.h:35
unit_t unit
Definition: ndf_sampler.h:49
Value G1(const Vec3d &v, const Vec3d &m, Mask mask=true) const
Value pdf(const Vec3d &view, const Vec3d &m, Mask mask=true) const
Value eval(const Vec3d &halfway, Mask mask=true) const
Definition: ndf_sampler.h:43
Vec3d sample(const Vec3d &view, const Vec2d &xi, Mask mask=true) const
backscatter(void)
Definition: ndf_sampler.h:40
BBM_ATTRIBUTES(reflection::attributes(*model))
bsdf_flag component
Definition: ndf_sampler.h:48
const BSDFMODEL * model
Definition: ndf_sampler.h:50
backscatter(const BSDFMODEL *src, bsdf_flag c, unit_t u)
Definition: ndf_sampler.h:41
BBM_IMPORT_CONFIG(BSDFMODEL)
static constexpr string_literal name
Definition: ndf_sampler.h:38
Definition: string_literal.h:16
Compile-time reflection of: