@@ -6,15 +6,14 @@ struct WhittedIntegrator{C<: Camera, S <: AbstractSampler} <: SamplerIntegrator
6
6
max_depth:: Int64
7
7
end
8
8
9
- @noinline function sample_kernel_inner (pool, i, scene, t_sampler, film, film_tile, camera, pixel, spp_sqr)
9
+ @noinline function sample_kernel_inner (i, scene, t_sampler, film, film_tile, camera, pixel, spp_sqr)
10
10
while has_next_sample (t_sampler)
11
- free_all (pool) # clear memory pool
12
11
camera_sample = get_camera_sample (t_sampler, pixel)
13
- ray, ω = generate_ray_differential (pool, camera, camera_sample)
14
- scale_differentials! (ray, spp_sqr)
12
+ ray, ω = generate_ray_differential (camera, camera_sample)
13
+ ray = scale_differentials (ray, spp_sqr)
15
14
l = RGBSpectrum (0f0 )
16
15
if ω > 0.0f0
17
- l = li (pool, i, ray, scene, 1 )
16
+ l = li (i, ray, scene, 1 )
18
17
end
19
18
# TODO check l for invalid values
20
19
if isnan (l)
25
24
end
26
25
end
27
26
28
- @noinline function sample_kernel (mempools, i, camera, scene, film, film_tile, tile_bounds)
29
-
30
- pool = mempools[Threads. threadid ()]
27
+ @noinline function sample_kernel (i, camera, scene, film, film_tile, tile_bounds)
31
28
t_sampler = deepcopy (i. sampler)
32
29
spp_sqr = 1f0 / √ Float32 (t_sampler. samples_per_pixel)
33
30
for pixel in tile_bounds
34
31
start_pixel! (t_sampler, pixel)
35
- sample_kernel_inner (pool, i, scene, t_sampler, film, film_tile, camera, pixel, spp_sqr)
32
+ sample_kernel_inner (i, scene, t_sampler, film, film_tile, camera, pixel, spp_sqr)
36
33
end
37
34
merge_film_tile! (film, film_tile)
38
35
end
@@ -51,7 +48,6 @@ function (i::SamplerIntegrator)(scene::Scene)
51
48
total_tiles = width * height - 1
52
49
bar = Progress (total_tiles, 1 )
53
50
@info " Utilizing $(Threads. nthreads ()) threads"
54
- mempools = [MemoryPool (round (Int, 3 * 16384 )) for _ in 1 : Threads. maxthreadid ()]
55
51
film = get_film (i. camera)
56
52
camera = i. camera
57
53
filter_radius = film. filter. radius
@@ -70,20 +66,20 @@ function (i::SamplerIntegrator)(scene::Scene)
70
66
tile_bounds = Bounds2 (tb_min, tb_max)
71
67
film_tile = filmtiles[Threads. threadid ()]
72
68
film_tile = update_bounds! (film, film_tile, tile_bounds)
73
- sample_kernel (mempools, i, camera, scene, film, film_tile, tile_bounds)
69
+ sample_kernel (i, camera, scene, film, film_tile, tile_bounds)
74
70
end
75
71
next! (bar)
76
72
end
77
73
save (film)
78
74
end
79
75
80
76
function li (
81
- pool, i:: WhittedIntegrator , ray:: RayDifferentials , scene:: Scene , depth:: Int64 ,
77
+ i:: WhittedIntegrator , ray:: RayDifferentials , scene:: Scene , depth:: Int64 ,
82
78
):: RGBSpectrum
83
79
84
80
l = RGBSpectrum (0f0 )
85
81
# Find closest ray intersection or return background radiance.
86
- hit, primitive, si = intersect! (pool, scene, ray)
82
+ hit, primitive, si = intersect! (scene, ray)
87
83
if ! hit
88
84
for light in scene. lights
89
85
l += le (light, ray)
@@ -96,10 +92,10 @@ function li(
96
92
n = si. shading. n
97
93
wo = core. wo
98
94
# Compute scattering functions for surface interaction.
99
- si, bsdf = compute_scattering! (pool, primitive, si, ray)
95
+ si, bsdf = compute_scattering! (primitive, si, ray)
100
96
if bsdf. bxdfs. last == 0
101
97
return li (
102
- pool, spawn_ray (pool, si, ray. d),
98
+ spawn_ray (si, ray. d),
103
99
scene, i. sampler, depth,
104
100
)
105
101
end
@@ -108,7 +104,7 @@ function li(
108
104
# Add contribution of each light source.
109
105
for light in scene. lights
110
106
sampled_li, wi, pdf, visibility_tester = sample_li (
111
- pool, light, core, get_2d (i. sampler),
107
+ light, core, get_2d (i. sampler),
112
108
)
113
109
(is_black (sampled_li) || pdf ≈ 0f0 ) && continue
114
110
f = bsdf (wo, wi)
@@ -118,14 +114,14 @@ function li(
118
114
end
119
115
if depth + 1 ≤ i. max_depth
120
116
# Trace rays for specular reflection & refraction.
121
- l += specular_reflect (pool, bsdf, i, ray, si, scene, depth)
122
- l += specular_transmit (pool, bsdf, i, ray, si, scene, depth)
117
+ l += specular_reflect (bsdf, i, ray, si, scene, depth)
118
+ l += specular_transmit (bsdf, i, ray, si, scene, depth)
123
119
end
124
120
l
125
121
end
126
122
127
123
function specular_reflect (
128
- pool, bsdf, i:: I , ray:: RayDifferentials ,
124
+ bsdf, i:: I , ray:: RayDifferentials ,
129
125
surface_intersect:: SurfaceInteraction , scene:: Scene , depth:: Int64 ,
130
126
) where I<: SamplerIntegrator
131
127
@@ -142,11 +138,10 @@ function specular_reflect(
142
138
return RGBSpectrum (0f0 )
143
139
end
144
140
# Compute ray differential for specular reflection.
145
- rd = allocate (pool, RayDifferentials, spawn_ray (pool, surface_intersect, wi))
141
+ rd = RayDifferentials ( spawn_ray (surface_intersect, wi))
146
142
if ray. has_differentials
147
- rd. has_differentials = true
148
- rd. rx_origin = surface_intersect. core. p + surface_intersect.∂p∂x
149
- rd. ry_origin = surface_intersect. core. p + surface_intersect.∂p∂y
143
+ rx_origin = surface_intersect. core. p + surface_intersect.∂p∂x
144
+ ry_origin = surface_intersect. core. p + surface_intersect.∂p∂y
150
145
# Compute differential reflected directions.
151
146
∂n∂x = (
152
147
surface_intersect. shading.∂n∂u * surface_intersect.∂u∂x
@@ -162,14 +157,15 @@ function specular_reflect(
162
157
∂wo∂y = - ray. ry_direction - wo
163
158
∂dn∂x = ∂wo∂x ⋅ ns + wo ⋅ ∂n∂x
164
159
∂dn∂y = ∂wo∂y ⋅ ns + wo ⋅ ∂n∂y
165
- rd. rx_direction = wi - ∂wo∂x + 2f0 * (wo ⋅ ns) * ∂n∂x + ∂dn∂x * ns
166
- rd. ry_direction = wi - ∂wo∂y + 2f0 * (wo ⋅ ns) * ∂n∂y + ∂dn∂y * ns
160
+ rx_direction = wi - ∂wo∂x + 2f0 * (wo ⋅ ns) * ∂n∂x + ∂dn∂x * ns
161
+ ry_direction = wi - ∂wo∂y + 2f0 * (wo ⋅ ns) * ∂n∂y + ∂dn∂y * ns
162
+ rd = RayDifferentials (rd, rx_origin= rx_origin, ry_origin= ry_origin, rx_direction= rx_direction, ry_direction= ry_direction)
167
163
end
168
- return f * li (pool, i, rd, scene, depth + 1 ) * abs (wi ⋅ ns) / pdf
164
+ return f * li (i, rd, scene, depth + 1 ) * abs (wi ⋅ ns) / pdf
169
165
end
170
166
171
167
function specular_transmit (
172
- pool, bsdf, i:: S , ray:: RayDifferentials ,
168
+ bsdf, i:: S , ray:: RayDifferentials ,
173
169
surface_intersect:: SurfaceInteraction , scene:: Scene , depth:: Int64 ,
174
170
) where S<: SamplerIntegrator
175
171
@@ -185,11 +181,10 @@ function specular_transmit(
185
181
return RGBSpectrum (0f0 )
186
182
end
187
183
# TODO shift in ray direction instead of normal?
188
- rd = allocate (pool, RayDifferentials, spawn_ray (pool, surface_intersect, wi))
184
+ rd = RayDifferentials ( spawn_ray (surface_intersect, wi))
189
185
if ray. has_differentials
190
- rd. has_differentials = true
191
- rd. rx_origin = surface_intersect. core. p + surface_intersect.∂p∂x
192
- rd. ry_origin = surface_intersect. core. p + surface_intersect.∂p∂y
186
+ rx_origin = surface_intersect. core. p + surface_intersect.∂p∂x
187
+ ry_origin = surface_intersect. core. p + surface_intersect.∂p∂y
193
188
# Compute differential transmitted directions.
194
189
∂n∂x = (
195
190
surface_intersect. shading.∂n∂u * surface_intersect.∂u∂x
@@ -219,8 +214,9 @@ function specular_transmit(
219
214
ν = η - (η^ 2 * (wo ⋅ ns)) / abs (wi ⋅ ns)
220
215
∂μ∂x = ν * ∂dn∂x
221
216
∂μ∂y = ν * ∂dn∂y
222
- rd. rx_direction = wi - η * ∂wo∂x + μ * ∂n∂x + ∂μ∂x * ns
223
- rd. ry_direction = wi - η * ∂wo∂y + μ * ∂n∂y + ∂μ∂y * ns
217
+ rx_direction = wi - η * ∂wo∂x + μ * ∂n∂x + ∂μ∂x * ns
218
+ ry_direction = wi - η * ∂wo∂y + μ * ∂n∂y + ∂μ∂y * ns
219
+ rd = RayDifferentials (rd, rx_origin= rx_origin, ry_origin= ry_origin, rx_direction= rx_direction, ry_direction= ry_direction)
224
220
end
225
- f * li (pool, i, rd, scene, depth + 1 ) * abs (wi ⋅ ns) / pdf
221
+ f * li (i, rd, scene, depth + 1 ) * abs (wi ⋅ ns) / pdf
226
222
end
0 commit comments