commit 1c25f43c6c8d4eb081051a4706720401da9e5091
parent f89945f16a1a4c640266b29f9d583dfe9473f057
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 28 Sep 2018 18:05:14 +0200
Use double in the bintree ray tracing kernel
Diffstat:
2 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/src/svx_bintree_trace_ray.c b/src/svx_bintree_trace_ray.c
@@ -86,12 +86,12 @@ bintree_trace_ray
struct buffer_index inode;
size_t istack; /* Top of the stack */
size_t iaxis; /* Id in [0, 2] of the axis along which the tree is defined */
- float pos_min, pos_max; /* Min/Max pos along the ray in [0,1] +dir 1D space */
- float org; /* Ray origin in the [0,1] +dir 1D space */
- float dir; /* Ray direction in the [0,1] +dir 1D space */
- float ts; /* 1/(Ray direction) in the [0,1] +dir 1D space */
- float rcp_btreesz; /* Reciprocal of the binary tree size */
- float low; /* Lower bound of the traversed node */
+ double pos_min, pos_max; /* Min/Max pos along the ray in [0,1] +dir 1D space */
+ double org; /* Ray origin in the [0,1] +dir 1D space */
+ double dir; /* Ray direction in the [0,1] +dir 1D space */
+ double ts; /* 1/(Ray direction) in the [0,1] +dir 1D space */
+ double rcp_btreesz; /* Reciprocal of the binary tree size */
+ double low; /* Lower bound of the traversed node */
float scale_exp2; /* Current size of a node in the [0,1] +dir 1D space */
uint32_t depth; /* Depth of the traversed nodes */
int ichild; /* Traversed child */
@@ -109,13 +109,13 @@ bintree_trace_ray
}
iaxis = btree->frame[0];
- rcp_btreesz = (float)(1.0 / btree->tree_size[iaxis]);
+ rcp_btreesz = 1.0 / (double)btree->tree_size[iaxis];
ASSERT(rcp_btreesz > 0);
/* Transform the ray origin in [0, 1] space */
- org = (float)(ray_org[iaxis] - btree->tree_low[iaxis]) * rcp_btreesz;
+ org = (ray_org[iaxis] - btree->tree_low[iaxis]) * rcp_btreesz;
/* Transform the direction in the normalized bintree space */
- dir = (float)(ray_dir[iaxis] * rcp_btreesz);
+ dir = (ray_dir[iaxis] * rcp_btreesz);
/* Define if the 1D ray direction is roughly null */
null_dir = eq_eps(ray_dir[iaxis], 0, 1.e-6);
@@ -140,11 +140,11 @@ bintree_trace_ray
* on the t parameter:
* M.X = M.O * t(M.D)
* t = (M.X-M.O)/(M.D) = (M.X-M.O)*ts; with ts = 1/(M.D) */
- ts = null_dir ? (float)INF : 1.f / dir;
+ ts = null_dir ? INF : 1.f / dir;
/* Compute the range in [0, 1] of the ray/binary tree intersection */
- pos_min = (float)MMAX(dir * ray_range[0] + org, 0);
- pos_max = (float)MMIN(dir * ray_range[1] + org, 1);
+ pos_min = MMAX(dir * ray_range[0] + org, 0);
+ pos_max = MMIN(dir * ray_range[1] + org, 1);
/* Define the first traversed child and set its lower bound */
if(pos_min <= 0.5) {
@@ -161,7 +161,7 @@ bintree_trace_ray
/* Init the traversal */
depth = 1;
istack = 0;
- scale_exp2 = 0.5;
+ scale_exp2 = 0.5f;
inode = btree->root;
/* Here we go */
@@ -176,7 +176,7 @@ bintree_trace_ray
if(is_leaf || challenge) {
struct svx_hit hit_tmp;
- const float upp = MMIN(low + scale_exp2, pos_max) ;
+ const double upp = MMIN(low + scale_exp2, pos_max) ;
const double t_min = null_dir ? ray_range[0] : (pos_min - org) * ts;
const double t_max = null_dir ? ray_range[1] : (upp - org) * ts;
const struct buffer_index iattr = buffer_get_child_attr_index
@@ -203,7 +203,7 @@ bintree_trace_ray
if(go_deeper) {
const float scale_exp2_child = scale_exp2 * 0.5f;
- const float child_mid = low + scale_exp2_child;
+ const double child_mid = low + scale_exp2_child;
/* Push parent node if necessary */
if(ichild == 0 && !null_dir) {
diff --git a/src/test_svx_bintree_trace_ray.c b/src/test_svx_bintree_trace_ray.c
@@ -302,8 +302,8 @@ main(int argc, char** argv)
CHK(RT(btree, r.org, r.dir, r.range, NULL, NULL, NULL, &hit) == RES_OK);
CHK(!SVX_HIT_NONE(&hit));
CHK(SVX_VOXEL_EQ(&hit.voxel, &hit2.voxel));
- CHK(eq_eps(hit.distance[0], (hit.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-6));
- CHK(eq_eps(hit.distance[1], (hit.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-6));
+ CHK(eq_eps(hit.distance[0], (hit.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-4));
+ CHK(eq_eps(hit.distance[1], (hit.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-4));
CHK(eq_eps(hit.voxel.upper[0], 1, 1.e-6));
CHK(eq_eps(hit.voxel.lower[0], 1-2*(1/(double)(1<<hit.voxel.depth)), 1.e-6));
CHK(hit.voxel.is_leaf);
@@ -329,8 +329,8 @@ main(int argc, char** argv)
CHK(hit.voxel.is_leaf == 1);
CHK(hit.voxel.depth == 5);
CHK(*(char*)hit.voxel.data == 1);
- CHK(eq_eps(hit.distance[0], (hit.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-6));
- CHK(eq_eps(hit.distance[1], (hit.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-6));
+ CHK(eq_eps(hit.distance[0], (hit.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-4));
+ CHK(eq_eps(hit.distance[1], (hit.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-4));
CHK(eq_eps(hit.voxel.lower[0], 0.5, 1.e-6));
CHK(eq_eps(hit.voxel.upper[0], 0.5+2.0/32.0, 1.e-6));
@@ -351,8 +351,8 @@ main(int argc, char** argv)
CHK(hit2.voxel.is_leaf == 1);
CHK(hit2.voxel.depth == 5);
CHK(*(char*)hit2.voxel.data == 1);
- CHK(eq_eps(hit2.distance[0], (hit2.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-6));
- CHK(eq_eps(hit2.distance[1], (hit2.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-6));
+ CHK(eq_eps(hit2.distance[0], (hit2.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-4));
+ CHK(eq_eps(hit2.distance[1], (hit2.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-4));
CHK(eq_eps(hit2.voxel.lower[0], 0.5-2.0/32.0, 1.e-6));
CHK(eq_eps(hit2.voxel.upper[0], 0.5, 1.e-6));
@@ -369,8 +369,8 @@ main(int argc, char** argv)
CHK(RT(btree, r.org, r.dir, r.range, NULL, hit_filter2, &hit.voxel, &hit2) == RES_OK);
CHK(!SVX_HIT_NONE(&hit2));
CHK(!SVX_VOXEL_EQ(&hit.voxel, &hit2.voxel));
- CHK(eq_eps(hit2.distance[0], (hit2.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-6));
- CHK(eq_eps(hit2.distance[1], (hit2.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-6));
+ CHK(eq_eps(hit2.distance[0], (hit2.voxel.upper[0]-r.org[0])/r.dir[0], 1.e-4));
+ CHK(eq_eps(hit2.distance[1], (hit2.voxel.lower[0]-r.org[0])/r.dir[0], 1.e-4));
CHK(eq_eps(hit2.voxel.lower[0], 0.5-2.0/32.0, 1.e-6));
CHK(eq_eps(hit2.voxel.upper[0], 0.5, 1.e-6));