@@ -81,6 +81,41 @@ template <std::size_t N, typename T>
8181 return std::abs (numerator / denominator);
8282}
8383
84+ template <std::size_t N, typename T, typename Color>
85+ void surface_not_found (
86+ const bool camera_path,
87+ const Scene<N, T, Color>* const scene,
88+ const LightDistribution<N, T, Color>* const light_distribution,
89+ const Color& beta,
90+ const T pdf_forward,
91+ const numerical::Ray<N, T>& ray,
92+ std::vector<vertex::Vertex<N, T, Color>>* const path)
93+ {
94+ if (camera_path)
95+ {
96+ path->emplace_back (
97+ std::in_place_type<vertex::InfiniteLight<N, T, Color>>, scene, light_distribution, ray, beta,
98+ pdf_forward);
99+ }
100+ }
101+
102+ template <std::size_t N, typename T, typename Color>
103+ void sample_not_found (
104+ const Color& beta,
105+ const T pdf_forward,
106+ const numerical::Ray<N, T>& ray,
107+ const SurfaceIntersection<N, T, Color>& surface,
108+ const com::Normals<N, T>& normals,
109+ std::vector<vertex::Vertex<N, T, Color>>* const path)
110+ {
111+ if (surface.light_source ())
112+ {
113+ vertex::Surface<N, T, Color> next (surface, normals, beta, -ray.dir ());
114+ set_forward_pdf (path->back (), &next, pdf_forward);
115+ path->push_back (std::move (next));
116+ }
117+ }
118+
84119template <std::size_t N, typename T, typename Color>
85120void add_sample (
86121 const com::SurfaceSamplePdf<N, T, Color>& sample,
@@ -126,25 +161,15 @@ void walk(
126161 {
127162 if (!surface_found (ray, surface, normals))
128163 {
129- if (camera_path)
130- {
131- path->emplace_back (
132- std::in_place_type<vertex::InfiniteLight<N, T, Color>>, scene,
133- light_distribution, ray, beta, pdf_forward);
134- }
164+ surface_not_found (camera_path, scene, light_distribution, beta, pdf_forward, ray, path);
135165 return ;
136166 }
137167
138168 const auto sample = com::surface_sample_with_pdf (surface, -ray.dir (), normals, engine);
139169
140170 if (!sample)
141171 {
142- if (surface.light_source ())
143- {
144- vertex::Surface<N, T, Color> next (surface, normals, beta, -ray.dir ());
145- set_forward_pdf (path->back (), &next, pdf_forward);
146- path->push_back (std::move (next));
147- }
172+ sample_not_found (beta, pdf_forward, ray, surface, normals, path);
148173 return ;
149174 }
150175
0 commit comments