@@ -24,6 +24,8 @@ struct Film{Pixels<:AbstractMatrix{Pixel}}
24
24
"""
25
25
filter_table:: Matrix{Float32}
26
26
scale:: Float32
27
+ framebuffer:: Matrix{RGB{Float32}}
28
+
27
29
"""
28
30
- resolution: full resolution of the image in pixels.
29
31
- crop_bounds: subset of the image to render in [0, 1] range.
@@ -44,16 +46,20 @@ struct Film{Pixels<:AbstractMatrix{Pixel}}
44
46
)
45
47
crop_resolution = Int32 .(inclusive_sides (crop_bounds))
46
48
# Allocate film image storage.
47
- pixels = StructArray (fill (Pixel (), crop_resolution[end ], crop_resolution[end ]))
49
+ pixels = StructArray {Pixel} (undef, crop_resolution[end ], crop_resolution[end ])
50
+ pixels. xyz .= (Point3f (0 ),)
51
+ pixels. filter_weight_sum .= 0f0
52
+ pixels. splat_xyz .= (Point3f (0 ),)
48
53
# Precompute filter weight table.
49
54
r = filter. radius ./ filter_table_width
50
55
for y in 0 : filter_table_width- 1 , x in 0 : filter_table_width- 1
51
56
p = Point2f ((x + 0.5f0 ) * r[1 ], (y + 0.5f0 ) * r[2 ])
52
57
filter_table[y+ 1 , x+ 1 ] = filter (p)
53
58
end
59
+ framebuffer = Matrix {RGB{Float32}} (undef, size (pixels)... )
54
60
new {typeof(pixels)} (
55
61
resolution, crop_bounds, diagonal * 0.001f0 , filter, filename,
56
- pixels, filter_table_width, filter_table, scale,
62
+ pixels, filter_table_width, filter_table, scale, framebuffer
57
63
)
58
64
end
59
65
end
@@ -98,11 +104,13 @@ struct FilmTile{Pixels<:AbstractMatrix{<:FilmTilePixel}}
98
104
pixels:: Pixels
99
105
100
106
function FilmTile (
101
- bounds:: Bounds2 , filter_radius:: Point2f ,
102
- filter_table:: Matrix{Float32} , filter_table_width:: Int32 ,
103
- )
107
+ bounds:: Bounds2 , filter_radius:: Point2f ,
108
+ filter_table:: Matrix{Float32} , filter_table_width:: Int32 ,
109
+ )
104
110
tile_res = (Int32 .(inclusive_sides (bounds)))
105
- pixels = StructArray (fill (FilmTilePixel (), (tile_res[2 ], tile_res[1 ])))
111
+ pixels = StructArray {FilmTilePixel{RGBSpectrum}} (undef, tile_res[2 ], tile_res[1 ])
112
+ pixels. contrib_sum .= (RGBSpectrum (),)
113
+ pixels. filter_weight_sum .= 0.0f0
106
114
new {typeof(pixels)} (
107
115
bounds, filter_radius, 1f0 ./ filter_radius,
108
116
filter_table, filter_table_width,
@@ -129,14 +137,15 @@ Add sample contribution to the film tile.
129
137
And is relative to the film, not the film tile.
130
138
"""
131
139
function add_sample! (
132
- t:: FilmTile , point:: Point2f , spectrum:: S ,
133
- sample_weight:: Float32 = 1f0 ,
134
- ) where S<: Spectrum
140
+ t:: FilmTile , point:: Point2f , spectrum:: S ,
141
+ sample_weight:: Float32 = 1f0 ,
142
+ ) where S<: Spectrum
143
+
135
144
# Compute sample's raster bounds.
136
145
discrete_point = point .- 0.5f0
137
146
p0 = ceil .(Int32, discrete_point .- t. filter_radius)
138
147
p1 = floor .(Int32, discrete_point .+ t. filter_radius) .+ 1
139
- p0 = Int32 .(max .(p0, max .(t. bounds. p_min, Point2 ( Int32 ( 1 ) ))))
148
+ p0 = Int32 .(max .(p0, max .(t. bounds. p_min, Point2 { Int32} ( 1 ))))
140
149
p1 = Int32 .(min .(p1, t. bounds. p_max))
141
150
# Precompute x & y filter offsets.
142
151
offsets_x = Vector {Int32} (undef, p1[1 ] - p0[1 ] + 1 )
0 commit comments