1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// // Copyright 2017 Dasein Phaos aka. Luxko
// //
// // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// // option. This file may not be copied, modified, or distributed
// // except according to those terms.
// //! path tracing renderer usage example
// extern crate arendur;
// extern crate cgmath;
// extern crate rand;
// extern crate rayon;
// #[cfg(feature = "flame")]
// extern crate flame;
// extern crate env_logger;
// use arendur::prelude::*;
// type NaiveAggregate = arendur::component::naive::Naive;
// use std::sync::Arc;
// use std::collections::HashMap;
// use std::time::*;
// fn main() {
// env_logger::init().unwrap();
// rayon::initialize(rayon::Configuration::new().num_threads(4)).unwrap();
// println!("Path tracing example");
// println!("component ptr size : {}", std::mem::size_of::<arendur::component::ComponentPointer>());
// use std::io;
// let mut s = String::new();
// let _ = io::stdin().read_line(&mut s);
// println!("Rendering...");
// let sudato = Instant::now();
// // let transform0 = Arc::new(Matrix4f::from_translation(Vector3f::new(2.0 as Float, 12.0 as Float, 30.0 as Float)));
// let transform0 = Arc::new(Matrix4f::from_translation(Vector3f::new(2.0 as Float, 0.0 as Float, -10.0 as Float)));
// let transform1 = Arc::new(Matrix4f::from_translation(Vector3f::new(0.0 as Float, 12.0 as Float, 0.0 as Float)));
// let inv_transform0 = Arc::new(transform0.invert().unwrap());
// let inv_transform1 = Arc::new(transform1.invert().unwrap());
// // let transform2 = Arc::new(Matrix4f::from_translation(Vector3f::new(-5.0 as Float, 20.0 as Float, 10.0 as Float)));
// let transform2 = Arc::new(Matrix4f::from_translation(Vector3f::new(-5.0 as Float, 8.0 as Float, 3.50 as Float)));
// // let transform2 = Arc::new(Matrix4f::from_translation(Vector3f::new(0.0 as Float, 6.0 as Float, 3.50 as Float)));
// let inv_transform2 = Arc::new(transform2.invert().unwrap());
// // let sphere0 = Sphere::new(8. as Float, -7. as Float, 7. as Float, 6.28 as Float);
// let sphere0 = Sphere::full(6. as Float);
// // let sphere0 = Sphere::new(SphereInfo::new(20. as Float, -28. as Float, 58. as Float, 6.49 as Float), ShapeInfo::new(transform0, inv_transform0, false));
// let sphere1 = Sphere::full(8. as Float);
// // let sphere2 = Sphere::full(3. as Float);
// let sphere2 = Sphere::full(2. as Float);
// let mut ref_table = HashMap::new();
// let info = ImageInfo{
// name: String::from("target/540.jpg"),
// trilinear: false,
// max_aniso: 16. as Float,
// wrapping: ImageWrapMode::Repeat,
// gamma: false,
// scale: 1. as Float,
// };
// let kd = RGBImageTexture::new(
// info.clone(),
// UVMapping{
// scaling: Vector2f::new(16. as Float, 16. as Float),
// shifting: Vector2f::new(0. as Float, 0. as Float),
// },
// &mut ref_table,
// ).unwrap();
// let sigma = ConstantTexture{value: 0. as Float};
// let kd = Arc::new(kd);
// let material0 = MatteMaterial::new(kd.clone(), Arc::new(sigma), None);
// let sphere0 = ShapedPrimitive::new(sphere0, material0.clone(), Some(kd));
// let sphere0 = TransformedComposable::new(sphere0, transform0, inv_transform0);
// let sphere0 = Arc::new(sphere0);
// let kd = ConstantTexture{value: RGBSpectrumf::new(0.5 as Float, 0.6 as Float, 0.7 as Float)};
// let sigma = ConstantTexture{value: 10. as Float};
// let material1 = MatteMaterial::new(Arc::new(kd), Arc::new(sigma), None);
// let texture = ConstantTexture{value: RGBSpectrumf::new(5.5 as Float, 5.5 as Float, 5.0 as Float)};
// let sphere1 = ShapedPrimitive::new(sphere1, material1.clone(), Some(Arc::new(texture)));
// let sphere1 = TransformedComposable::new(sphere1, transform1, inv_transform1);
// let kd = ConstantTexture{value: RGBSpectrumf::new(0.6 as Float, 0.6 as Float, 0.6 as Float)};
// let sigma = ConstantTexture{value: 1.0 as Float};
// let material2 = MatteMaterial::new(Arc::new(kd), Arc::new(sigma), None);
// let texture = ConstantTexture{value: RGBSpectrumf::new(15.5 as Float, 13.2 as Float, 10.3 as Float)};
// // let texture = ConstantTexture{value: RGBSpectrumf::new(0.5 as Float, 0.5 as Float, 0.5 as Float)};
// let sphere2 = ShapedPrimitive::new(sphere2, material2.clone(), Some(Arc::new(texture)));
// let sphere2 = Arc::new(TransformedComposable::new(sphere2, transform2, inv_transform2));
// let mut naive = NaiveAggregate::from_one(sphere2.clone());
// // std::env::set_current_dir("./target/sponza/").unwrap();
// // let bvh = BVH::load_obj(
// // "sponza.obj", Matrix4f::from_translation(
// // Vector3f::new(0.0 as Float, -5.0 as Float, 15.0 as Float)
// // ) * Matrix4f::from_angle_y(Rad(float::frac_pi_2()))
// // * Matrix4f::from_scale(1.0 as Float)
// // ).unwrap();
// // println!("bbox:{:?}", bvh.bbox_parent());
// // // naive.append(Arc::new(bvh));
// // let naive = bvh;
// // std::env::set_current_dir("./target/sibenik/").unwrap();
// // #[cfg(feature = "flame")]
// // flame::start("BVH Loading");
// // let bvh = BVH::load_obj(
// // "sibenik.obj", Matrix4f::from_translation(
// // Vector3f::new(0.0 as Float, -0.0 as Float, 15.0 as Float)
// // ) * Matrix4f::from_angle_y(Rad(float::frac_pi_2()))
// // * Matrix4f::from_scale(1.0 as Float)
// // ).unwrap();
// // #[cfg(feature = "flame")]
// // flame::end("BVH Loading");
// // println!("bbox:{:?}", bvh.bbox_parent());
// // // naive.append(Arc::new(bvh));
// // let naive = bvh;
// std::env::set_current_dir("./target/mitsuba/").unwrap();
// let bvh = BVH::load_obj(
// "mitsuba.obj", Matrix4f::from_translation(
// Vector3f::new(0.0 as Float, -2.50 as Float, 7.0 as Float)
// ) * Matrix4f::from_angle_y(Rad(float::pi()))
// * Matrix4f::from_scale(3.0 as Float)
// ).unwrap();
// println!("bbox:{:?}", bvh.bbox_parent());
// naive.append(Arc::new(bvh));
// naive.append(sphere0.clone());
// // let naive = bvh;
// let mut lights: Vec<Arc<Light>> = vec![
// // Arc::new(PointLight::new(
// // Point3f::new(-10.0 as Float, 0.0 as Float, 0.0 as Float),
// // RGBSpectrumf::new(300.7 as Float, 0.0 as Float, 0.0 as Float))
// // ),
// // Arc::new(PointLight::new(
// // Point3f::new(0.0 as Float, -10.0 as Float, 0.0 as Float),
// // RGBSpectrumf::new(0.0 as Float, 300.0 as Float, 0.0 as Float))
// // ),
// // Arc::new(PointLight::new(
// // Point3f::new(0.0 as Float, 0.0 as Float, 0.0 as Float),
// // RGBSpectrumf::new(0.0 as Float, 0.0 as Float, 1.0 as Float))
// // ),
// // Arc::new(PointLight::new(
// // Point3f::new(0.0 as Float, 20. as Float, 15. as Float),
// // RGBSpectrumf::new(1000.7 as Float, 1000.0 as Float, 1000.0 as Float))
// // ),
// // Arc::new(SpotLight::new(
// // // Point3f::new(-8.0 as Float, 20.0 as Float, 5.0 as Float),
// // // Vector3f::new(8.0 as Float, -20.0 as Float, 10.0 as Float).normalize(),
// // Point3f::new(0.0 as Float, 0.0 as Float, 30.0 as Float),
// // Vector3f::new(0.0 as Float, -0.5 as Float, 0.0 as Float).normalize(),
// // RGBSpectrumf::new(350.0 as Float, 73.0 as Float, 345.0 as Float),
// // float::frac_pi_4()*0.75 as Float, float::frac_pi_4()*0.25 as Float)
// // ),
// Arc::new(PointLight::new(
// Point3f::new(0.0 as Float, 0.0 as Float, 0.0 as Float),
// RGBSpectrumf::new(20.0 as Float, 20.0 as Float, 25.0 as Float))
// ),
// ];
// lights.push(sphere0);
// lights.push(sphere2);
// for light in &lights {
// println!("pawa+{:?}", light.power().to_xyz().y);
// }
// let scene = Scene::new(lights, Arc::new(naive));
// let mut camera = PerspecCam::new(
// Matrix4f::identity(),
// BBox2f::new(
// Point2f::new(-1.0 as Float, -0.75 as Float),
// Point2f::new(1.0 as Float, 1.0 as Float)
// // Point2f::new(-0.2 as Float, -0.2 as Float),
// // Point2f::new(0.2 as Float, 0.2 as Float)
// ),
// 0.1 as Float,
// 1000.0 as Float,
// // float::pi()*2.0 as Float / 3.0 as Float,
// float::frac_pi_2(),
// None,
// Film::new(
// Point2::new(86, 80),
// BBox2f::new(
// Point2f::new(0.0 as Float, 0.0 as Float),
// Point2f::new(1.0 as Float, 1.0 as Float)
// ),
// Arc::new(
// // MitchellFilter::new(
// // Vector2f::new(2.0 as Float, 2.0 as Float),
// // 0.5 as Float, 0.25 as Float,
// // )
// LanczosSincFilter::new(
// Vector2f::new(4.0 as Float, 4.0 as Float),
// 3.0 as Float,
// )
// )
// )
// );
// camera.look_from(
// Point3f::origin(),
// Point3f::new(0.0 as Float, 0.0 as Float, 155.0 as Float),
// Vector3f::unit_y()
// );
// // camera.look_from(
// // Point3f::new(0.0 as Float, -3.0 as Float, 15. as Float),
// // Point3f::new(0.0 as Float, 0. as Float, 30. as Float),
// // Vector3f::unit_y()
// // );
// println!("vray_world: {:?}", camera.view_to_parent().transform_vector(
// Vector3f::unit_z()
// ));
// let mut renderer = PTRenderer::new(StrataSampler::new(1, 1, 8, rand::StdRng::new().unwrap()), Arc::new(camera), "target137.png", 8, true);
// // use arendur::sample;
// // let mut renderer = PTRenderer::new(sample::naive::Naive::new(16), Arc::new(camera), "mitsuba15s16_naive.png", 5, true);
// #[cfg(feature = "flame")]
// flame::start("Rendering");
// renderer.render(&scene);
// #[cfg(feature = "flame")]
// flame::end("Rendering");
// let duration = sudato.elapsed();
// println!("Done! Time used: {:.4}s", duration.as_secs() as f64 + (duration.subsec_nanos() as f64/1_000_000_000.0f64));
// #[cfg(feature = "flame")]
// flame::dump_html(&mut std::fs::File::create("flaming.html").unwrap()).unwrap();
// }
extern crate arendur;
use *;
use Arc;