-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from romainaugier/main
Found a bug in BVH8_CPU CombineLeafs when number of triangles in BLAS…
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Minimal example for tiny_bvh.h | ||
|
||
#define TINYBVH_IMPLEMENTATION | ||
#include "tiny_bvh.h" | ||
|
||
#include <cstdlib> | ||
#include <cstdio> | ||
|
||
#define TRIANGLE_COUNT 3 | ||
|
||
tinybvh::bvhvec4 triangles[TRIANGLE_COUNT * 3]; // must be 16 byte! | ||
|
||
float uniform_rand() { return (float)rand() / (float)RAND_MAX; } | ||
|
||
int main() | ||
{ | ||
// create a scene consisting of some random small triangles | ||
for (int i = 0; i < TRIANGLE_COUNT; i++) | ||
{ | ||
// create a random triangle | ||
tinybvh::bvhvec4& v0 = triangles[i * 3 + 0]; | ||
tinybvh::bvhvec4& v1 = triangles[i * 3 + 1]; | ||
tinybvh::bvhvec4& v2 = triangles[i * 3 + 2]; | ||
// triangle position, x/y/z = 0..1 | ||
float x = uniform_rand(); | ||
float y = uniform_rand(); | ||
float z = uniform_rand(); | ||
// set first vertex | ||
v0.x = x + 0.1f * uniform_rand(); | ||
v0.y = y + 0.1f * uniform_rand(); | ||
v0.z = z + 0.1f * uniform_rand(); | ||
// set second vertex | ||
v1.x = x + 0.1f * uniform_rand(); | ||
v1.y = y + 0.1f * uniform_rand(); | ||
v1.z = z + 0.1f * uniform_rand(); | ||
// set third vertex | ||
v2.x = x + 0.1f * uniform_rand(); | ||
v2.y = y + 0.1f * uniform_rand(); | ||
v2.z = z + 0.1f * uniform_rand(); | ||
} | ||
|
||
tinybvh::bvhvec3 O( 0.5f, 0.5f, -1 ); | ||
tinybvh::bvhvec3 D( 0.1f, 0, 2 ); | ||
tinybvh::Ray ray( O, D ); | ||
|
||
// build a BVH over the scene | ||
tinybvh::BVH8_CPU bvh; | ||
bvh.Build( triangles, TRIANGLE_COUNT ); | ||
|
||
// from here: play with the BVH! | ||
int steps = bvh.Intersect( ray ); | ||
printf( "std: nearest intersection: %f (found in %i traversal steps).\n", ray.hit.t, steps ); | ||
|
||
// all done. | ||
return 0; | ||
} |