Skip to content

Commit

Permalink
Simplify LightTree implementation (#1568)
Browse files Browse the repository at this point in the history
* Remove LightSource stuff from building the `LightTree`

* Stop changing emitting triangle vector when building the light tree

* Remove light source stuff from light tree sampling

* Remove `LightSource`

* Avoid duplication

* Cosmetics

* Tree build returns look up table for EMTs

* Move is redundant, c++11 will move it during RVO

* Cosmetics
  • Loading branch information
gospodnetic authored and dictoon committed Aug 2, 2017
1 parent 11203ae commit 7937ff3
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 366 deletions.
3 changes: 0 additions & 3 deletions src/appleseed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,9 @@ set (renderer_kernel_lighting_sources
renderer/kernel/lighting/lightsample.h
renderer/kernel/lighting/materialsamplers.cpp
renderer/kernel/lighting/materialsamplers.h
renderer/kernel/lighting/lighttypes.h
renderer/kernel/lighting/lighttypes.cpp
renderer/kernel/lighting/lighttree.cpp
renderer/kernel/lighting/lighttree.h
renderer/kernel/lighting/lighttree_node.h
renderer/kernel/lighting/lighttypes.cpp
renderer/kernel/lighting/lighttypes.h
renderer/kernel/lighting/pathtracer.h
renderer/kernel/lighting/pathvertex.cpp
Expand Down
34 changes: 21 additions & 13 deletions src/appleseed/renderer/kernel/lighting/backwardlightsampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ BackwardLightSampler::BackwardLightSampler(
if (m_non_physical_lights_cdf.valid())
m_non_physical_lights_cdf.prepare();

// Build the light tree.
m_light_tree_light_count = m_use_light_tree
? m_light_tree.build(m_light_tree_lights, m_emitting_triangles)
: 0;

if (!m_use_light_tree)
if (m_use_light_tree)
{
// Initialize the LightTree only after the lights are collected.
m_light_tree.reset(new LightTree(m_light_tree_lights, m_emitting_triangles));

const vector<size_t> tri_index_to_node_index = m_light_tree->build();
if (has_hittable_lights())
{
// Update information about emitting triangle position within the light tree.
for (size_t i = 0, e = tri_index_to_node_index.size(); i < e; ++i)
m_emitting_triangles[i].m_light_tree_node_index = tri_index_to_node_index[i];
}
}
else
{
if (m_emitting_triangles_cdf.valid())
m_emitting_triangles_cdf.prepare();
Expand All @@ -107,8 +115,8 @@ BackwardLightSampler::BackwardLightSampler(
"found %s %s, %s %s, %s emitting %s.",
pretty_int(m_non_physical_light_count).c_str(),
plural(m_non_physical_light_count, "non-physical light").c_str(),
pretty_int(m_light_tree_light_count).c_str(),
plural(m_light_tree_light_count, "light-tree compatible light").c_str(),
pretty_int(m_light_tree_lights.size() + m_emitting_triangles.size()).c_str(),
plural(m_light_tree_lights.size() + m_emitting_triangles.size(), "light-tree compatible light").c_str(),
pretty_int(m_emitting_triangles.size()).c_str(),
plural(m_emitting_triangles.size(), "triangle").c_str());
}
Expand Down Expand Up @@ -171,7 +179,7 @@ float BackwardLightSampler::evaluate_pdf(const ShadingPoint& shading_point) cons
if (m_use_light_tree)
{
const float triangle_probability =
m_light_tree.evaluate_node_pdf(
m_light_tree->evaluate_node_pdf(
shading_point.get_ray().m_org,
triangle->m_light_tree_node_index);

Expand Down Expand Up @@ -526,17 +534,17 @@ void BackwardLightSampler::sample_light_tree(
{
assert(has_lightset());

int light_type;
LightType light_type;
size_t light_index;
float light_prob;
m_light_tree.sample(
m_light_tree->sample(
shading_point.get_point(),
s[0],
light_type,
light_index,
light_prob);

if (light_type == LightSource::NonPhysicalLightType)
if (light_type == NonPhysicalLightType)
{
// Fetch the light.
const NonPhysicalLightInfo& light_info = m_light_tree_lights[light_index];
Expand All @@ -552,7 +560,7 @@ void BackwardLightSampler::sample_light_tree(
}
else
{
assert(light_type == LightSource::EmittingTriangleType);
assert(light_type == EmittingTriangleType);
sample_emitting_triangle(
time,
Vector2f(s[1], s[2]),
Expand Down
10 changes: 5 additions & 5 deletions src/appleseed/renderer/kernel/lighting/backwardlightsampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

// Standard headers.
#include <cstddef>
#include <memory>
#include <vector>

// Forward declarations.
Expand Down Expand Up @@ -112,15 +113,14 @@ class BackwardLightSampler
explicit Parameters(const ParamArray& params);
};

typedef std::vector<NonPhysicalLightInfo> NonPhysicalLightVector;
typedef std::vector<EmittingTriangle> EmittingTriangleVector;
typedef foundation::CDF<size_t, float> EmitterCDF;
typedef std::vector<NonPhysicalLightInfo> NonPhysicalLightVector;
typedef std::vector<EmittingTriangle> EmittingTriangleVector;
typedef foundation::CDF<size_t, float> EmitterCDF;

const Parameters m_params;

NonPhysicalLightVector m_light_tree_lights;
NonPhysicalLightVector m_non_physical_lights;
size_t m_light_tree_light_count;
size_t m_non_physical_light_count;

EmittingTriangleVector m_emitting_triangles;
Expand All @@ -131,7 +131,7 @@ class BackwardLightSampler
EmittingTriangleKeyHasher m_triangle_key_hasher;
EmittingTriangleHashTable m_emitting_triangle_hash_table;

LightTree m_light_tree;
std::unique_ptr<LightTree> m_light_tree;

bool m_use_light_tree;

Expand Down

0 comments on commit 7937ff3

Please sign in to comment.