star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 1d92e14eea11a637fc2661b8021acc5e3d185076
parent ae294c92192df43eb5441bc2df6bfdc3a8674f47
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 22 Jun 2021 11:53:14 +0200

Merge branch 'release_0.8'

Diffstat:
MREADME.md | 7++++++-
Mcmake/CMakeLists.txt | 8++++----
Msrc/s3d.h | 3++-
Msrc/s3d_backend.h | 2+-
Msrc/s3d_buffer.h | 2+-
Msrc/s3d_c.h | 2+-
Msrc/s3d_device.c | 2+-
Msrc/s3d_device_c.h | 2+-
Msrc/s3d_geometry.c | 2+-
Msrc/s3d_geometry.h | 2+-
Msrc/s3d_instance.c | 2+-
Msrc/s3d_instance.h | 2+-
Msrc/s3d_mesh.c | 2+-
Msrc/s3d_mesh.h | 2+-
Msrc/s3d_primitive.c | 2+-
Msrc/s3d_scene.c | 2+-
Msrc/s3d_scene_c.h | 2+-
Msrc/s3d_scene_view.c | 2+-
Msrc/s3d_scene_view_c.h | 2+-
Msrc/s3d_scene_view_closest_point.c | 30++++++++++++++++++++++--------
Msrc/s3d_scene_view_trace_ray.c | 10++++++++--
Msrc/s3d_shape.c | 2+-
Msrc/s3d_shape_c.h | 2+-
Msrc/s3d_sphere.c | 2+-
Msrc/s3d_sphere.h | 2+-
Msrc/test_s3d_accel_struct_conf.c | 2+-
Msrc/test_s3d_camera.h | 2+-
Msrc/test_s3d_cbox.h | 2+-
Msrc/test_s3d_closest_point.c | 17++++++++++++++---
Msrc/test_s3d_device.c | 2+-
Msrc/test_s3d_primitive.c | 2+-
Msrc/test_s3d_sample_sphere.c | 2+-
Msrc/test_s3d_sampler.c | 2+-
Msrc/test_s3d_scene.c | 2+-
Msrc/test_s3d_scene_view.c | 5+++--
Msrc/test_s3d_scene_view_aabb.c | 2+-
Msrc/test_s3d_seams.c | 2+-
Msrc/test_s3d_shape.c | 5+++--
Msrc/test_s3d_sphere.c | 2+-
Msrc/test_s3d_sphere_box.c | 2+-
Msrc/test_s3d_sphere_instance.c | 5++++-
Msrc/test_s3d_trace_ray.c | 26++++++++++++++++++++++----
Msrc/test_s3d_trace_ray_instance.c | 15+++++++++------
Msrc/test_s3d_trace_ray_sphere.c | 2+-
Msrc/test_s3d_utils.h | 2+-
45 files changed, 131 insertions(+), 68 deletions(-)

diff --git a/README.md b/README.md @@ -120,6 +120,11 @@ with `<STAR3D_INSTALL_DIR>` the install directory of Star-3D and ## Release notes +### Version 0.8 + +Update the API of the filtering function: add the range of the ray as input +argument. For closest point queries, this range is from 0 to query radius. + ### Version 0.7.4 - Fix the barycentric coordinates of the intersection of the ray onto the @@ -226,7 +231,7 @@ with `<STAR3D_INSTALL_DIR>` the install directory of Star-3D and ## License -Copyright (C) 2015-2020 |Méso|Star> (<contact@meso-star.com>). Star-3D is +Copyright (C) 2015-2021 |Méso|Star> (<contact@meso-star.com>). Star-3D is released under the CeCILLv2.1 license. You are welcome to redistribute it under certain conditions; refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2019 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) # # This software is a computer program whose purpose is to generate files used # to build the Star-3D library. @@ -29,7 +29,7 @@ # The fact that you are presently reading this means that you have had # knowledge of the CeCILL license and that you accept its terms. -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.1) project(star-3d C) enable_testing() @@ -57,8 +57,8 @@ endif() # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 7) -set(VERSION_PATCH 4) +set(VERSION_MINOR 8) +set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(S3D_FILES_SRC diff --git a/src/s3d.h b/src/s3d.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -214,6 +214,7 @@ typedef int (const struct s3d_hit* hit, const float org[3], const float dir[3], /* Direction from `org' to `hit' */ + const float range[2], /* Submitted range */ void* query_data, /* User data submitted on query invocation */ void* filter_data); /* Data defined on the setup of the filter function */ diff --git a/src/s3d_backend.h b/src/s3d_backend.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_buffer.h b/src/s3d_buffer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_c.h b/src/s3d_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_device.c b/src/s3d_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_device_c.h b/src/s3d_device_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_geometry.c b/src/s3d_geometry.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_geometry.h b/src/s3d_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_instance.c b/src/s3d_instance.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_instance.h b/src/s3d_instance.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_mesh.h b/src/s3d_mesh.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_primitive.c b/src/s3d_primitive.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_scene_c.h b/src/s3d_scene_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_scene_view.c b/src/s3d_scene_view.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_scene_view_c.h b/src/s3d_scene_view_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_scene_view_closest_point.c b/src/s3d_scene_view_closest_point.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -47,6 +47,7 @@ struct point_query_context { struct RTCPointQueryContext rtc; struct s3d_scene_view* scnview; + float radius; /* Submitted radius */ void* data; /* Per point query defined data */ }; @@ -167,6 +168,7 @@ closest_point_mesh (struct RTCPointQueryFunctionArguments* args, struct geometry* geom, struct geometry* inst, /* Can be NULL */ + const float radius, void* query_data) { struct s3d_hit hit = S3D_HIT_NULL; @@ -181,9 +183,9 @@ closest_point_mesh double vec[3]; double uv[2]; float dst; - float pos[3], dir[3]; + float pos[3], dir[3], range[2]; int flip_surface = 0; - ASSERT(args && geom && geom->type == GEOM_MESH); + ASSERT(args && geom && geom->type == GEOM_MESH && radius >= 0); ASSERT(args->primID < mesh_get_ntris(geom->data.mesh)); /* Fetch triangle indices */ @@ -267,14 +269,18 @@ closest_point_mesh + geom->scene_prim_id_offset + (inst ? inst->scene_prim_id_offset : 0); + range[0] = 0; + range[1] = radius; + /* `dir' is the direction along which the closest point was found. We thus * submit it to the filter function as the direction corresponding to the * computed hit */ f3_set_d3(dir, vec); f3_set_d3(pos, query_pos_ws); + filter = &geom->data.mesh->filter; if(filter->func - && filter->func(&hit, pos, dir, query_data, filter->data)) { + && filter->func(&hit, pos, dir, range, query_data, filter->data)) { return 0; /* This point is filtered. Discard it! */ } @@ -293,6 +299,7 @@ closest_point_sphere (struct RTCPointQueryFunctionArguments* args, struct geometry* geom, struct geometry* inst, + const float radius, /* User defined radius */ void* query_data) { struct s3d_hit hit = S3D_HIT_NULL; @@ -301,12 +308,13 @@ closest_point_sphere float query_pos[3]; float sphere_pos[3]; float Ng[3]; - float dir[3]; + float dir[3], range[2]; float uv[2]; float dst; float len; int flip_surface = 0; ASSERT(args && geom && geom->type == GEOM_SPHERE && args->primID == 0); + ASSERT(radius >= 0); /* Local copy of the query position */ query_pos[0] = args->query->x; @@ -377,12 +385,15 @@ closest_point_sphere + geom->scene_prim_id_offset + (inst ? inst->scene_prim_id_offset : 0); + range[0] = 0; + range[1] = radius; + /* Use the reversed geometric normal as the hit direction since it is along * this vector that the closest point was effectively computed */ f3_minus(dir, Ng); filter = &geom->data.sphere->filter; if(filter->func - && filter->func(&hit, query_pos, dir, query_data, filter->data)) { + && filter->func(&hit, query_pos, dir, range, query_data, filter->data)) { return 0; } @@ -419,10 +430,12 @@ closest_point(struct RTCPointQueryFunctionArguments* args) switch(geom->type) { case GEOM_MESH: - query_radius_is_upd = closest_point_mesh(args, geom, inst, ctx->data); + query_radius_is_upd = closest_point_mesh + (args, geom, inst, ctx->radius, ctx->data); break; case GEOM_SPHERE: - query_radius_is_upd = closest_point_sphere(args, geom, inst, ctx->data); + query_radius_is_upd = closest_point_sphere + (args, geom, inst, ctx->radius, ctx->data); break; default: FATAL("Unreachable code\n"); break; } @@ -464,6 +477,7 @@ s3d_scene_view_closest_point /* Initialise the point query context */ rtcInitPointQueryContext(&query_ctx.rtc); query_ctx.scnview = scnview; + query_ctx.radius = radius; query_ctx.data = query_data; /* Here we go! */ diff --git a/src/s3d_scene_view_trace_ray.c b/src/s3d_scene_view_trace_ray.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -48,6 +48,7 @@ struct intersect_context { void* data; /* Per ray user defined data */ float ws_org[3]; /* World space ray origin */ float ws_dir[3]; /* World space ray direction */ + float ws_range[3]; /* World space ray range */ }; /******************************************************************************* @@ -216,6 +217,8 @@ s3d_scene_view_trace_ray intersect_ctx.ws_dir[0] = dir[0]; intersect_ctx.ws_dir[1] = dir[1]; intersect_ctx.ws_dir[2] = dir[2]; + intersect_ctx.ws_range[0] = range[0]; + intersect_ctx.ws_range[1] = range[1]; intersect_ctx.scnview = scnview; intersect_ctx.data = ray_data; @@ -276,6 +279,7 @@ rtc_hit_filter_wrapper(const struct RTCFilterFunctionNArguments* args) struct intersect_context* ctx; struct geometry* geom; struct hit_filter* filter; + int is_hit_filtered = 0; ASSERT(args && args->N == 1 && args->context && args->valid[0] != 0); rtc_rayN_get_ray(args->ray, args->N, 0, &ray_hit.ray); @@ -296,7 +300,9 @@ rtc_hit_filter_wrapper(const struct RTCFilterFunctionNArguments* args) ASSERT(filter->func); hit_setup(ctx->scnview, &ray_hit, &hit); - if(filter->func(&hit, ctx->ws_org, ctx->ws_dir, ctx->data, filter->data)) { + is_hit_filtered = filter->func + (&hit, ctx->ws_org, ctx->ws_dir, ctx->ws_range, ctx->data, filter->data); + if(is_hit_filtered) { args->valid[0] = 0; } } diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_shape_c.h b/src/s3d_shape_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_sphere.c b/src/s3d_sphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/s3d_sphere.h b/src/s3d_sphere.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_accel_struct_conf.c b/src/test_s3d_accel_struct_conf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_camera.h b/src/test_s3d_camera.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_cbox.h b/src/test_s3d_cbox.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_closest_point.c b/src/test_s3d_closest_point.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -473,6 +473,7 @@ test_cbox_sphere(struct s3d_device* dev) ******************************************************************************/ struct sphere_filter_data { float query_pos[3]; + float query_radius; }; static int @@ -480,6 +481,7 @@ sphere_filter (const struct s3d_hit* hit, const float org[3], const float dir[3], + const float range[2], void* query_data, void* filter_data) { @@ -488,7 +490,7 @@ sphere_filter float pos[3]; float vec[3]; - CHK(hit && org && dir && !S3D_HIT_NONE(hit)); + CHK(hit && org && dir && range && !S3D_HIT_NONE(hit)); CHK((intptr_t)filter_data == (intptr_t)0xDECAFBAD); CHK(f3_normalize(vec, dir) != 0); @@ -498,6 +500,8 @@ sphere_filter CHK(f3_eq_eps(attr.value, pos, POSITION_EPSILON)); CHK(f3_eq_eps(data->query_pos, org, POSITION_EPSILON)); + CHK(range[0] == 0); + CHK(range[1] == data->query_radius); return 1; } @@ -588,6 +592,7 @@ test_sphere(struct s3d_device* dev) f3_splat(query_pos, 10); f3_set(filter_data.query_pos, query_pos); + filter_data.query_radius = (float)INF; CHK(s3d_scene_view_closest_point (scnview, query_pos, (float)INF, &filter_data, &hit) == RES_OK); CHK(!S3D_HIT_NONE(&hit)); @@ -615,6 +620,7 @@ enum cbox_geom { struct cbox_filter_data { float query_pos[3]; + float query_radius; unsigned geom_to_filter[3]; }; @@ -623,6 +629,7 @@ cbox_filter (const struct s3d_hit* hit, const float org[3], const float dir[3], + const float range[2], void* query_data, void* filter_data) { @@ -631,7 +638,7 @@ cbox_filter float pos[3]; float vec[3]; - CHK(hit && org && dir && !S3D_HIT_NONE(hit)); + CHK(hit && org && dir && range && !S3D_HIT_NONE(hit)); CHK((intptr_t)filter_data == (intptr_t)0xDECAFBAD); CHK(f3_normalize(vec, dir) != 0); @@ -643,6 +650,8 @@ cbox_filter if(!query_data) return 0; CHK(f3_eq_eps(data->query_pos, org, POSITION_EPSILON)); + CHK(range[0] == 0); + CHK(range[1] == data->query_radius); return data->geom_to_filter[0] == hit->prim.geom_id || data->geom_to_filter[1] == hit->prim.geom_id @@ -762,6 +771,7 @@ test_cbox(struct s3d_device* dev) pos[1] = (ucast.ui = 0x43e635b8, ucast.f); pos[2] = (ucast.ui = 0x4319ab78, ucast.f); f3_set(filter_data.query_pos, pos); + filter_data.query_radius = (float)INF; CHK(s3d_scene_view_closest_point (scnview, pos, (float)INF, &filter_data, &hit) == RES_OK); check_closest_point_cbox(pos, geom_id, &hit); @@ -795,6 +805,7 @@ test_cbox(struct s3d_device* dev) pos[2] = mid[2] + (rand_canonic() * 2 - 1) * (upp[2] - low[2]); f3_set(filter_data.query_pos, pos); + filter_data.query_radius = (float)INF; CHK(s3d_scene_view_closest_point (scnview, pos, (float)INF, &filter_data, &hit) == RES_OK); diff --git a/src/test_s3d_device.c b/src/test_s3d_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_primitive.c b/src/test_s3d_primitive.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_sample_sphere.c b/src/test_s3d_sample_sphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_sampler.c b/src/test_s3d_sampler.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_scene_view.c b/src/test_s3d_scene_view.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -48,10 +48,11 @@ filter (const struct s3d_hit* hit, const float org[3], const float dir[3], + const float range[2], void* ray_data, void* filter_data) { - (void)org, (void)dir, (void)ray_data, (void)filter_data; + (void)org, (void)dir, (void)range, (void)ray_data, (void)filter_data; CHK(S3D_HIT_NONE(hit) == 0); return hit->prim.prim_id % 2 == 0; } diff --git a/src/test_s3d_scene_view_aabb.c b/src/test_s3d_scene_view_aabb.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_seams.c b/src/test_s3d_seams.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -42,10 +42,11 @@ filter_none (const struct s3d_hit* hit, const float org[3], const float dir[3], + const float range[2], void* ray_data, void* filter_data) { - (void)hit, (void)org, (void)dir, (void)ray_data, (void)filter_data; + (void)hit, (void)org, (void)dir, (void)range, (void)ray_data, (void)filter_data; return 0; } diff --git a/src/test_s3d_sphere.c b/src/test_s3d_sphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_sphere_box.c b/src/test_s3d_sphere_box.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_sphere_instance.c b/src/test_s3d_sphere_instance.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -45,12 +45,15 @@ filter_front_face (const struct s3d_hit* hit, const float pos[3], const float dir[3], + const float range[2], void* ray_data, void* filter_data) { CHK(hit != NULL); CHK(pos != NULL); CHK(dir != NULL); + CHK(range != NULL); + CHK(range[0] < range[1]); CHK(filter_data == NULL); CHK(ray_data == NULL); CHK(S3D_HIT_NONE(hit) == 0); diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -35,28 +35,41 @@ #include "test_s3d_cbox.h" #include "test_s3d_utils.h" -#include <rsys/image.h> +#include <rsys/float2.h> #include <rsys/float3.h> +#include <rsys/image.h> #include <string.h> #define IMG_WIDTH 640 #define IMG_HEIGHT 480 +struct ray_data { + float ray_org[3]; + float ray_dir[3]; + float ray_range[2]; +}; + static int filter_func (const struct s3d_hit* hit, const float pos[3], const float dir[3], + const float range[2], void* ray_data, void* filter_data) { + struct ray_data* data = ray_data; CHK(hit != NULL); CHK(pos != NULL); CHK(dir != NULL); - CHK((uintptr_t)ray_data == 0xDEADBEEF); + CHK(range != NULL); + CHK(ray_data != NULL); CHK((uintptr_t)filter_data == 0xDECAFBAD); CHK(S3D_HIT_NONE(hit) == 0); + CHK(f3_eq(pos, data->ray_org)); + CHK(f3_eq(dir, data->ray_dir)); + CHK(f2_eq(range, data->ray_range)); return hit->prim.prim_id % 2 == 0; } @@ -309,12 +322,17 @@ main(int argc, char** argv) pixel[1] = (float)iy/(float)IMG_HEIGHT; FOR_EACH(ix, 0, IMG_WIDTH) { + struct ray_data ray_data; const size_t ipix = (iy*IMG_WIDTH + ix) * 3/*RGB*/; pixel[0] = (float)ix/(float)IMG_WIDTH; camera_ray(&cam, pixel, org, dir); + + f3_set(ray_data.ray_org, org); + f3_set(ray_data.ray_dir, dir); + f2_set(ray_data.ray_range, range); CHK(s3d_scene_view_trace_ray - (scnview, org, dir, range, (void*)(uintptr_t)0xDEADBEEF, &hit) == RES_OK); + (scnview, org, dir, range, &ray_data, &hit) == RES_OK); if(S3D_HIT_NONE(&hit)) { ((uint8_t*)img.pixels)[ipix+0] = 0; diff --git a/src/test_s3d_trace_ray_instance.c b/src/test_s3d_trace_ray_instance.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly @@ -56,11 +56,13 @@ struct ray { }; static int -filter(const struct s3d_hit* hit, - const float ray_org[3], - const float ray_dir[3], - void* ray_data, - void* filter_data) +filter + (const struct s3d_hit* hit, + const float ray_org[3], + const float ray_dir[3], + const float ray_range[2], + void* ray_data, + void* filter_data) { struct ray* ray = ray_data; @@ -68,6 +70,7 @@ filter(const struct s3d_hit* hit, CHK(ray_org != NULL); CHK(ray_dir != NULL); CHK(ray_data != NULL); + CHK(ray_range != NULL); CHK(filter_data == NULL); CHK(f3_eq(ray_org, ray->org) == 1); CHK(f3_eq(ray_dir, ray->dir) == 1); diff --git a/src/test_s3d_trace_ray_sphere.c b/src/test_s3d_trace_ray_sphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly diff --git a/src/test_s3d_utils.h b/src/test_s3d_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a computer program whose purpose is to describe a * virtual 3D environment that can be ray-traced and sampled both robustly