Skip to content

Commit

Permalink
Properly handle single node case
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Aug 23, 2024
1 parent bd59cf5 commit fcb7097
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 65 deletions.
7 changes: 6 additions & 1 deletion internal/SceneCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,12 @@ void Ray::Cpu::Scene::RebuildLightTree_nolock() {
(void)root_node;
light_nodes_.clear();

// Collapse leaf level (all nodes have only 1 child)
// Collapse leaf level (all leafs have only 1 light)
if ((light_wnodes_[0].child[0] & LEAF_NODE_BIT) != 0) {
for (int j = 1; j < 8; ++j) {
light_wnodes_[0].child[j] = 0x7fffffff;
}
}
std::vector<bool> should_remove(light_wnodes_.size(), false);
for (uint32_t i = 0; i < light_wnodes_.size(); ++i) {
if ((light_wnodes_[i].child[0] & LEAF_NODE_BIT) == 0) {
Expand Down
7 changes: 6 additions & 1 deletion internal/SceneGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,12 @@ inline void Ray::NS::Scene::RebuildLightTree_nolock() {
assert(root_node == 0);
(void)root_node;

// Collapse leaf level (all nodes have only 1 child)
// Collapse leaf level (all leafs have only 1 light)
if ((temp_light_wnodes[0].child[0] & LEAF_NODE_BIT) != 0) {
for (int j = 1; j < 8; ++j) {
temp_light_wnodes[0].child[j] = 0x7fffffff;
}
}
std::vector<bool> should_remove(temp_light_wnodes.size(), false);
for (uint32_t i = 0; i < temp_light_wnodes.size(); ++i) {
if ((temp_light_wnodes[i].child[0] & LEAF_NODE_BIT) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_atlas.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_atlas.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_bindless.comp.cso.inl

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/output/shade_secondary_bindless.comp.spv.inl

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/shaders/shade.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,9 @@ float EvalTriLightFactor(const vec3 P, const vec3 ro, uint tri_index) {
const uint cur = g_stack[gl_LocalInvocationIndex][--stack_size];
const float cur_factor = g_stack_factors[gl_LocalInvocationIndex][stack_size];

light_wbvh_node_t n = g_light_wnodes[cur];
if ((cur & LEAF_NODE_BIT) == 0) {
light_wbvh_node_t n = g_light_wnodes[cur];

if ((n.child[0] & LEAF_NODE_BIT) == 0) {
float importance[8];
const float total_importance = calc_lnode_importance(n, ro, importance);

Expand All @@ -1329,7 +1329,7 @@ float EvalTriLightFactor(const vec3 P, const vec3 ro, uint tri_index) {
}
}
} else {
const int light_index = int(n.child[0] & PRIM_INDEX_BITS);
const int light_index = int(cur & PRIM_INDEX_BITS);

light_t l = g_lights[light_index];
if (LIGHT_TYPE(l) == LIGHT_TYPE_TRI && floatBitsToUint(l.TRI_TRI_INDEX) == tri_index) {
Expand Down

0 comments on commit fcb7097

Please sign in to comment.