52
52
53
53
function to_trace_primitive (plot:: Makie.Mesh )
54
54
# Potentially per instance attributes
55
- triangles = Trace. create_triangle_mesh (
56
- plot. mesh[], Trace. ShapeCore (Trace. translate (Vec3f (0 )), false ),
57
- )
55
+ triangles = Trace. create_triangle_mesh (plot. mesh[])
58
56
material = extract_material (plot, plot. color)
59
- return [ Trace. GeometricPrimitive (t , material) for t in triangles]
57
+ return Trace. GeometricPrimitive (triangles , material)
60
58
end
61
59
62
60
function to_trace_primitive (plot:: Makie.Surface )
@@ -85,14 +83,13 @@ function to_trace_primitive(plot::Makie.Surface)
85
83
# with this we can beuild a mesh
86
84
mesh = normal_mesh (GeometryBasics. Mesh (meta (vec (positions[]), uv= uv), faces))
87
85
88
- triangles = Trace. create_triangle_mesh (
89
- mesh, Trace. ShapeCore (Trace. translate (Vec3f (0 )), false ),
90
- )
86
+ triangles = Trace. create_triangle_mesh (mesh)
91
87
material = extract_material (plot, plot. z)
92
- return [ Trace. GeometricPrimitive (t , material) for t in triangles]
88
+ return Trace. GeometricPrimitive (triangles , material)
93
89
end
90
+
94
91
function to_trace_primitive (plot:: Makie.Plot )
95
- return []
92
+ return nothing
96
93
end
97
94
98
95
function to_trace_light (light:: Makie.AmbientLight )
@@ -118,13 +115,10 @@ function to_trace_light(light::Makie.PointLight)
118
115
)
119
116
end
120
117
121
-
122
-
123
118
function to_trace_light (light)
124
119
return nothing
125
120
end
126
121
127
-
128
122
function to_trace_camera (scene:: Makie.Scene , film)
129
123
cc = scene. camera_controls
130
124
fov = cc. fov[]
@@ -156,7 +150,7 @@ function render_scene(integrator_f, mscene::Makie.Scene)
156
150
primitives = []
157
151
for plot in mscene. plots
158
152
prim = to_trace_primitive (plot)
159
- append ! (primitives, prim)
153
+ ! isnothing (prim) && push ! (primitives, prim)
160
154
end
161
155
camera = to_trace_camera (mscene, film)
162
156
lights = []
@@ -167,48 +161,50 @@ function render_scene(integrator_f, mscene::Makie.Scene)
167
161
if isempty (lights)
168
162
error (" Must have at least one light" )
169
163
end
170
- bvh = Trace. BVHAccel (map (identity, primitives) , 1 )
164
+ bvh = Trace. BVHAccel (primitives, 1 )
171
165
integrator = integrator_f (camera)
172
166
scene = Trace. Scene ([lights... ], bvh)
173
- integrator (scene)
167
+ integrator (scene, film )
174
168
return reverse (film. framebuffer, dims= 1 )
175
169
end
176
-
170
+ glass = Trace. GlassMaterial (
171
+ Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )),
172
+ Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )),
173
+ Trace. ConstantTexture (0.0f0 ),
174
+ Trace. ConstantTexture (0.0f0 ),
175
+ Trace. ConstantTexture (1.25f0 ),
176
+ true ,
177
+ )
178
+ mirror = Trace. MirrorMaterial (Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )))
179
+ plastic = Trace. PlasticMaterial (
180
+ Trace. ConstantTexture (Trace. RGBSpectrum (0.6399999857f0 , 0.6399999857f0 , 0.6399999857f0 )),
181
+ Trace. ConstantTexture (Trace. RGBSpectrum (0.1000000015f0 , 0.1000000015f0 , 0.1000000015f0 )),
182
+ Trace. ConstantTexture (0.010408001f0 ),
183
+ true ,
184
+ )
177
185
catmesh = load (Makie. assetpath (" cat.obj" ))
186
+
178
187
begin
179
- glass = Trace. GlassMaterial (
180
- Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )),
181
- Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )),
182
- Trace. ConstantTexture (0.0f0 ),
183
- Trace. ConstantTexture (0.0f0 ),
184
- Trace. ConstantTexture (1.25f0 ),
185
- true ,
188
+ scene = Scene (size= (1024 , 1024 );
189
+ lights= [AmbientLight (RGBf (0.7 , 0.6 , 0.6 )), PointLight (Vec3f (0 , 1 , 0.5 ), RGBf (1.3 , 1.3 , 1.3 ))]
186
190
)
187
- mirror = Trace. MirrorMaterial (Trace. ConstantTexture (Trace. RGBSpectrum (1.0f0 )))
188
- plastic = Trace. PlasticMaterial (
189
- Trace. ConstantTexture (Trace. RGBSpectrum (0.6399999857f0 , 0.6399999857f0 , 0.6399999857f0 )),
190
- Trace. ConstantTexture (Trace. RGBSpectrum (0.1000000015f0 , 0.1000000015f0 , 0.1000000015f0 )),
191
- Trace. ConstantTexture (0.010408001f0 ),
192
- true ,
193
- )
194
- scene = Scene (size= (1024 , 1024 ); lights= [AmbientLight (RGBf (0.7 , 0.6 , 0.6 )), PointLight (Vec3f (0 , 1 , 0.5 ), RGBf (1.3 , 1.3 , 1.3 ))])
195
191
cam3d! (scene)
196
192
mesh! (scene, catmesh, color= load (Makie. assetpath (" diffusemap.png" )))
197
193
center! (scene)
198
- render_scene (scene)
194
+ # 1.024328 seconds (16.94 M allocations: 5.108 GiB, 46.19% gc time, 81 lock conflicts)
195
+ @time render_scene (scene)
199
196
end
200
197
201
-
202
198
begin
203
- scene = Scene (size= (1024 , 1024 ); lights= [
204
- AmbientLight (RGBf (0.4 , 0.4 , 0.4 )), PointLight (Vec3f (4 , 4 , 10 ), RGBf (500 , 500 , 500 ))])
199
+ scene = Scene (size= (1024 , 1024 );
200
+ lights= [AmbientLight (RGBf (0.4 , 0.4 , 0.4 )), PointLight (Vec3f (4 , 4 , 10 ), RGBf (500 , 500 , 500 ))]
201
+ )
205
202
cam3d! (scene)
206
203
xs = LinRange (0 , 10 , 100 )
207
204
ys = LinRange (0 , 15 , 100 )
208
205
zs = [cos (x) * sin (y) for x in xs, y in ys]
209
206
surface! (scene, xs, ys, zs)
210
207
center! (scene)
211
- render_scene (scene) do cam
212
-
213
- end
208
+ # 1.598740s
209
+ @time render_scene (scene)
214
210
end
0 commit comments