Blender V5.3
light_tree.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "scene/light_tree.h"
6#include "scene/mesh.h"
7#include "scene/object.h"
8
9#include "util/math_fast.h"
10#include "util/progress.h"
11
13
15{
16 if (this->is_empty()) {
17 return 0.0f;
18 }
19
20 const float theta_w = fminf(M_PI_F, theta_o + theta_e);
21 const float cos_theta_o = cosf(theta_o);
22 const float sin_theta_o = sinf(theta_o);
23
24 return M_2PI_F * (1 - cos_theta_o) +
25 M_PI_2_F * (2 * theta_w * sin_theta_o - cosf(theta_o - 2 * theta_w) -
26 2 * theta_o * sin_theta_o + cos_theta_o);
27}
28
30{
31 if (cone_a.is_empty()) {
32 return cone_b;
33 }
34 if (cone_b.is_empty()) {
35 return cone_a;
36 }
37
38 /* Set cone `a` to always have the greater `theta_o`. */
39 const OrientationBounds *a = &cone_a;
40 const OrientationBounds *b = &cone_b;
41 if (cone_b.theta_o > cone_a.theta_o) {
42 a = &cone_b;
43 b = &cone_a;
44 }
45
46 const float cos_a_b = dot(a->axis, b->axis);
47 const float theta_d = safe_acosf(cos_a_b);
48 const float theta_e = fmaxf(a->theta_e, b->theta_e);
49
50 /* Return axis and `theta_o` of `a` if it already contains `b`. */
51 /* This should also be called when `b` is empty. */
52 if (a->theta_o + 5e-4f >= fminf(M_PI_F, theta_d + b->theta_o)) {
53 return OrientationBounds({a->axis, a->theta_o, theta_e});
54 }
55
56 /* Compute new `theta_o` that contains both `a` and `b`. */
57 const float theta_o = (theta_d + a->theta_o + b->theta_o) * 0.5f;
58
59 if (theta_o >= M_PI_F) {
60 return OrientationBounds({a->axis, M_PI_F, theta_e});
61 }
62
63 /* Slerp between `a` and `b`. */
64 float3 new_axis;
65 if (cos_a_b < -0.9995f) {
66 /* Opposite direction, any orthogonal vector is fine. */
67 float3 unused;
68 make_orthonormals(a->axis, &new_axis, &unused);
69 }
70 else {
71 const float theta_r = theta_o - a->theta_o;
72 const float3 ortho = safe_normalize(b->axis - a->axis * cos_a_b);
73 new_axis = a->axis * cosf(theta_r) + ortho * sinf(theta_r);
74 }
75
76 return OrientationBounds({new_axis, theta_o, theta_e});
77}
78
80{
81 centroid = object->bounds.center();
82 light_set_membership = object->get_light_set_membership();
83}
84
86 const int prim_id,
87 const int object_id,
88 bool need_transformation)
90{
91 Object *object = scene->objects[object_id];
92
93 if (is_triangle()) {
94 float3 vertices[3];
95 Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
96 const Mesh::Triangle triangle = mesh->get_triangle(prim_id);
97 Shader *shader = static_cast<Shader *>(mesh->get_used_shaders()[mesh->get_shader()[prim_id]]);
98
99 const packed_float3 *mesh_positions = mesh->get_position();
100 for (int i = 0; i < 3; i++) {
101 vertices[i] = mesh_positions[triangle.v[i]];
102 }
103
104 if (need_transformation) {
106 const Transform &tfm = object->get_tfm();
107 for (int i = 0; i < 3; i++) {
108 vertices[i] = transform_point(&tfm, vertices[i]);
109 }
110 }
111
112 /* TODO: need a better way to handle this when textures are used. */
113 const float area = triangle_area(vertices[0], vertices[1], vertices[2]);
114 /* Use absolute value of emission_estimate so lights with negative strength are properly
115 * supported in the light tree. */
116 measure.energy = area * average(fabs(shader->emission_estimate));
117
118 /* NOTE: the original implementation used the bounding box centroid, but triangle centroid
119 * seems to work fine. */
120 centroid = (vertices[0] + vertices[1] + vertices[2]) * (1.0f / 3.0f);
121
122 const bool is_front_only = (shader->emission_sampling == EMISSION_SAMPLING_FRONT);
123 const bool is_back_only = (shader->emission_sampling == EMISSION_SAMPLING_BACK);
124 if (is_front_only || is_back_only) {
125 /* One-sided. */
127 cross(vertices[1] - vertices[0], vertices[2] - vertices[0]));
128 if (is_back_only) {
130 }
131 if ((need_transformation || mesh->transform_applied) &&
132 transform_negative_scale(object->get_tfm()))
133 {
135 }
137 }
138 else {
139 /* Double sided: any vector in the plane. */
140 measure.bcone.axis = safe_normalize(vertices[0] - vertices[1]);
142 }
144
145 for (int i = 0; i < 3; i++) {
146 measure.bbox.grow(vertices[i]);
147 }
148
149 light_set_membership = object->get_light_set_membership();
150 }
151 else {
152 assert(is_light());
153 Light *lamp = static_cast<Light *>(object->get_geometry());
154 float3 strength = lamp->get_strength();
155
156 if (!lamp->get_normalize()) {
157 strength *= lamp->area(object->get_tfm());
158 }
159
160 centroid = transform_get_column(&object->get_tfm(), 3);
161 measure.bcone.axis = -safe_normalize(transform_get_column(&object->get_tfm(), 2));
162
163 if (lamp->is_area_light()) {
164 const AreaLight *light = static_cast<const AreaLight *>(lamp);
166 measure.bcone.theta_e = light->get_spread() * 0.5f;
167
168 /* For an area light, sizeu and sizev determine the 2 dimensions of the area light,
169 * while axisu and axisv determine the orientation of the 2 dimensions.
170 * We want to add all 4 corners to our bounding box. */
171 const float3 axisu = transform_get_column(&object->get_tfm(), 0);
172 const float3 axisv = transform_get_column(&object->get_tfm(), 1);
173 const float3 half_extentu = 0.5f * light->get_sizeu() * axisu;
174 const float3 half_extentv = 0.5f * light->get_sizev() * axisv;
175 measure.bbox.grow(centroid + half_extentu + half_extentv);
176 measure.bbox.grow(centroid + half_extentu - half_extentv);
177 measure.bbox.grow(centroid - half_extentu + half_extentv);
178 measure.bbox.grow(centroid - half_extentu - half_extentv);
179
180 /* Convert irradiance to radiance. */
181 strength *= M_1_PI_F;
182 }
183 else if (lamp->is_point_light()) {
186 }
187 else if (lamp->is_spot_light()) {
189
190 float theta_e = min(static_cast<const SpotLight *>(lamp)->get_angle() * 0.5f, M_PI_2_F);
191 const float len_u = len(transform_get_column(&object->get_tfm(), 0));
192 const float len_v = len(transform_get_column(&object->get_tfm(), 1));
193 const float len_w = len(transform_get_column(&object->get_tfm(), 2));
194
195 /* As `theta_e` approaches `pi/2`, the behavior of `atan(tan(theta_e))` can become quite
196 * unpredictable as `tan(x)` has an asymptote at `x = pi/2`. To avoid this, we skip the back
197 * and forward conversion.
198 * The conversion is required to deal with scaled lights, but near `pi/2` the scaling does
199 * not make a big difference in the angle, so we can skip the conversion without worrying
200 * about overestimation. */
201 if (fabsf(M_PI_2_F - theta_e) < 1e-6f) {
202 theta_e = M_PI_2_F;
203 }
204 else {
205 theta_e = fast_atanf(fast_tanf(theta_e) * fmaxf(len_u, len_v) / len_w);
206 }
207 measure.bcone.theta_e = theta_e;
208 }
209 else if (lamp->is_background_light()) {
210 /* Set an arbitrary direction for the background light. */
211 measure.bcone.axis = make_float3(0.0f, 0.0f, 1.0f);
212 /* TODO: this may depend on portal lights as well. */
215
216 /* integrate over cosine-weighted hemisphere */
217 strength *= static_cast<const BackgroundLight *>(lamp)->get_average_radiance() * M_PI_F;
218 }
219 else if (lamp->is_sun_light()) {
221 measure.bcone.theta_e = 0.5f * static_cast<const SunLight *>(lamp)->get_angle();
222 }
223
224 if (const PointLight *point_light = dynamic_cast<PointLight *>(lamp)) {
225 /* Point and spot lights can emit light from any point within its radius. */
226 const float3 radius = make_float3(point_light->get_radius());
227 measure.bbox.grow(centroid - radius);
228 measure.bbox.grow(centroid + radius);
229
230 strength *= 0.25f * M_1_PI_F; /* eval_fac scaling in `spot.h` and `point.h` */
231 }
232
233 if (lamp->get_shader()) {
234 strength *= lamp->get_shader()->emission_estimate;
235 }
236
237 /* Use absolute value of energy so lights with negative strength are properly supported in the
238 * light tree. */
239 measure.energy = average(fabs(strength));
240
241 light_set_membership = object->get_light_set_membership();
242 }
243}
244
245static void sort_leaf(const int start, const int end, LightTreeEmitter *emitters)
246{
247 /* Sort primitive by light link mask so that specialized trees can use a subset of these. */
248 if (end > start) {
249 std::sort(emitters + start,
250 emitters + end,
251 [](const LightTreeEmitter &a, const LightTreeEmitter &b) {
252 return a.light_set_membership < b.light_set_membership;
253 });
254 }
255}
256
257bool LightTree::triangle_usable_as_light(Mesh *mesh, const int prim_id)
258{
259 const int shader_index = mesh->get_shader()[prim_id];
260 if (shader_index < mesh->get_used_shaders().size()) {
261 Shader *shader = static_cast<Shader *>(mesh->get_used_shaders()[shader_index]);
263 return true;
264 }
265 }
266 return false;
267}
268
269void LightTree::add_mesh(Scene *scene, Mesh *mesh, const int object_id)
270{
271 const size_t mesh_num_triangles = mesh->num_triangles();
272 for (size_t i = 0; i < mesh_num_triangles; i++) {
273 if (triangle_usable_as_light(mesh, i)) {
274 emitters_.emplace_back(scene, i, object_id);
275 }
276 }
277}
278
280 DeviceScene *dscene,
281 Progress &progress,
282 const uint max_lights_in_leaf)
283 : progress_(progress), max_lights_in_leaf_(max_lights_in_leaf)
284{
285 KernelIntegrator *kintegrator = &dscene->data.integrator;
286
287 local_lights_.reserve(kintegrator->num_lights - kintegrator->num_distant_lights);
288 distant_lights_.reserve(kintegrator->num_distant_lights);
289
290 /* When we keep track of the light index, only contributing lights will be added to the device.
291 * Therefore, we want to keep track of the light's index on the device.
292 * However, we also need the light's index in the scene when we're constructing the tree. */
293 int device_light_index = 0;
294 for (Object *object : scene->objects) {
295 if (progress_.get_cancel()) {
296 return;
297 }
298
299 if (object->get_geometry()->is_light()) {
300 /* Regular lights. */
301 Light *light = static_cast<Light *>(object->get_geometry());
302 if (light->is_enabled) {
303 if (light->is_distant_light()) {
304 distant_lights_.emplace_back(scene, ~device_light_index, object->index);
305 }
306 else {
307 local_lights_.emplace_back(scene, ~device_light_index, object->index);
308 }
309
310 device_light_index++;
311 }
312 }
313 else {
314 /* Emissive triangles. */
315 light_link_receiver_used |= (uint64_t(1) << object->get_receiver_light_set());
316
317 if (!object->usable_as_light()) {
318 continue;
319 }
320
321 mesh_lights_.emplace_back(object, object->index);
322
323 /* Only count unique meshes. */
324 Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
325 auto map_it = offset_map_.find(mesh);
326 if (map_it == offset_map_.end()) {
327 offset_map_[mesh] = num_triangles;
328 num_triangles += mesh->num_triangles();
329 }
330 }
331 }
332}
333
335{
336 if (local_lights_.empty() && distant_lights_.empty() && mesh_lights_.empty()) {
337 return nullptr;
338 }
339
340 const int num_mesh_lights = mesh_lights_.size();
341 int num_local_lights = local_lights_.size() + num_mesh_lights;
342 const int num_distant_lights = distant_lights_.size();
343
344 /* Create a node for each mesh light, and keep track of unique mesh lights. */
345 std::unordered_map<Mesh *, std::tuple<LightTreeNode *, int, int>> unique_mesh;
346 uint *object_offsets = dscene->object_lookup_offset.alloc(scene->objects.size());
347 emitters_.reserve(num_triangles + num_local_lights + num_distant_lights);
348 for (LightTreeEmitter &emitter : mesh_lights_) {
349 Object *object = scene->objects[emitter.object_id];
350 Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
351 emitter.root = create_node(LightTreeMeasure::empty, 0);
352
353 auto map_it = unique_mesh.find(mesh);
354 if (map_it == unique_mesh.end()) {
355 const int start = emitters_.size();
356 add_mesh(scene, mesh, emitter.object_id);
357 const int end = emitters_.size();
358
359 unique_mesh[mesh] = std::make_tuple(emitter.root.get(), start, end);
360 emitter.root->object_id = emitter.object_id;
361 }
362 else {
363 emitter.root->make_instance(std::get<0>(map_it->second), emitter.object_id);
364 }
365 object_offsets[emitter.object_id] = offset_map_[mesh];
366 }
367
368 /* Build a subtree for each unique mesh light. */
369 parallel_for_each(unique_mesh, [this](auto &map_it) {
370 LightTreeNode *node = std::get<0>(map_it.second);
371 int const start = std::get<1>(map_it.second);
372 int const end = std::get<2>(map_it.second);
373 recursive_build(self, node, start, end, emitters_.data(), 0, 0);
374 node->type |= LIGHT_TREE_INSTANCE;
375 });
376 task_pool.wait_work();
377
378 /* Update measure. */
379 parallel_for_each(mesh_lights_, [&](LightTreeEmitter &emitter) {
380 Object *object = scene->objects[emitter.object_id];
381 Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
382
383 LightTreeNode *reference = std::get<0>(unique_mesh.find(mesh)->second);
384 emitter.measure = emitter.root->measure = reference->measure;
385
386 /* Transform measure. The measure is only directly transformable if the transformation has
387 * uniform scaling, otherwise recount all the triangles in the mesh with transformation. */
388 /* NOTE: in theory only energy needs recalculating: #bbox is available via `object->bounds`,
389 * transformation of #bcone is possible. However, the computation involves eigendecomposition
390 * and solving a cubic equation (https://doi.org/10.1016/j.nima.2009.11.075 section 3.4), then
391 * the angle is derived from the major axis of the resulted right elliptic cone's base, which
392 * can be an overestimation. */
393 if (!mesh->transform_applied && !emitter.measure.transform(object->get_tfm())) {
394 emitter.measure.reset();
395 size_t const mesh_num_triangles = mesh->num_triangles();
396 for (size_t i = 0; i < mesh_num_triangles; i++) {
397 if (triangle_usable_as_light(mesh, i)) {
398 emitter.measure.add(LightTreeEmitter(scene, i, emitter.object_id, true).measure);
399 }
400 }
401 }
402 });
403
404 for (LightTreeEmitter &emitter : mesh_lights_) {
405 emitter.root->measure = emitter.measure;
406 }
407
408 /* Could be different from `num_triangles` if only some triangles of an object are emissive. */
409 const int num_emissive_triangles = emitters_.size();
410 num_local_lights += num_emissive_triangles;
411
412 /* Build the top level tree. */
414
415 /* All local lights and mesh lights are grouped to the left child as an inner node. */
416 std::move(local_lights_.begin(), local_lights_.end(), std::back_inserter(emitters_));
417 std::move(mesh_lights_.begin(), mesh_lights_.end(), std::back_inserter(emitters_));
418 recursive_build(
419 left, root_.get(), num_emissive_triangles, num_local_lights, emitters_.data(), 0, 1);
420 task_pool.wait_work();
421
422 if (progress_.get_cancel()) {
423 root_.reset();
424 return nullptr;
425 }
426
427 /* All distant lights are grouped to the right child as a leaf node. */
428 root_->get_inner().children[right] = create_node(LightTreeMeasure::empty, 1);
429 for (int i = 0; i < num_distant_lights; i++) {
430 root_->get_inner().children[right]->add(distant_lights_[i]);
431 }
432
433 sort_leaf(0, num_distant_lights, distant_lights_.data());
434 root_->get_inner().children[right]->make_distant(num_local_lights, num_distant_lights);
435
436 root_->measure = root_->get_inner().children[left]->measure +
437 root_->get_inner().children[right]->measure;
438 root_->light_link = root_->get_inner().children[left]->light_link +
439 root_->get_inner().children[right]->light_link;
440
441 /* Root nodes are never meant to be shared, even if the local and distant lights are from the
442 * same light linking set. Attempting to sharing it will make it so the specialized tree will
443 * try to use the same root as the default tree. */
444 root_->light_link.shareable = false;
445
446 std::move(distant_lights_.begin(), distant_lights_.end(), std::back_inserter(emitters_));
447
448 return root_.get();
449}
450
451void LightTree::recursive_build(const Child child,
452 LightTreeNode *inner,
453 const int start,
454 const int end,
455 LightTreeEmitter *emitters,
456 const uint bit_trail,
457 const int depth)
458{
459 if (progress_.get_cancel()) {
460 return;
461 }
462
463 LightTreeNode *node;
464 if (child == self) {
465 /* Building subtree. */
466 node = inner;
467 }
468 else {
469 inner->get_inner().children[child] = create_node(LightTreeMeasure::empty, bit_trail);
470 node = inner->get_inner().children[child].get();
471 }
472
473 /* Find the best place to split the emitters into 2 nodes.
474 * If the best split cost is no better than making a leaf node, make a leaf instead. */
475 int split_dim = -1;
476 int middle;
477 if (should_split(emitters, start, middle, end, node->measure, node->light_link, split_dim)) {
478
479 if (split_dim != -1) {
480 /* Partition the emitters between start and end based on the centroids. */
481 std::nth_element(emitters + start,
482 emitters + middle,
483 emitters + end,
484 [split_dim](const LightTreeEmitter &l, const LightTreeEmitter &r) {
485 return l.centroid[split_dim] < r.centroid[split_dim];
486 });
487 }
488
489 /* Recursively build the left branch. */
490 if (middle - start > MIN_EMITTERS_PER_THREAD) {
491 task_pool.push([this, node, start, middle, emitters, bit_trail, depth] {
492 recursive_build(left, node, start, middle, emitters, bit_trail, depth + 1);
493 });
494 }
495 else {
496 recursive_build(left, node, start, middle, emitters, bit_trail, depth + 1);
497 }
498
499 /* Recursively build the right branch. */
500 if (end - middle > MIN_EMITTERS_PER_THREAD) {
501 task_pool.push([this, node, middle, end, emitters, bit_trail, depth] {
502 recursive_build(right, node, middle, end, emitters, bit_trail | (1u << depth), depth + 1);
503 });
504 }
505 else {
506 recursive_build(right, node, middle, end, emitters, bit_trail | (1u << depth), depth + 1);
507 }
508 }
509 else {
510 sort_leaf(start, end, emitters);
511 node->make_leaf(start, end - start);
512 }
513}
514
515bool LightTree::should_split(LightTreeEmitter *emitters,
516 const int start,
517 int &middle,
518 const int end,
519 LightTreeMeasure &measure,
520 LightTreeLightLink &light_link,
521 int &split_dim)
522{
523 const int num_emitters = end - start;
524 if (num_emitters < 2) {
525 if (num_emitters) {
526 /* Do not try to split if there is only one emitter. */
527 measure = emitters[start].measure;
528 light_link = LightTreeLightLink(emitters[start].light_set_membership);
529 }
530 return false;
531 }
532
533 middle = (start + end) / 2;
534
535 BoundBox centroid_bbox = BoundBox::empty;
536 for (int i = start; i < end; i++) {
537 centroid_bbox.grow((emitters + i)->centroid);
538 }
539
540 const float3 extent = centroid_bbox.size();
541 const float max_extent = max4(extent.x, extent.y, extent.z, 0.0f);
542
543 /* Check each dimension to find the minimum splitting cost. */
544 float total_cost = 0.0f;
545 float min_cost = FLT_MAX;
546 for (int dim = 0; dim < 3; dim++) {
547 std::array<LightTreeBucket, LightTreeBucket::num_buckets> buckets;
548 float inv_extent;
549
550 if (centroid_bbox.size()[dim] == 0.0f) {
551 /* If the centroid bounding box is 0 along a given dimension and the node measure is
552 * already computed, skip it. */
553 if (dim != 0) {
554 continue;
555 }
556
557 /* Degenerate case, everything in the same bucket. */
558 inv_extent = FLT_MAX;
559 for (int i = start; i < end; i++) {
560 buckets[0].add(emitters[i]);
561 }
562 }
563 else {
564 /* Fill in buckets with emitters. */
565 inv_extent = 1 / (centroid_bbox.size()[dim]);
566 for (int i = start; i < end; i++) {
567 const LightTreeEmitter *emitter = emitters + i;
568
569 /* Place emitter into the appropriate bucket, where the centroid box is split into equal
570 * partitions. */
571 int bucket_idx = LightTreeBucket::num_buckets *
572 (emitter->centroid[dim] - centroid_bbox.min[dim]) * inv_extent;
573 bucket_idx = clamp(bucket_idx, 0, LightTreeBucket::num_buckets - 1);
574
575 buckets[bucket_idx].add(*emitter);
576 }
577 }
578
579 /* Precompute the left bucket measure cumulatively. */
580 std::array<LightTreeBucket, LightTreeBucket::num_buckets - 1> left_buckets;
581 left_buckets.front() = buckets.front();
582 for (int i = 1; i < LightTreeBucket::num_buckets - 1; i++) {
583 left_buckets[i] = left_buckets[i - 1] + buckets[i];
584 }
585
586 if (dim == 0) {
587 /* Calculate node measure by summing up the bucket measure. */
588 measure = left_buckets.back().measure + buckets.back().measure;
589 light_link = left_buckets.back().light_link + buckets.back().light_link;
590
591 /* Degenerate case with co-located emitters. */
592 if (is_zero(centroid_bbox.size())) {
593 break;
594 }
595
596 /* If the centroid bounding box is 0 along a given dimension, skip it. */
597 if (centroid_bbox.size()[dim] == 0.0f) {
598 continue;
599 }
600
601 total_cost = measure.calculate();
602 if (total_cost == 0.0f) {
603 break;
604 }
605 }
606
607 /* Precompute the right bucket measure cumulatively. */
608 std::array<LightTreeBucket, LightTreeBucket::num_buckets - 1> right_buckets;
609 right_buckets.back() = buckets.back();
610 for (int i = LightTreeBucket::num_buckets - 3; i >= 0; i--) {
611 right_buckets[i] = right_buckets[i + 1] + buckets[i + 1];
612 }
613
614 /* Calculate the cost of splitting at each point between partitions. */
615 const float regularization = max_extent * inv_extent;
616 for (int split = 0; split < LightTreeBucket::num_buckets - 1; split++) {
617 const float left_cost = left_buckets[split].measure.calculate();
618 const float right_cost = right_buckets[split].measure.calculate();
619 const float cost = regularization * (left_cost + right_cost);
620
621 if (cost < total_cost && cost < min_cost) {
622 min_cost = cost;
623 split_dim = dim;
624 middle = start + left_buckets[split].count;
625 }
626 }
627 }
628 return min_cost < total_cost || num_emitters > max_lights_in_leaf_;
629}
630
632{
633 LightTreeMeasure c(a);
634 c.add(b);
635 return c;
636}
637
639{
640 return LightTreeBucket(a.measure + b.measure, a.light_link + b.light_link, a.count + b.count);
641}
642
644{
646 c.add(b);
647 return c;
648}
649
unsigned long long int uint64_t
__forceinline float3 size() const
Definition boundbox.h:122
__forceinline void grow(const float3 &pt)
Definition boundbox.h:35
float3 min
Definition boundbox.h:20
device_vector< uint > object_lookup_offset
Definition devicescene.h:72
KernelData data
bool transform_applied
const packed_float3 * get_position() const
LightTree(Scene *scene, DeviceScene *dscene, Progress &progress, const uint max_lights_in_leaf)
unique_ptr< LightTreeNode > create_node(const LightTreeMeasure &measure, const uint &bit_trial)
Definition light_tree.h:419
size_t num_triangles
Definition light_tree.h:401
LightTreeNode * build(Scene *scene, DeviceScene *dscene)
size_t num_emitters() const
Definition light_tree.h:425
bool is_spot_light() const
bool is_sun_light() const
virtual float area(const Transform &tfm) const =0
Shader * get_shader() const
bool is_background_light() const
bool is_point_light() const
bool is_area_light() const
size_t num_triangles() const
Definition scene/mesh.h:73
Triangle get_triangle(const size_t i) const
Definition scene/mesh.h:67
bool get_cancel() const
Definition progress.h:77
Definition scene.h:133
unique_ptr_vector< Object > objects
Definition scene.h:162
float3 emission_estimate
EmissionSampling emission_sampling
T * alloc(const size_t width, const size_t height=0)
size_t size() const
#define M_PI_2_F
#define M_1_PI_F
#define __forceinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define assert(assertion)
#define FLT_MAX
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
constexpr T clamp(T, U, U) RET
VecBase< float, 3 > float3
bool is_zero(float3x3 a)
float3 transform_point(float3x3 mat, float3 point)
float average(float2 a)
VecT safe_normalize(VecT vector)
if(state< num_states)
@ LIGHT_TREE_INSTANCE
@ EMISSION_SAMPLING_NONE
@ EMISSION_SAMPLING_BACK
@ EMISSION_SAMPLING_FRONT
static void sort_leaf(const int start, const int end, LightTreeEmitter *emitters)
__forceinline LightTreeMeasure operator+(const LightTreeMeasure &a, const LightTreeMeasure &b)
OrientationBounds merge(const OrientationBounds &cone_a, const OrientationBounds &cone_b)
ccl_device float safe_acosf(const float a)
Definition math_base.h:590
ccl_device_inline T max4(const T &a, const T &b, const T &c, const T &d)
Definition math_base.h:214
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
Definition math_dual.h:241
ccl_device float fast_tanf(float x)
Definition math_fast.h:183
ccl_device float fast_atanf(const float x)
Definition math_fast.h:290
ccl_device_inline float triangle_area(const ccl_private float3 &v1, const ccl_private float3 &v2, const ccl_private float3 &v3)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)
int size(const AssetLibraryReference *library_reference)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
ATTR_WARN_UNUSED_RESULT const BMLoop * l
#define fabsf
#define M_2PI_F
#define fmaxf
#define sinf
#define fminf
#define M_PI_F
#define cosf
#define min(a, b)
Definition sort.cc:38
LightTreeBucket()=default
LightTreeLightLink light_link
Definition light_tree.h:223
static const int num_buckets
Definition light_tree.h:225
LightTreeMeasure measure
Definition light_tree.h:222
__forceinline bool is_triangle() const
Definition light_tree.h:208
unique_ptr< LightTreeNode > root
Definition light_tree.h:186
uint64_t light_set_membership
Definition light_tree.h:193
LightTreeMeasure measure
Definition light_tree.h:195
LightTreeEmitter(Object *object, const int object_id)
__forceinline bool is_light() const
Definition light_tree.h:213
OrientationBounds bcone
Definition light_tree.h:66
bool transform(const Transform &tfm)
Definition light_tree.h:117
__forceinline void reset()
Definition light_tree.h:112
__forceinline float calculate()
Definition light_tree.h:101
__forceinline void add(const LightTreeMeasure &measure)
Definition light_tree.h:91
unique_ptr< LightTreeNode > children[2]
Definition light_tree.h:266
__forceinline Inner & get_inner()
Definition light_tree.h:299
LightTreeMeasure measure
Definition light_tree.h:248
__forceinline bool is_empty() const
Definition light_tree.h:46
__forceinline OrientationBounds()=default
float calculate_measure() const
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
ccl_device_inline float3 transform_get_column(const Transform *t, const int column)
Definition transform.h:387
ccl_device_inline bool transform_negative_scale(const Transform &tfm)
Definition transform.h:429