Skip to content

Commit 8f7032c

Browse files
committed
fix bugs and reclaim performance
1 parent a153620 commit 8f7032c

File tree

13 files changed

+146
-162
lines changed

13 files changed

+146
-162
lines changed

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ GeometryBasics = "0.4"
2323
ImageCore = "0.10"
2424
ImageIO = "0.6"
2525
ProgressMeter = "1.10"
26-
Random = "1.11.0"
2726
RandomNumbers = "1.6.0"
2827
StaticArrays = "1.9.7"
2928
StructArrays = "0.6.18"

docs/code/caustic_glass.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ for t in floor_triangles
4545
push!(primitives, Trace.GeometricPrimitive(t, plastic))
4646
end
4747

48-
bvh = Trace.BVHAccel(primitives, 1);
48+
bvh = Trace.BVHAccel(map(identity, primitives), 1);
4949

5050
from, to = Point3f(0, 2, 0), Point3f(-5, 0, 5)
5151
cone_angle, cone_δ_angle = 30f0, 10f0
@@ -73,14 +73,14 @@ lights = [
7373

7474
scene = Trace.Scene(lights, bvh)
7575

76-
resolution = Point2f(1024)
7776
n_samples = 8
7877
ray_depth = 5
7978

8079
look_point = Point3f(-3, 0, -91)
8180
screen = Trace.Bounds2(Point2f(-1f0), Point2f(1f0))
8281
filter = Trace.LanczosSincFilter(Point2f(1f0), 3f0)
8382

83+
resolution = Point2f(1024)
8484
ir = Int64.(resolution)
8585
film = Trace.Film(
8686
resolution, Trace.Bounds2(Point2f(0), Point2f(1)),
@@ -92,5 +92,6 @@ camera = Trace.PerspectiveCamera(
9292
screen, 0f0, 1f0, 0f0, 1f6, 90f0, film,
9393
)
9494

95-
integrator = Trace.SPPMIntegrator(camera, 0.075f0, ray_depth, 10)
96-
integrator(scene)
95+
integrator = Trace.SPPMIntegrator(camera, 0.075f0, ray_depth, 1)
96+
@profview_allocs integrator(scene)
97+
@time integrator(scene)

src/accel/bvh.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,18 @@ function intersect!(bvh::BVHAccel{P}, ray::AbstractRay)::Tuple{Bool,P,SurfaceInt
225225
nodes_to_visit[i] = Int32(0)
226226
end
227227
primitive::P = first(bvh.primitives)
228+
primitives = bvh.primitives::Vector{P}
228229
@inbounds while true
229230
ln = bvh.nodes[current_node_i]
230231
if intersect_p(ln.bounds, ray, inv_dir, dir_is_neg)
231232
if ln isa LinearBVHLeaf && ln.n_primitives > 0
232233
# Intersect ray with primitives in node.
233234
for i in 0:ln.n_primitives-1
234-
tmp_primitive = bvh.primitives[ln.primitives_offset+i]
235+
tmp_primitive::P = primitives[ln.primitives_offset+i]
235236
tmp_hit, ray, tmp_interaction = intersect_p!(
236237
tmp_primitive, ray,
237238
)
238-
if tmp_hit && !(tmp_interaction isa Vec3)
239+
if tmp_hit
239240
hit = tmp_hit
240241
interaction = tmp_interaction
241242
primitive = tmp_primitive

src/bounds.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ end
181181
"""
182182
dir_is_negative: 1 -- false, 2 -- true
183183
"""
184-
function intersect_p(
184+
@inline function intersect_p(
185185
b::Bounds3, ray::AbstractRay,
186186
inv_dir::Vec3f, dir_is_negative::Point3{UInt8},
187187
)::Bool

src/camera/perspective.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,5 @@ end
108108
)
109109
# TODO add medium
110110
ray = apply(camera.core.core.camera_to_world, ray)
111-
Ray(ray, d=normalize(ray.d))
112-
ray, 1f0
111+
return Ray(ray, d=normalize(ray.d), time=time), 1.0f0
113112
end

src/film.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function FilmTile(
108108
bounds::Bounds2, filter_radius::Point2f,
109109
filter_table_width::Int32,
110110
)
111+
# Include some padding for over rounding (since we re-use the tiles)
111112
tile_res = (Int32.(inclusive_sides(bounds))) .+ 2
112113
contrib_sum = fill(RGBSpectrum(), tile_res[2], tile_res[1])
113114
filter_weight_sum = fill(0.0f0, tile_res[2], tile_res[1])

src/integrators/sampler.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct WhittedIntegrator{C<: Camera, S <: AbstractSampler} <: SamplerIntegrator
66
max_depth::Int64
77
end
88

9-
@noinline function sample_kernel_inner(i, scene, t_sampler, film, film_tile, camera, pixel, spp_sqr)
9+
function sample_kernel_inner(i::A, scene::B, t_sampler::C, film::D, film_tile::E, camera::F, pixel::G, spp_sqr::H) where {A, B, C, D, E, F, G, H}
1010
while has_next_sample(t_sampler)
1111
camera_sample = get_camera_sample(t_sampler, pixel)
1212
ray, ω = generate_ray_differential(camera, camera_sample)
@@ -57,7 +57,7 @@ function (i::SamplerIntegrator)(scene::Scene)
5757
_tb_max = min.(_tb_min .+ (tile_size - 1), sample_bounds.p_max)
5858
_tile_bounds = Bounds2(_tb_min, _tb_max)
5959
filmtiles = [FilmTile(film, _tile_bounds, filter_radius) for _ in 1:Threads.maxthreadid()]
60-
Threads.@threads for k in 0:total_tiles
60+
Threads.@threads :greedy for k in 0:total_tiles
6161
x, y = k % width, k ÷ width
6262
tile = Point2f(x, y)
6363
tb_min = sample_bounds.p_min .+ tile .* tile_size

0 commit comments

Comments
 (0)