commit 9f9fbb4701831286f478e27af8c60541eaadabd6
parent 7b25850885890e45e21b83f3c031acdd9fd6481a
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 14 Oct 2016 12:08:08 +0200
Add a new test on missing intersection on triangle edges.
The test trace a specific ray that was wrongly non-intersecting some
geometry using Embree 2.9. Using Embree 2.11 the intersection is found.
The test is aimed at detection a possible future regression Embree side.
Diffstat:
2 files changed, 193 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -111,6 +111,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
COMPILE_FLAGS "-Wno-variadic-macros -Wno-long-long")
endif()
+if(MSVC)
+ set_target_properties(s3d PROPERTIES LINK_FLAGS /DEBUG)
+endif()
+
rcmake_setup_devel(s3d Star3D ${VERSION} star/s3d_version.h)
################################################################################
@@ -145,6 +149,8 @@ if(NOT NO_TEST)
new_test(test_s3d_scene_view)
new_test(test_s3d_shape)
new_test(test_s3d_trace_ray_instance)
+ new_test(test_s3d_seams)
+
build_test(test_s3d_trace_ray)
register_test(test_s3d_trace_ray_legacy test_s3d_trace_ray)
diff --git a/src/test_s3d_seams.c b/src/test_s3d_seams.c
@@ -0,0 +1,187 @@
+/* Copyright (C) |Meso|Star> 2015-2016 (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
+* and efficiently.
+*
+* This software is governed by the CeCILL license under French law and
+* abiding by the rules of distribution of free software. You can use,
+* modify and/or redistribute the software under the terms of the CeCILL
+* license as circulated by CEA, CNRS and INRIA at the following URL
+* "http://www.cecill.info".
+*
+* As a counterpart to the access to the source code and rights to copy,
+* modify and redistribute granted by the license, users are provided only
+* with a limited warranty and the software's author, the holder of the
+* economic rights, and the successive licensors have only limited
+* liability.
+*
+* In this respect, the user's attention is drawn to the risks associated
+* with loading, using, modifying and/or developing or reproducing the
+* software by the user in light of its specific status of free software,
+* that may mean that it is complicated to manipulate, and that also
+* therefore means that it is reserved for developers and experienced
+* professionals having in-depth computer knowledge. Users are therefore
+* encouraged to load and test the software's suitability as regards their
+* requirements in conditions enabling the security of their systems and/or
+* data to be ensured and, more generally, to use and operate it in the
+* same conditions as regards security.
+*
+* The fact that you are presently reading this means that you have had
+* knowledge of the CeCILL license and that you accept its terms. */
+
+#include "s3d.h"
+#include "test_s3d_utils.h"
+
+#include <rsys/mem_allocator.h>
+#include <rsys/float33.h>
+#include <rsys/double33.h>
+
+struct desc {
+ const float* vertices;
+ const unsigned* indices;
+};
+
+/*******************************************************************************
+* Callbacks
+******************************************************************************/
+static INLINE void
+get_ids(const unsigned itri, unsigned ids[3], void* data)
+{
+ const unsigned id = itri * 3;
+ struct desc* desc = data;
+ NCHECK(desc, NULL);
+ NCHECK(ids, NULL);
+ ids[0] = desc->indices[id + 0];
+ ids[1] = desc->indices[id + 1];
+ ids[2] = desc->indices[id + 2];
+}
+
+static INLINE void
+get_position(const unsigned ivert, float position[3], void* data)
+{
+ struct desc* desc = data;
+ NCHECK(desc, NULL);
+ NCHECK(position, NULL);
+ position[0] = desc->vertices[ivert * 3 + 0];
+ position[1] = desc->vertices[ivert * 3 + 1];
+ position[2] = desc->vertices[ivert * 3 + 2];
+}
+
+static INLINE void
+get_normal(const unsigned ivert, float normal[3], void* data)
+{
+ (void) ivert, (void) data;
+ NCHECK(normal, NULL);
+ normal[0] = 1.f;
+ normal[1] = 0.f;
+ normal[2] = 0.f;
+}
+
+static INLINE void
+get_uv(const unsigned ivert, float uv[2], void* data)
+{
+ (void) ivert, (void) data;
+ NCHECK(uv, NULL);
+ uv[0] = -1.f;
+ uv[1] = 1.f;
+}
+
+static INLINE void
+get_polygon_vertices(const size_t ivert, double position[2], void* ctx)
+{
+ const double* verts = ctx;
+ NCHECK(position, NULL);
+ NCHECK(ctx, NULL);
+ position[0] = verts[ivert * 2 + 0];
+ position[1] = verts[ivert * 2 + 1];
+}
+
+static const float SQUARE_EDGES__ [] = {
+ -0.1f, -0.1f, 0.f,
+ 0.1f, -0.1f, 0.f,
+ 0.1f, 0.1f, 0.f,
+ -0.1f, 0.1f, 0.f
+};
+static const unsigned SQUARE_NVERTS__ = sizeof(SQUARE_EDGES__) / sizeof(float[3]);
+static const unsigned SQUARE_TRG_IDS__ [] = { 0, 2, 1, 2, 0, 3 };
+static const unsigned SQUARE_NTRIS__ = sizeof(SQUARE_TRG_IDS__) / sizeof(unsigned[3]);
+static const struct desc SQUARE_DESC__ = { SQUARE_EDGES__, SQUARE_TRG_IDS__ };
+
+static int
+check_ray(int use_double) {
+ struct mem_allocator allocator;
+ struct s3d_device* dev;
+ struct s3d_hit hit;
+ struct s3d_scene* scn;
+ struct s3d_scene* scn2;
+ struct s3d_scene_view* scnview;
+ struct s3d_shape* square;
+ struct s3d_shape* inst;
+ struct s3d_vertex_data attribs;
+ float _transform[12];
+ double transform[12];
+ float range[2] = { 0.f, FLT_MAX };
+ float org[3] = { 3.3492994308471680f, -9.7470426559448242f, 2.6555661803570274f };
+ float dir[3] = { -0.26465030351986046f, 0.77017831656345948f, 0.58033229924097962f };
+ float pos[3];
+
+ if (use_double) {
+ d33_rotation_pitch(transform, PI);
+ f33_set_d33(_transform, transform);
+ }
+ else {
+ f33_rotation_pitch(_transform, (float)PI);
+ }
+ f3_splat(_transform + 9, 0);
+ _transform[11] = 10;
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(s3d_device_create(NULL, &allocator, 1, &dev), RES_OK);
+ CHECK(s3d_scene_create(dev, &scn), RES_OK);
+ CHECK(s3d_scene_create(dev, &scn2), RES_OK);
+
+ attribs.usage = S3D_POSITION;
+ attribs.type = S3D_FLOAT3;
+ attribs.get = get_position;
+
+ CHECK(s3d_shape_create_mesh(dev, &square), RES_OK);
+ CHECK(s3d_mesh_setup_indexed_vertices(square, SQUARE_NTRIS__, get_ids,
+ SQUARE_NVERTS__, &attribs, 1, (void*) &SQUARE_DESC__), RES_OK);
+ CHECK(s3d_scene_attach_shape(scn, square), RES_OK);
+ s3d_scene_instantiate(scn, &inst);
+ CHECK(s3d_instance_set_transform(inst, _transform), RES_OK);
+ CHECK(s3d_scene_attach_shape(scn2, inst), RES_OK);
+
+ CHECK(s3d_scene_view_create(scn2, S3D_TRACE, &scnview), RES_OK);
+ CHECK(s3d_scene_view_trace_ray(scnview, org, dir, range, NULL, &hit), RES_OK);
+ printf("\nRaytrace using %s: ", use_double ? "double" : "float");
+ if (!S3D_HIT_NONE(&hit)) {
+ f3_add(pos, org, f3_mulf(pos, dir, hit.distance));
+ printf("Hit at [%g %g %g]\n",SPLIT3(pos));
+ }
+ else {
+ printf("No hit\n");
+ }
+ CHECK(s3d_scene_view_ref_put(scnview), RES_OK);
+ CHECK(s3d_scene_ref_put(scn), RES_OK);
+ CHECK(s3d_scene_ref_put(scn2), RES_OK);
+ CHECK(s3d_device_ref_put(dev), RES_OK);
+ CHECK(s3d_shape_ref_put(square), RES_OK);
+ CHECK(s3d_shape_ref_put(inst), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+
+ return S3D_HIT_NONE(&hit) ? RES_UNKNOWN_ERR : RES_OK;
+}
+
+int main() {
+ check_ray(1);
+ check_ray(0);
+
+ return 0;
+}
+