star-vx

Structuring voxels for ray-tracing
git clone git://git.meso-star.fr/star-vx.git
Log | Files | Refs | README | LICENSE

commit 114cc20211fdf9ae828f36a2c400d0abc7ddc2d6
parent d1097a96bead3bca7012af41a7655130dbd60fe2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 13 Sep 2018 16:29:42 +0200

Fix several issues in the svx_bintree_trace_ray function

Diffstat:
Msrc/svx_bintree_trace_ray.c | 29++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/svx_bintree_trace_ray.c b/src/svx_bintree_trace_ray.c @@ -34,6 +34,7 @@ setup_hit const int flip, /* Define if the btree was reverted or not */ struct svx_hit* hit) { + enum svx_axis axis; double low; double upp; ASSERT(btree && hit); @@ -52,10 +53,11 @@ setup_hit upp = low + scale_exp2; /* Transform the voxel AABB in world space */ + axis = btree->frame[0]; d3_splat(hit->voxel.lower, -INF); d3_splat(hit->voxel.upper, INF); - hit->voxel.lower[btree->frame[0]] = low; - hit->voxel.upper[btree->frame[1]] = upp; + hit->voxel.lower[axis] = low * btree->tree_size[axis] + btree->tree_low[axis]; + hit->voxel.upper[axis] = upp * btree->tree_size[axis] + btree->tree_low[axis]; } /******************************************************************************* @@ -96,7 +98,7 @@ svx_bintree_trace_ray int null_dir = 0; /* Is the 1D dir is roughly null? */ if(!btree || !ray_org || !ray_dir || !ray_range || btree->type != SVX_BINTREE - || !d3_is_normalized(ray_dir)) { + || !d3_is_normalized(ray_dir) || !hit) { return RES_BAD_ARG; } @@ -142,8 +144,11 @@ svx_bintree_trace_ray pos_min = (float)MMAX(dir * ray_range[0] + org, 0); pos_max = (float)MMIN(dir * ray_range[1] + org, 1); - /* Defone the first traversed child and set its lower bound */ - if(org < 0.5) { + /* Define the first traversed child and set its lower bound */ + if(pos_min <= 0.5) { + /* Note that we use less than or *equal* in the previous test to be + * consistent with the svx_tree_at function: a position onto a boundary is + * owned by the node before the boundary */ ichild = 0; low = 0.0; } else { @@ -188,6 +193,9 @@ svx_bintree_trace_ray *hit = hit_tmp; break; } + + /* Stop traversal if no more voxel can be traversed */ + if(null_dir) break; } } @@ -203,9 +211,15 @@ svx_bintree_trace_ray ++istack; } - if(pos_min > child_mid) low = child_mid; + /* Get the node index of the traversed child */ + inode = buffer_get_child_node_index + (&btree->buffer, inode, (int)ichild_adjusted); + + ichild = pos_min > child_mid; + if(ichild == 1) low = child_mid; scale_exp2 = scale_exp2_child; ++depth; + continue; } } @@ -213,8 +227,9 @@ svx_bintree_trace_ray ASSERT(pos_min >= low && pos_min < low + scale_exp2); low += scale_exp2; /* Lower bound of the next node to traverse */ pos_min = low; /* Snap the pos_min to the next node lower bound */ + ++ichild; - if(ichild == 1) { /* No more child to traverse in this node => Pop node */ + if(ichild > 1) { /* No more child to traverse in this node => Pop node */ if(istack == 0) break; /* No more node to traverse */ /* Pop node */