-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from Jack-Grogan/main
Implementation of raytracing in ImplicitBHV.jl
- Loading branch information
Showing
18 changed files
with
1,306 additions
and
415 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,76 @@ | ||
# File : bvh_build.jl | ||
# License: MIT | ||
# Author : Andrei Leonard Nicusan <[email protected]> | ||
# Date : 15.12.2022 | ||
|
||
|
||
using ImplicitBVH | ||
using ImplicitBVH: BSphere, BBox | ||
|
||
using Random | ||
Random.seed!(42) | ||
|
||
using MeshIO | ||
using FileIO | ||
|
||
using BenchmarkTools | ||
using Profile | ||
using PProf | ||
|
||
|
||
# Types used | ||
const LeafType = BBox{Float32} | ||
|
||
|
||
|
||
num_bvs = 1_000_000 | ||
|
||
bvs = [LeafType(rand(3, 3)) for _ in 1:num_bvs] | ||
points = rand(Float32, 3, num_bvs) | ||
directions = rand(Float32, 3, num_bvs) | ||
|
||
|
||
# Example usage | ||
function check_intersections!(intersections, bvs, points, directions) | ||
@inbounds for i in eachindex(intersections) | ||
intersections[i] = isintersection(bvs[i], @view(points[:, i]), @view(directions[:, i])) | ||
end | ||
nothing | ||
end | ||
|
||
intersections = Vector{Bool}(undef, length(bvs)) | ||
check_intersections!(intersections, bvs, points, directions) | ||
|
||
|
||
println("Benchmarking $(length(bvs)) intersections:") | ||
display(@benchmark check_intersections!(intersections, bvs, points, directions)) | ||
|
||
|
||
# # Collect a pprof profile of the complete build | ||
# Profile.clear() | ||
# @profile begin | ||
# for _ in 1:1000 | ||
# check_intersections!(intersections, bvs, points, directions) | ||
# end | ||
# end | ||
# | ||
# | ||
# # Export pprof profile and open interactive profiling web interface. | ||
# pprof(; out="bvh_rays.pb.gz") | ||
|
||
|
||
# Test for some coding mistakes | ||
using Test | ||
Test.detect_unbound_args(ImplicitBVH, recursive = true) | ||
Test.detect_ambiguities(ImplicitBVH, recursive = true) | ||
|
||
|
||
# More complete report on type stabilities | ||
using JET | ||
JET.@report_opt check_intersections!(intersections, bvs, points, directions) | ||
|
||
|
||
# using Profile | ||
# BVH(bounding_spheres, NodeType, MortonType) | ||
# Profile.clear_malloc_data() | ||
# BVH(bounding_spheres, NodeType, MortonType) |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ ImplicitBVH.BSphere | |
|
||
```@docs | ||
ImplicitBVH.iscontact | ||
ImplicitBVH.isintersection | ||
ImplicitBVH.center | ||
``` | ||
|
||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
```@docs | ||
BVH | ||
traverse | ||
traverse_rays | ||
BVHTraversal | ||
default_start_level | ||
ImplicitBVH.IndexPair | ||
|
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,46 @@ | ||
|
||
using Random | ||
|
||
using BenchmarkTools | ||
|
||
using ImplicitBVH | ||
using ImplicitBVH: BSphere, BBox | ||
|
||
using Profile | ||
using PProf | ||
|
||
|
||
Random.seed!(0) | ||
|
||
num_bvs = 100_000 | ||
bvs = map(BSphere{Float32}, [6 * rand(3) .+ rand(3, 3) for _ in 1:num_bvs]) | ||
|
||
options = BVHOptions(block_size=128, num_threads=8) | ||
bvh = BVH(bvs, BBox{Float32}, UInt32, 1, options=options) | ||
|
||
|
||
num_rays = 100_000 | ||
points = 100 * rand(3, num_rays) .+ rand(Float32, 3, num_rays) | ||
directions = rand(Float32, 3, num_rays) | ||
|
||
|
||
bvtt1, bvtt2, num_bvtt = ImplicitBVH.initial_bvtt( | ||
bvh, | ||
points, | ||
directions, | ||
2, | ||
nothing, | ||
options, | ||
) | ||
|
||
bvt = traverse_rays(bvh, points, directions) | ||
|
||
for (ibv, iray) in bvt.contacts | ||
@assert ImplicitBVH.isintersection(bvs[ibv], points[:, iray], directions[:, iray]) | ||
end | ||
|
||
|
||
# TODO add example to README | ||
# TODO maybe a pretty image / render? | ||
# TODO benchmark against a standard raytracer? Check Chitalu's paper; the Stanford bunny example | ||
|
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
Oops, something went wrong.