├── .gitignore
├── COPYING
├── Cargo.lock
├── Cargo.toml
├── README.md
├── clippy.toml
├── examples
├── common
│ ├── mod.rs
│ ├── ray_tracing_in_one_weekend.rs
│ ├── ray_tracing_next_week.rs
│ └── scene.rs
├── earth-map.png
├── rtnw_10.rs
├── rtnw_2_5.rs
├── rtnw_4_3.rs
├── rtnw_4_4.rs
├── rtnw_5_1.rs
├── rtnw_5_2.rs
├── rtnw_5_3.rs
├── rtnw_5_4.rs
├── rtnw_5_5.rs
├── rtnw_5_6.rs
├── rtnw_5_7.rs
├── rtnw_6_2.rs
├── rtnw_7_4.rs
├── rtnw_7_4_2.rs
├── rtnw_7_6.rs
├── rtnw_8_0.rs
├── rtnw_8_1.rs
├── rtnw_8_2.rs
├── rtnw_9_2.rs
├── rtow_10_3.rs
├── rtow_10_5.rs
├── rtow_11_1.rs
├── rtow_11_2.rs
├── rtow_11_2_2.rs
├── rtow_12_2.rs
├── rtow_13_1.rs
├── rtow_2_2.rs
├── rtow_4_2.rs
├── rtow_5_2.rs
├── rtow_6_1.rs
├── rtow_6_7.rs
├── rtow_7_2.rs
├── rtow_8_2.rs
├── rtow_8_3.rs
├── rtow_8_5.rs
├── rtow_8_6.rs
├── rtow_9_5.rs
├── rtow_9_6.rs
├── rtrl_2_1.rs
├── rtrl_2_2.rs
├── rtrl_2_3.rs
├── rtrl_3_1.rs
└── rtrl_3_3.rs
├── rustfmt.toml
└── src
├── camera.rs
├── hittable
├── collection
│ ├── bvh.rs
│ ├── list.rs
│ ├── mod.rs
│ └── world.rs
├── geometry
│ ├── carton.rs
│ ├── mod.rs
│ ├── rect.rs
│ └── sphere.rs
├── hit.rs
├── medium
│ ├── constant.rs
│ └── mod.rs
├── mod.rs
└── transform
│ ├── mod.rs
│ ├── rotation.rs
│ └── translation.rs
├── internal
├── mod.rs
└── rayon_seq_iter.rs
├── lib.rs
├── material
├── dielectric.rs
├── isotropic.rs
├── lambertian.rs
├── light.rs
├── metal.rs
└── mod.rs
├── painter.rs
├── prelude
├── aabb.rs
├── color.rs
├── mod.rs
├── random.rs
├── ray.rs
└── vec3.rs
└── texture
├── checker.rs
├── image.rs
├── mod.rs
└── noise.rs
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /.idea
3 | /.vscode
4 | /*.ppm
5 | **/.DS_Store
6 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | \"This License\" refers to version 3 of the GNU General Public License.
76 |
77 | \"Copyright\" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | \"The Program\" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as \"you\". \"Licensees\" and
82 | \"recipients\" may be individuals or organizations.
83 |
84 | To \"modify\" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a \"modified version\" of the
87 | earlier work or a work \"based on\" the earlier work.
88 |
89 | A \"covered work\" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To \"propagate\" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To \"convey\" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays \"Appropriate Legal Notices\
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The \"source code\" for a work means the preferred form of the work
115 | for making modifications to it. \"Object code\" means any non-source
116 | form of a work.
117 |
118 | A \"Standard Interface\" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The \"System Libraries\" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | \"Major Component\", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The \"Corresponding Source\" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | \"keep intact all notices\".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | \"aggregate\" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A \"User Product\" is either (1) a \"consumer product\", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, \"normally used\" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | \"Installation Information\" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | \"Additional permissions\" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered \"further
389 | restrictions\" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An \"entity transaction\" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A \"contributor\" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's \"contributor version\".
476 |
477 | A contributor's \"essential patent claims\" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, \"control\" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a \"patent license\" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To \"grant\" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. \"Knowingly relying\" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is \"discriminatory\" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License \"or any later version\" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the \"copyright\" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an \"about box\".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a \"copyright disclaimer\" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
676 |
--------------------------------------------------------------------------------
/Cargo.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Cargo.
2 | # It is not intended for manual editing.
3 | [[package]]
4 | name = "adler32"
5 | version = "1.2.0"
6 | source = "registry+https://github.com/rust-lang/crates.io-index"
7 | checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
8 |
9 | [[package]]
10 | name = "aho-corasick"
11 | version = "0.7.15"
12 | source = "registry+https://github.com/rust-lang/crates.io-index"
13 | checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
14 | dependencies = [
15 | "memchr",
16 | ]
17 |
18 | [[package]]
19 | name = "atty"
20 | version = "0.2.14"
21 | source = "registry+https://github.com/rust-lang/crates.io-index"
22 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
23 | dependencies = [
24 | "hermit-abi",
25 | "libc",
26 | "winapi",
27 | ]
28 |
29 | [[package]]
30 | name = "autocfg"
31 | version = "1.0.1"
32 | source = "registry+https://github.com/rust-lang/crates.io-index"
33 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
34 |
35 | [[package]]
36 | name = "bitflags"
37 | version = "1.2.1"
38 | source = "registry+https://github.com/rust-lang/crates.io-index"
39 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
40 |
41 | [[package]]
42 | name = "bytemuck"
43 | version = "1.5.1"
44 | source = "registry+https://github.com/rust-lang/crates.io-index"
45 | checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58"
46 |
47 | [[package]]
48 | name = "byteorder"
49 | version = "1.4.2"
50 | source = "registry+https://github.com/rust-lang/crates.io-index"
51 | checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
52 |
53 | [[package]]
54 | name = "cfg-if"
55 | version = "1.0.0"
56 | source = "registry+https://github.com/rust-lang/crates.io-index"
57 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
58 |
59 | [[package]]
60 | name = "color_quant"
61 | version = "1.1.0"
62 | source = "registry+https://github.com/rust-lang/crates.io-index"
63 | checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
64 |
65 | [[package]]
66 | name = "crc32fast"
67 | version = "1.2.1"
68 | source = "registry+https://github.com/rust-lang/crates.io-index"
69 | checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
70 | dependencies = [
71 | "cfg-if",
72 | ]
73 |
74 | [[package]]
75 | name = "crossbeam-channel"
76 | version = "0.5.0"
77 | source = "registry+https://github.com/rust-lang/crates.io-index"
78 | checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
79 | dependencies = [
80 | "cfg-if",
81 | "crossbeam-utils",
82 | ]
83 |
84 | [[package]]
85 | name = "crossbeam-deque"
86 | version = "0.8.0"
87 | source = "registry+https://github.com/rust-lang/crates.io-index"
88 | checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
89 | dependencies = [
90 | "cfg-if",
91 | "crossbeam-epoch",
92 | "crossbeam-utils",
93 | ]
94 |
95 | [[package]]
96 | name = "crossbeam-epoch"
97 | version = "0.9.3"
98 | source = "registry+https://github.com/rust-lang/crates.io-index"
99 | checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12"
100 | dependencies = [
101 | "cfg-if",
102 | "crossbeam-utils",
103 | "lazy_static",
104 | "memoffset",
105 | "scopeguard",
106 | ]
107 |
108 | [[package]]
109 | name = "crossbeam-utils"
110 | version = "0.8.3"
111 | source = "registry+https://github.com/rust-lang/crates.io-index"
112 | checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49"
113 | dependencies = [
114 | "autocfg",
115 | "cfg-if",
116 | "lazy_static",
117 | ]
118 |
119 | [[package]]
120 | name = "deflate"
121 | version = "0.8.6"
122 | source = "registry+https://github.com/rust-lang/crates.io-index"
123 | checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174"
124 | dependencies = [
125 | "adler32",
126 | "byteorder",
127 | ]
128 |
129 | [[package]]
130 | name = "either"
131 | version = "1.6.1"
132 | source = "registry+https://github.com/rust-lang/crates.io-index"
133 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
134 |
135 | [[package]]
136 | name = "env_logger"
137 | version = "0.8.3"
138 | source = "registry+https://github.com/rust-lang/crates.io-index"
139 | checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f"
140 | dependencies = [
141 | "atty",
142 | "humantime",
143 | "log",
144 | "regex",
145 | "termcolor",
146 | ]
147 |
148 | [[package]]
149 | name = "getrandom"
150 | version = "0.2.2"
151 | source = "registry+https://github.com/rust-lang/crates.io-index"
152 | checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
153 | dependencies = [
154 | "cfg-if",
155 | "libc",
156 | "wasi",
157 | ]
158 |
159 | [[package]]
160 | name = "hermit-abi"
161 | version = "0.1.18"
162 | source = "registry+https://github.com/rust-lang/crates.io-index"
163 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
164 | dependencies = [
165 | "libc",
166 | ]
167 |
168 | [[package]]
169 | name = "humantime"
170 | version = "2.1.0"
171 | source = "registry+https://github.com/rust-lang/crates.io-index"
172 | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
173 |
174 | [[package]]
175 | name = "image"
176 | version = "0.23.14"
177 | source = "registry+https://github.com/rust-lang/crates.io-index"
178 | checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1"
179 | dependencies = [
180 | "bytemuck",
181 | "byteorder",
182 | "color_quant",
183 | "jpeg-decoder",
184 | "num-iter",
185 | "num-rational",
186 | "num-traits",
187 | "png",
188 | ]
189 |
190 | [[package]]
191 | name = "jpeg-decoder"
192 | version = "0.1.22"
193 | source = "registry+https://github.com/rust-lang/crates.io-index"
194 | checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
195 | dependencies = [
196 | "rayon",
197 | ]
198 |
199 | [[package]]
200 | name = "lazy_static"
201 | version = "1.4.0"
202 | source = "registry+https://github.com/rust-lang/crates.io-index"
203 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
204 |
205 | [[package]]
206 | name = "libc"
207 | version = "0.2.88"
208 | source = "registry+https://github.com/rust-lang/crates.io-index"
209 | checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
210 |
211 | [[package]]
212 | name = "log"
213 | version = "0.4.14"
214 | source = "registry+https://github.com/rust-lang/crates.io-index"
215 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
216 | dependencies = [
217 | "cfg-if",
218 | ]
219 |
220 | [[package]]
221 | name = "memchr"
222 | version = "2.3.4"
223 | source = "registry+https://github.com/rust-lang/crates.io-index"
224 | checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
225 |
226 | [[package]]
227 | name = "memoffset"
228 | version = "0.6.1"
229 | source = "registry+https://github.com/rust-lang/crates.io-index"
230 | checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
231 | dependencies = [
232 | "autocfg",
233 | ]
234 |
235 | [[package]]
236 | name = "miniz_oxide"
237 | version = "0.3.7"
238 | source = "registry+https://github.com/rust-lang/crates.io-index"
239 | checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435"
240 | dependencies = [
241 | "adler32",
242 | ]
243 |
244 | [[package]]
245 | name = "num-integer"
246 | version = "0.1.44"
247 | source = "registry+https://github.com/rust-lang/crates.io-index"
248 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
249 | dependencies = [
250 | "autocfg",
251 | "num-traits",
252 | ]
253 |
254 | [[package]]
255 | name = "num-iter"
256 | version = "0.1.42"
257 | source = "registry+https://github.com/rust-lang/crates.io-index"
258 | checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
259 | dependencies = [
260 | "autocfg",
261 | "num-integer",
262 | "num-traits",
263 | ]
264 |
265 | [[package]]
266 | name = "num-rational"
267 | version = "0.3.2"
268 | source = "registry+https://github.com/rust-lang/crates.io-index"
269 | checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07"
270 | dependencies = [
271 | "autocfg",
272 | "num-integer",
273 | "num-traits",
274 | ]
275 |
276 | [[package]]
277 | name = "num-traits"
278 | version = "0.2.14"
279 | source = "registry+https://github.com/rust-lang/crates.io-index"
280 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
281 | dependencies = [
282 | "autocfg",
283 | ]
284 |
285 | [[package]]
286 | name = "num_cpus"
287 | version = "1.13.0"
288 | source = "registry+https://github.com/rust-lang/crates.io-index"
289 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
290 | dependencies = [
291 | "hermit-abi",
292 | "libc",
293 | ]
294 |
295 | [[package]]
296 | name = "once_cell"
297 | version = "1.7.2"
298 | source = "registry+https://github.com/rust-lang/crates.io-index"
299 | checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
300 |
301 | [[package]]
302 | name = "png"
303 | version = "0.16.8"
304 | source = "registry+https://github.com/rust-lang/crates.io-index"
305 | checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6"
306 | dependencies = [
307 | "bitflags",
308 | "crc32fast",
309 | "deflate",
310 | "miniz_oxide",
311 | ]
312 |
313 | [[package]]
314 | name = "ppv-lite86"
315 | version = "0.2.10"
316 | source = "registry+https://github.com/rust-lang/crates.io-index"
317 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
318 |
319 | [[package]]
320 | name = "rand"
321 | version = "0.8.3"
322 | source = "registry+https://github.com/rust-lang/crates.io-index"
323 | checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
324 | dependencies = [
325 | "libc",
326 | "rand_chacha",
327 | "rand_core",
328 | "rand_hc",
329 | ]
330 |
331 | [[package]]
332 | name = "rand_chacha"
333 | version = "0.3.0"
334 | source = "registry+https://github.com/rust-lang/crates.io-index"
335 | checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
336 | dependencies = [
337 | "ppv-lite86",
338 | "rand_core",
339 | ]
340 |
341 | [[package]]
342 | name = "rand_core"
343 | version = "0.6.2"
344 | source = "registry+https://github.com/rust-lang/crates.io-index"
345 | checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
346 | dependencies = [
347 | "getrandom",
348 | ]
349 |
350 | [[package]]
351 | name = "rand_hc"
352 | version = "0.3.0"
353 | source = "registry+https://github.com/rust-lang/crates.io-index"
354 | checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
355 | dependencies = [
356 | "rand_core",
357 | ]
358 |
359 | [[package]]
360 | name = "rayon"
361 | version = "1.5.0"
362 | source = "registry+https://github.com/rust-lang/crates.io-index"
363 | checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
364 | dependencies = [
365 | "autocfg",
366 | "crossbeam-deque",
367 | "either",
368 | "rayon-core",
369 | ]
370 |
371 | [[package]]
372 | name = "rayon-core"
373 | version = "1.9.0"
374 | source = "registry+https://github.com/rust-lang/crates.io-index"
375 | checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
376 | dependencies = [
377 | "crossbeam-channel",
378 | "crossbeam-deque",
379 | "crossbeam-utils",
380 | "lazy_static",
381 | "num_cpus",
382 | ]
383 |
384 | [[package]]
385 | name = "regex"
386 | version = "1.4.3"
387 | source = "registry+https://github.com/rust-lang/crates.io-index"
388 | checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
389 | dependencies = [
390 | "aho-corasick",
391 | "memchr",
392 | "regex-syntax",
393 | "thread_local",
394 | ]
395 |
396 | [[package]]
397 | name = "regex-syntax"
398 | version = "0.6.22"
399 | source = "registry+https://github.com/rust-lang/crates.io-index"
400 | checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
401 |
402 | [[package]]
403 | name = "remda"
404 | version = "0.1.0"
405 | dependencies = [
406 | "env_logger",
407 | "image",
408 | "log",
409 | "num_cpus",
410 | "once_cell",
411 | "rand",
412 | "rayon",
413 | ]
414 |
415 | [[package]]
416 | name = "scopeguard"
417 | version = "1.1.0"
418 | source = "registry+https://github.com/rust-lang/crates.io-index"
419 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
420 |
421 | [[package]]
422 | name = "termcolor"
423 | version = "1.1.2"
424 | source = "registry+https://github.com/rust-lang/crates.io-index"
425 | checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
426 | dependencies = [
427 | "winapi-util",
428 | ]
429 |
430 | [[package]]
431 | name = "thread_local"
432 | version = "1.1.3"
433 | source = "registry+https://github.com/rust-lang/crates.io-index"
434 | checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
435 | dependencies = [
436 | "once_cell",
437 | ]
438 |
439 | [[package]]
440 | name = "wasi"
441 | version = "0.10.2+wasi-snapshot-preview1"
442 | source = "registry+https://github.com/rust-lang/crates.io-index"
443 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
444 |
445 | [[package]]
446 | name = "winapi"
447 | version = "0.3.9"
448 | source = "registry+https://github.com/rust-lang/crates.io-index"
449 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
450 | dependencies = [
451 | "winapi-i686-pc-windows-gnu",
452 | "winapi-x86_64-pc-windows-gnu",
453 | ]
454 |
455 | [[package]]
456 | name = "winapi-i686-pc-windows-gnu"
457 | version = "0.4.0"
458 | source = "registry+https://github.com/rust-lang/crates.io-index"
459 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
460 |
461 | [[package]]
462 | name = "winapi-util"
463 | version = "0.1.5"
464 | source = "registry+https://github.com/rust-lang/crates.io-index"
465 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
466 | dependencies = [
467 | "winapi",
468 | ]
469 |
470 | [[package]]
471 | name = "winapi-x86_64-pc-windows-gnu"
472 | version = "0.4.0"
473 | source = "registry+https://github.com/rust-lang/crates.io-index"
474 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
475 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "remda"
3 | version = "0.1.0"
4 | authors = ["7sDream "]
5 | edition = "2018"
6 | description = "Yet another simple and pure software ray tracing renderer"
7 | homepage = "https://github.com/7sDream/remda"
8 | repository = "https://github.com/7sDream/remda"
9 | license-file = "COPYING"
10 | publish = false
11 |
12 | [lib]
13 | name = "remda"
14 | path = "src/lib.rs"
15 |
16 | [dependencies]
17 | env_logger = "0.8"
18 | log = "0.4"
19 | rand = "0.8"
20 | rayon = "1.5"
21 | num_cpus = "1.13"
22 | once_cell = "1.7"
23 |
24 | [dependencies.image]
25 | version = "0.23"
26 | default-features = false
27 | features = ["jpeg_rayon", "png", "bmp"]
28 |
29 | [profile.release]
30 | debug = true
31 | lto = "fat"
32 | codegen-units = 1
33 | panic = "abort"
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Remda
2 |
3 | Learn [*Ray Tracing in One Weekend* series][book-series] using Rust.
4 |
5 | Yet another naive and pure software ray tracing renderer.
6 |
7 | ## Render Result Examples
8 |
9 | ![rendered image of RTOW's balls scene][rtow-balls-scene-render-result]
10 | *example rtow_13_1, 512 sample, 8 depth, 1920x1080, 8m30s*
11 |
12 | ![rendered image of RTNW's balls motion blur scene][rtnw-balls-scene-motion-blur-render-result]
13 | *example rtnw_4_3, 1024 sample, 8 depth, 1920x1080, 22min*
14 |
15 | ![rendered image of RTNW's ball with noise texture scene][rtnw-ball-noise-texture-scene-render-result]
16 | *example rtnw_7_4_2, 4096 sample, 8 depth, 1500x900, 15min*
17 |
18 | ![rendered image of RTNW's Cornell scene][rtnw-cornell-rotated-scene-render-result]
19 | *example rtnw_8_2, 10240 sample, 10 depth, 1000x1000, 1h20m*
20 |
21 | ![rendered image of RTNW's Cornel smoke scene][rtnw-cornell-smoke-scene-render-result]
22 | *example rtnw_9_2, 10240 sample, 10 depth, 1000x1000, 1h30m*
23 |
24 | ![rendered image of RTNW's final scene][rtnw-final-scene-render-result]
25 | *example rtnw_10, 10240 sample, 10 depth, 1000x1000, 2h30m*
26 |
27 | ## Current Progress
28 |
29 | - [x] [*Ray Tracing in One Weekend*][book-1]
30 | - [x] Basic types, Vec, Color, Ray, etc
31 | - [x] Background/Sky
32 | - [x] Sphere
33 | - [x] Lambertian Material
34 | - [x] Metal Material with Different Fuzz
35 | - [x] Glass Material with Different Refractive
36 | - [x] Pinhole Camera
37 | - [x] Camera Defocus/Depth Field
38 | - [x] (Extra) Parallelism (by using [rayon][rayon-crates-io])
39 | - [x] [*Ray Tracing: The Next Week*][book-2]
40 | - [x] Motion Blur
41 | - [x] BVH(Bounding Volume Hierarchies)
42 | - [x] Solid Textures
43 | - [x] Perlin Noise
44 | - [x] Image Textures
45 | - [x] Rectangles
46 | - [x] Lights
47 | - [x] Cornell Box
48 | - [x] Box
49 | - [x] Instance Translation and Rotation
50 | - [x] Volumes/Participating Media
51 | - [ ] [*Ray Tracing: The Rest of Your Life*][book-3] not started yet
52 |
53 | ## Run
54 |
55 | Remda is a library crate, but you can run built-in examples(from the book series) to try it.
56 |
57 | Use `cargo run --example` to get examples list, then choose one to run.
58 |
59 | For example, to get final scene in section 13.1 of *Ray Tracing in One Weekend*, run
60 |
61 | ```bash
62 | cargo run --example rtow_13_1 --release
63 | ```
64 |
65 | Wait about 1s(according to your machine's CPU performance), you will get a `rtow_13_1.ppm` in current dir, that's your result.
66 |
67 | If you want a bigger and clear image, adjust `height()`, `depth` and `samples()` parameter in example source file and re-run.
68 |
69 | You can also try other examples if you want.
70 |
71 | PS: Pure software ray tracing takes a long time to render, be patient.
72 |
73 | ## LICENSE
74 |
75 | GPLv3
76 |
77 | Except:
78 |
79 | - `example/earth-map.png`, download from [NASA][earth-map-source], fall in public domain.
80 |
81 | [book-series]: https://raytracing.github.io/
82 | [book-1]: https://raytracing.github.io/books/RayTracingInOneWeekend.html
83 | [book-2]: https://raytracing.github.io/books/RayTracingTheNextWeek.html
84 | [book-3]: https://raytracing.github.io/books/RayTracingTheRestOfYourLife.html
85 | [rtow-balls-scene-render-result]: https://rikka.7sdre.am/files/a952c7ca-af57-46a6-959f-237702333ab6.png
86 | [rtnw-balls-scene-motion-blur-render-result]: https://rikka.7sdre.am/files/a0f8d5bd-9bc5-4361-b1dc-4adabd9c9949.png
87 | [rtnw-ball-noise-texture-scene-render-result]: https://rikka.7sdre.am/files/e5b459c6-aa8e-47aa-ab20-33d430ba6b2f.png
88 | [rtnw-cornell-rotated-scene-render-result]: https://rikka.7sdre.am/files/1721b196-b746-4e6d-a4d0-f9c7c2e75c41.png
89 | [rtnw-cornell-smoke-scene-render-result]: https://rikka.7sdre.am/files/545972fd-d10d-4345-9e8c-3ba16fb50524.png
90 | [rtnw-final-scene-render-result]: https://rikka.7sdre.am/files/3e1e1849-54bf-4a7b-9e09-b2cc25b5cf6f.png
91 | [rayon-crates-io]: https://crates.io/crates/rayon
92 | [earth-map-source]: http://visibleearth.nasa.gov/view.php?id=57752
93 |
--------------------------------------------------------------------------------
/clippy.toml:
--------------------------------------------------------------------------------
1 | cognitive-complexity-threshold = 25
2 | literal-representation-threshold = 0
3 | enum-variant-name-threshold = 0
4 | enum-variant-size-threshold = 32
5 | single-char-binding-names-threshold = 6
6 | too-many-arguments-threshold = 5
7 | too-many-lines-threshold = 50
8 | trivial-copy-size-limit = 8
9 | verbose-bit-mask-threshold = 1
10 |
--------------------------------------------------------------------------------
/examples/common/mod.rs:
--------------------------------------------------------------------------------
1 | mod scene;
2 |
3 | pub mod ray_tracing_in_one_weekend;
4 | pub mod ray_tracing_next_week;
5 |
6 | pub fn init_log(level: &'static str) {
7 | let env = env_logger::Env::default().default_filter_or(level);
8 | env_logger::init_from_env(env);
9 | }
10 |
--------------------------------------------------------------------------------
/examples/common/ray_tracing_in_one_weekend.rs:
--------------------------------------------------------------------------------
1 | use {
2 | super::scene,
3 | remda::{camera::Camera, hittable::collection::HittableList},
4 | };
5 |
6 | #[must_use]
7 | fn final_world(seed: Option) -> HittableList {
8 | scene::balls_scene(seed, false, false)
9 | }
10 |
11 | #[must_use]
12 | fn final_camera() -> Camera {
13 | scene::balls_scene_camera(false)
14 | }
15 |
16 | #[must_use]
17 | pub fn final_scene(seed: Option) -> (Camera, HittableList) {
18 | (final_camera(), final_world(seed))
19 | }
20 |
--------------------------------------------------------------------------------
/examples/common/ray_tracing_next_week.rs:
--------------------------------------------------------------------------------
1 | use {
2 | super::scene,
3 | remda::{camera::Camera, hittable::collection::HittableList},
4 | };
5 |
6 | pub use scene::all_feature_scene;
7 |
8 | #[must_use]
9 | fn motion_blur_world(seed: Option, checker: bool) -> HittableList {
10 | scene::balls_scene(seed, true, checker)
11 | }
12 |
13 | #[must_use]
14 | fn motion_blur_camera() -> Camera {
15 | scene::balls_scene_camera(true)
16 | }
17 |
18 | #[must_use]
19 | pub fn motion_blur(seed: Option, checker: bool) -> (Camera, HittableList) {
20 | (motion_blur_camera(), motion_blur_world(seed, checker))
21 | }
22 |
23 | #[must_use]
24 | pub fn empty_cornell_box() -> (Camera, HittableList) {
25 | scene::cornell_box_scene(false, false, false)
26 | }
27 |
28 | #[must_use]
29 | pub fn cornell_box_no_rotation() -> (Camera, HittableList) {
30 | scene::cornell_box_scene(true, false, false)
31 | }
32 |
33 | #[must_use]
34 | pub fn cornell_box() -> (Camera, HittableList) {
35 | scene::cornell_box_scene(true, true, false)
36 | }
37 |
38 | #[must_use]
39 | pub fn cornell_box_smoke() -> (Camera, HittableList) {
40 | scene::cornell_box_scene(true, true, true)
41 | }
42 |
--------------------------------------------------------------------------------
/examples/common/scene.rs:
--------------------------------------------------------------------------------
1 | use {
2 | remda::{
3 | camera::{Camera, CameraBuilder},
4 | hittable::{
5 | collection::{HittableList, BVH},
6 | medium::ConstantMedium,
7 | transform::{AARotation, ByYAxis, Translation},
8 | AARect, AARectMetrics, Carton, Sphere,
9 | },
10 | material::{Dielectric, DiffuseLight, Glass, Lambertian, Metal},
11 | prelude::*,
12 | texture::{Checker, Image, Perlin, SmoothType},
13 | },
14 | std::sync::Arc,
15 | };
16 |
17 | fn add_small_balls(world: &mut HittableList, rng: &mut SeedRandom, need_speed: bool) {
18 | let small_ball_radius = 0.2;
19 | let mut avoid = Point3::new(0.0, 0.2, 0.0);
20 | for a in -11..11 {
21 | for b in -11..11 {
22 | let center = Point3::new(
23 | 0.9_f64.mul_add(rng.normal(), f64::from(a)),
24 | 0.2,
25 | 0.9_f64.mul_add(rng.normal(), f64::from(b)),
26 | );
27 |
28 | avoid.x = center.x;
29 |
30 | if !((0.0..0.9).contains(¢er.x.abs()) || (3.1..4.9).contains(¢er.x.abs()))
31 | || (¢er - &avoid).length() >= 0.9
32 | {
33 | let mat = rng.normal();
34 | if mat < 0.8 {
35 | let color = Color::new(rng.normal(), rng.normal(), rng.normal());
36 | let material = Lambertian::new(color);
37 | let mut sphere = Sphere::new(center, small_ball_radius, material);
38 | if need_speed {
39 | sphere = sphere.with_speed(Vec3::new(0.0, Random::range(0.0..0.5), 0.0));
40 | }
41 | world.add(sphere);
42 | } else if mat < 0.95 {
43 | let color = Color::new(
44 | rng.range(0.5..1.0),
45 | rng.range(0.5..1.0),
46 | rng.range(0.5..1.0),
47 | );
48 | let fuzz = rng.range(0.0..0.5);
49 | let material = Metal::new(color).fuzz(fuzz);
50 | world.add(Sphere::new(center, small_ball_radius, material));
51 | } else {
52 | world.add(Sphere::new(
53 | center,
54 | small_ball_radius,
55 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
56 | ));
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
63 | fn add_big_balls(world: &mut HittableList) {
64 | world.add(Sphere::new(
65 | Point3::new(0.0, 1.0, 0.0),
66 | 1.0,
67 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
68 | ));
69 |
70 | world.add(Sphere::new(
71 | Point3::new(-4.0, 1.0, 0.0),
72 | 1.0,
73 | Lambertian::new(Color::new(0.4, 0.2, 0.1)),
74 | ));
75 |
76 | world.add(Sphere::new(
77 | Point3::new(4.0, 1.0, 0.0),
78 | 1.0,
79 | Metal::new(Color::new(0.7, 0.6, 0.5)),
80 | ));
81 | }
82 |
83 | #[must_use]
84 | pub fn balls_scene(seed: Option, need_speed: bool, checker: bool) -> HittableList {
85 | let mut list = HittableList::default();
86 |
87 | if checker {
88 | list.add(Sphere::new(
89 | Point3::new(0.0, -1000.0, 0.0),
90 | 1000.0,
91 | Lambertian::new(Checker::new(
92 | Color::new(0.2, 0.3, 0.1),
93 | Color::new(0.9, 0.9, 0.9),
94 | )),
95 | ));
96 | } else {
97 | list.add(Sphere::new(
98 | Point3::new(0.0, -1000.0, 0.0),
99 | 1000.0,
100 | Lambertian::new(Color::new(0.5, 0.5, 0.5)),
101 | ));
102 | };
103 |
104 | // Ground
105 |
106 | let mut rng = if let Some(seed) = seed {
107 | SeedRandom::new(seed)
108 | } else {
109 | SeedRandom::random()
110 | };
111 |
112 | add_small_balls(&mut list, &mut rng, need_speed);
113 | add_big_balls(&mut list);
114 |
115 | list
116 | }
117 |
118 | #[must_use]
119 | pub fn balls_scene_camera(need_shutter_speed: bool) -> Camera {
120 | let mut builder = CameraBuilder::default()
121 | .look_from(Point3::new(13.0, 2.0, 3.0))
122 | .look_at(Point3::new(0.0, 0.0, 0.0))
123 | .fov(20.0)
124 | .aperture(0.1)
125 | .focus(10.0);
126 |
127 | if need_shutter_speed {
128 | builder = builder.shutter_speed(1.0);
129 | }
130 |
131 | builder.build()
132 | }
133 |
134 | #[must_use]
135 | pub fn cornell_box_scene(
136 | carton: bool, carton_rotation: bool, smoke: bool,
137 | ) -> (Camera, HittableList) {
138 | let red = Lambertian::new(Color::new(0.65, 0.05, 0.05));
139 | let green = Lambertian::new(Color::new(0.12, 0.45, 0.15));
140 | let white = Lambertian::new(Color::new(0.73, 0.73, 0.73));
141 | let light =
142 | DiffuseLight::new(Color::new(1.0, 1.0, 1.0)).multiplier(if smoke { 7.0 } else { 15.0 });
143 |
144 | let mut objects = HittableList::default();
145 |
146 | objects
147 | .add(AARect::new_yz(
148 | AARectMetrics::new(555.0, (0.0, 555.0), (0.0, 555.0)),
149 | green,
150 | ))
151 | .add(AARect::new_yz(
152 | AARectMetrics::new(0.0, (0.0, 555.0), (0.0, 555.0)),
153 | red,
154 | ))
155 | .add(AARect::new_xz(
156 | AARectMetrics::new(0.0, (0.0, 555.0), (0.0, 555.0)),
157 | white.clone(),
158 | ))
159 | .add(AARect::new_xz(
160 | AARectMetrics::new(555.0, (0.0, 555.0), (0.0, 555.0)),
161 | white.clone(),
162 | ))
163 | .add(AARect::new_xy(
164 | AARectMetrics::new(555.0, (0.0, 555.0), (0.0, 555.0)),
165 | white.clone(),
166 | ));
167 |
168 | if smoke {
169 | objects.add(AARect::new_xz(
170 | AARectMetrics::new(554.0, (113.0, 443.0), (127.0, 432.0)),
171 | light,
172 | ));
173 | } else {
174 | objects.add(AARect::new_xz(
175 | AARectMetrics::new(554.0, (213.0, 343.0), (227.0, 332.0)),
176 | light,
177 | ));
178 | }
179 |
180 | if carton {
181 | if carton_rotation {
182 | let box1 = Translation::new(
183 | AARotation::::new(
184 | Carton::new(
185 | Point3::new(0.0, 0.0, 0.0),
186 | Point3::new(165.0, 165.0, 165.0),
187 | white.clone(),
188 | ),
189 | -18.0,
190 | ),
191 | Vec3::new(130.0, 0.0, 65.0),
192 | );
193 | let box2 = Translation::new(
194 | AARotation::::new(
195 | Carton::new(
196 | Point3::new(0.0, 0.0, 0.0),
197 | Point3::new(165.0, 330.0, 165.0),
198 | white,
199 | ),
200 | 15.0,
201 | ),
202 | Vec3::new(265.0, 0.0, 295.0),
203 | );
204 | if smoke {
205 | let box1 = ConstantMedium::new(box1, Color::new(1.0, 1.0, 1.0), 0.01);
206 | let box2 = ConstantMedium::new(box2, Color::new(0.0, 0.0, 0.0), 0.01);
207 | objects.add(box1).add(box2);
208 | } else {
209 | objects.add(box1).add(box2);
210 | }
211 | } else {
212 | let box1 = Carton::new(
213 | Point3::new(130.0, 0.0, 65.0),
214 | Point3::new(295.0, 165.0, 230.0),
215 | white.clone(),
216 | );
217 | let box2 = Carton::new(
218 | Point3::new(265.0, 0.0, 295.0),
219 | Point3::new(430.0, 330.0, 460.0),
220 | white,
221 | );
222 | if smoke {
223 | let box1 = ConstantMedium::new(box1, Color::new(1.0, 1.0, 1.0), 0.01);
224 | let box2 = ConstantMedium::new(box2, Color::new(0.0, 0.0, 0.0), 0.01);
225 | objects.add(box1).add(box2);
226 | } else {
227 | objects.add(box1).add(box2);
228 | }
229 | }
230 | }
231 |
232 | let camera = CameraBuilder::default()
233 | .aspect_ratio(1.0)
234 | .fov(40.0)
235 | .look_from(Point3::new(278.0, 278.0, -800.0))
236 | .look_at(Point3::new(278.0, 278.0, 0.0))
237 | .build();
238 |
239 | (camera, objects)
240 | }
241 |
242 | pub fn all_feature_scene(seed: Option) -> (Camera, HittableList) {
243 | let time_limit = 0.0..1.0;
244 | let boxes_per_side: usize = 20;
245 | let mut rng = seed.map(SeedRandom::new).unwrap_or_default();
246 |
247 | let mut boxes1 = HittableList::default();
248 | let ground = Arc::new(Lambertian::new(Color::new(0.48, 0.83, 0.53)));
249 | for i in 0..boxes_per_side {
250 | for j in 0..boxes_per_side {
251 | let w = 100.0;
252 | let x0 = -1000.0 + i as f64 * w;
253 | let z0 = -1000.0 + j as f64 * w;
254 | let y0 = 0.0;
255 | let x1 = x0 + w;
256 | let y1 = rng.range(1.0..100.0);
257 | let z1 = z0 + w;
258 | boxes1.add(Carton::new(
259 | Point3::new(x0, y0, z0),
260 | Point3::new(x1, y1, z1),
261 | Arc::clone(&ground),
262 | ));
263 | }
264 | }
265 |
266 | let mut objects = HittableList::default();
267 | objects.add(BVH::new(boxes1, time_limit.clone()));
268 |
269 | let light = DiffuseLight::new(Color::new(1.0, 1.0, 1.0)).multiplier(7.0);
270 | objects.add(AARect::new_xz(
271 | AARectMetrics::new(554.0, (123.0, 423.0), (147.0, 412.0)),
272 | light,
273 | ));
274 |
275 | let moving_sphere = Sphere::new(
276 | Point3::new(400.0, 400.0, 200.0),
277 | 50.0,
278 | Lambertian::new(Color::new(0.7, 0.3, 0.1)),
279 | )
280 | .with_speed(Vec3::new(30.0, 0.0, 0.0));
281 | objects.add(moving_sphere);
282 |
283 | let glass_sphere = Sphere::new(
284 | Point3::new(260.0, 150.0, 45.0),
285 | 50.0,
286 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
287 | );
288 | objects.add(glass_sphere);
289 |
290 | let metal_sphere = Sphere::new(
291 | Point3::new(0.0, 150.0, 145.0),
292 | 50.0,
293 | Metal::new(Color::new(0.8, 0.8, 0.9)).fuzz(1.0),
294 | );
295 | objects.add(metal_sphere);
296 |
297 | let boundary = Sphere::new(
298 | Point3::new(360.0, 170.0, 145.0),
299 | 70.0,
300 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
301 | );
302 | objects.add(boundary);
303 | objects.add(ConstantMedium::new(
304 | Sphere::new(
305 | Point3::new(360.0, 170.0, 145.0),
306 | 70.0,
307 | Lambertian::new(Color::new(1.0, 1.0, 1.0)),
308 | ),
309 | Color::new(0.2, 0.4, 0.9),
310 | 0.2,
311 | ));
312 |
313 | objects.add(ConstantMedium::new(
314 | Sphere::new(
315 | Point3::new(0.0, 0.0, 0.0),
316 | 5000.0,
317 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
318 | ),
319 | Color::new(1.0, 1.0, 1.0),
320 | 0.0001,
321 | ));
322 |
323 | objects.add(Sphere::new(
324 | Point3::new(400.0, 200.0, 400.0),
325 | 100.0,
326 | Lambertian::new(Image::new("examples/earth-map.png").unwrap()),
327 | ));
328 |
329 | objects.add(Sphere::new(
330 | Point3::new(220.0, 280.0, 300.0),
331 | 80.0,
332 | Lambertian::new(
333 | Perlin::new(256, true)
334 | .scale(0.1)
335 | .smooth(SmoothType::HermitianCubic),
336 | ),
337 | ));
338 |
339 | let white = Arc::new(Lambertian::new(Color::new(0.73, 0.73, 0.73)));
340 | let mut boxes2 = HittableList::default();
341 | for _ in 0..1000_usize {
342 | boxes2.add(Sphere::new(
343 | Point3::new(
344 | rng.range(0.0..165.0),
345 | rng.range(0.0..165.0),
346 | rng.range(0.0..165.0),
347 | ),
348 | 10.0,
349 | Arc::clone(&white),
350 | ));
351 | }
352 |
353 | objects.add(Translation::new(
354 | AARotation::::new(BVH::new(boxes2, time_limit), 15.0),
355 | Vec3::new(-100.0, 270.0, 395.0),
356 | ));
357 |
358 | let camera = CameraBuilder::default()
359 | .look_from(Point3::new(478.0, 278.0, -600.0))
360 | .look_at(Point3::new(278.0, 278.0, 0.0))
361 | .aspect_ratio(1.0)
362 | .fov(40.0)
363 | .shutter_speed(1.0)
364 | .build();
365 |
366 | (camera, objects)
367 | }
368 |
--------------------------------------------------------------------------------
/examples/earth-map.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/7sDream/remda/a80e94528ddd70443b7faadf0853e9e8d59c71c6/examples/earth-map.png
--------------------------------------------------------------------------------
/examples/rtnw_10.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::prelude::*;
5 |
6 | fn main() {
7 | common::init_log("info");
8 |
9 | let (camera, world) = common::ray_tracing_next_week::all_feature_scene(Some(777));
10 |
11 | camera
12 | .take_photo(world)
13 | .background(|_| Color::default())
14 | .height(300)
15 | .depth(50)
16 | .samples(1000)
17 | .shot(Some("rtnw_10.ppm"))
18 | .unwrap();
19 | }
20 |
--------------------------------------------------------------------------------
/examples/rtnw_2_5.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | fn main() {
5 | common::init_log("info");
6 |
7 | // Change `77` to another number to generate different scene
8 | // Or use `None` to use random seed
9 | let (camera, world) = common::ray_tracing_next_week::motion_blur(Some(77), false);
10 |
11 | camera
12 | .take_photo(world)
13 | .height(100)
14 | .samples(100)
15 | .shot(Some("rtnw_2_5.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtnw_4_3.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | fn main() {
5 | common::init_log("info");
6 |
7 | // Change `77` to another number to generate different scene
8 | // Or use `None` to use random seed
9 | let (camera, world) = common::ray_tracing_next_week::motion_blur(Some(77), true);
10 |
11 | camera
12 | .take_photo(world)
13 | .height(500)
14 | .samples(128)
15 | .shot(Some("rtnw_4_3.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtnw_4_4.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Checker,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let checker = Checker::new(Color::new(0.2, 0.3, 0.1), Color::new(0.9, 0.9, 0.9));
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -10.0, 0.0),
16 | 10.0,
17 | Lambertian::new(checker.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 10.0, 0.0),
21 | 10.0,
22 | Lambertian::new(checker),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_4_4.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_1.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::{Perlin, SmoothType},
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, false).smooth(SmoothType::None);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_1.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::{Perlin, SmoothType},
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, false).smooth(SmoothType::LinearInterpolate);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_2.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_3.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, false);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_3.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_4.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, false).scale(4.0);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_4.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_5.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, true).scale(4.0);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_5.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_6.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, true).turbulence(7);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_6.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_5_7.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, true).scale(4.0).marble(7);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ));
24 |
25 | let camera = CameraBuilder::default()
26 | .aspect_ratio(5.0 / 3.0)
27 | .fov(20.0)
28 | .look_from(Point3::new(13.0, 2.0, 3.0))
29 | .look_at(Point3::new(0.0, 0.0, 0.0))
30 | .focus(10.0)
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(300)
36 | .samples(128)
37 | .shot(Some("rtnw_5_7.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_6_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | texture::Image,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | // Image comes from http://visibleearth.nasa.gov/view.php?id=57752
12 | let earth_texture = Image::new("examples/earth-map.png").unwrap();
13 |
14 | world
15 | .add(Sphere::new(
16 | Point3::new(0.0, 0.0, 0.0),
17 | 3.0,
18 | Lambertian::new(earth_texture),
19 | ))
20 | .add(Sphere::new(
21 | Point3::new(0.0, -1003.0, 0.0),
22 | 1000.0,
23 | Lambertian::new(Color::new(0.5, 0.5, 0.5)),
24 | ));
25 |
26 | let camera = CameraBuilder::default()
27 | .aspect_ratio(1.0)
28 | .fov(90.0)
29 | .look_from(Point3::new(0.0, 4.0, -6.0))
30 | .look_at(Point3::new(0.0, 0.0, 0.0))
31 | .build();
32 |
33 | camera
34 | .take_photo(world)
35 | .height(800)
36 | .samples(128)
37 | .shot(Some("rtnw_6_2.ppm"))
38 | .unwrap();
39 | }
40 |
--------------------------------------------------------------------------------
/examples/rtnw_7_4.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, AARect, AARectMetrics, Sphere},
4 | material::{DiffuseLight, Lambertian},
5 | prelude::*,
6 | texture::Perlin,
7 | };
8 |
9 | fn main() {
10 | let mut world = HittableList::default();
11 | let perlin = Perlin::new(256, true).scale(4.0).marble(7);
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -1000.0, 0.0),
16 | 1000.0,
17 | Lambertian::new(perlin.clone()),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 2.0, 0.0),
21 | 2.0,
22 | Lambertian::new(perlin),
23 | ))
24 | .add(AARect::new_xy(
25 | AARectMetrics::new(-2.0, (3.0, 5.0), (1.0, 3.0)),
26 | DiffuseLight::new(Color::new(1.0, 1.0, 1.0)).multiplier(4.0),
27 | ));
28 |
29 | let camera = CameraBuilder::default()
30 | .aspect_ratio(5.0 / 3.0)
31 | .fov(20.0)
32 | .look_from(Point3::new(25.0, 5.0, 7.5))
33 | .look_at(Point3::new(0.0, 2.0, 0.0))
34 | .focus(10.0)
35 | .build();
36 |
37 | camera
38 | .take_photo(world)
39 | .background(|_| Color::default())
40 | .height(300)
41 | .samples(1000)
42 | .shot(Some("rtnw_7_4.ppm"))
43 | .unwrap();
44 | }
45 |
--------------------------------------------------------------------------------
/examples/rtnw_7_4_2.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::{
5 | camera::CameraBuilder,
6 | hittable::{collection::HittableList, AARect, AARectMetrics, Sphere},
7 | material::{DiffuseLight, Lambertian},
8 | prelude::*,
9 | texture::Perlin,
10 | };
11 |
12 | fn main() {
13 | common::init_log("info");
14 |
15 | let mut world = HittableList::default();
16 | let perlin = Perlin::new(256, true).scale(4.0).marble(7);
17 |
18 | world
19 | .add(Sphere::new(
20 | Point3::new(0.0, -1000.0, 0.0),
21 | 1000.0,
22 | Lambertian::new(perlin.clone()),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(0.0, 2.0, 0.0),
26 | 2.0,
27 | Lambertian::new(perlin),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(0.0, 7.0, 0.0),
31 | 2.0,
32 | DiffuseLight::new(Color::new(1.0, 1.0, 1.0)).multiplier(4.0),
33 | ))
34 | .add(AARect::new_xy(
35 | AARectMetrics::new(-2.0, (3.0, 5.0), (1.0, 3.0)),
36 | DiffuseLight::new(Color::new(1.0, 1.0, 1.0)).multiplier(4.0),
37 | ));
38 |
39 | let camera = CameraBuilder::default()
40 | .aspect_ratio(5.0 / 3.0)
41 | .fov(20.0)
42 | .look_from(Point3::new(25.0, 5.0, 7.5))
43 | .look_at(Point3::new(0.0, 2.0, 0.0))
44 | .focus(10.0)
45 | .build();
46 |
47 | camera
48 | .take_photo(world)
49 | .background(|_| Color::default())
50 | .height(300)
51 | .samples(1000)
52 | .shot(Some("rtnw_7_4_2.ppm"))
53 | .unwrap();
54 | }
55 |
--------------------------------------------------------------------------------
/examples/rtnw_7_6.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::prelude::*;
5 |
6 | fn main() {
7 | let (camera, world) = common::ray_tracing_next_week::empty_cornell_box();
8 |
9 | camera
10 | .take_photo(world)
11 | .background(|_| Color::default())
12 | .height(300)
13 | .depth(50)
14 | .samples(1000)
15 | .shot(Some("rtnw_7_6.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtnw_8_0.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::prelude::*;
5 |
6 | fn main() {
7 | let (camera, world) = common::ray_tracing_next_week::cornell_box_no_rotation();
8 |
9 | camera
10 | .take_photo(world)
11 | .background(|_| Color::default())
12 | .height(300)
13 | .depth(50)
14 | .samples(1000)
15 | .shot(Some("rtnw_8_0.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtnw_8_1.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::{
5 | camera::CameraBuilder,
6 | hittable::{collection::HittableList, transform::Translation, Carton},
7 | material::Lambertian,
8 | prelude::*,
9 | };
10 |
11 | fn main() {
12 | let camera = CameraBuilder::default()
13 | .look_from(Point3::new(-1.0, 1.5, 2.0))
14 | .look_at(Point3::new(0.0, 0.0, 0.5))
15 | .build();
16 |
17 | let mut world = HittableList::default();
18 | let carton_at_origin = Carton::new(
19 | Point3::new(-0.5, 0.0, -0.5),
20 | Point3::new(0.5, 1.0, 0.5),
21 | Lambertian::new(Color::new(0.2, 0.2, 0.2)),
22 | );
23 | let carton_moved = Translation::new(carton_at_origin.clone(), Vec3::new(2.0, 0.0, 0.0));
24 | world.add(carton_at_origin).add(carton_moved);
25 |
26 | camera
27 | .take_photo(world)
28 | .height(480)
29 | .samples(512)
30 | .shot(Some("rtnw_8_1.ppm"))
31 | .unwrap();
32 | }
33 |
--------------------------------------------------------------------------------
/examples/rtnw_8_2.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::prelude::*;
5 |
6 | fn main() {
7 | common::init_log("info");
8 |
9 | let (camera, world) = common::ray_tracing_next_week::cornell_box();
10 |
11 | camera
12 | .take_photo(world)
13 | .background(|_| Color::default())
14 | .height(300)
15 | .depth(50)
16 | .samples(1000)
17 | .shot(Some("rtnw_8_2.ppm"))
18 | .unwrap();
19 | }
20 |
--------------------------------------------------------------------------------
/examples/rtnw_9_2.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | use remda::prelude::*;
5 |
6 | fn main() {
7 | common::init_log("info");
8 |
9 | let (camera, world) = common::ray_tracing_next_week::cornell_box_smoke();
10 |
11 | camera
12 | .take_photo(world)
13 | .background(|_| Color::default())
14 | .height(300)
15 | .depth(50)
16 | .samples(1000)
17 | .shot(Some("rtnw_9_2.ppm"))
18 | .unwrap();
19 | }
20 |
--------------------------------------------------------------------------------
/examples/rtow_10_3.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Dielectric, Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.1, 0.2, 0.5)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5),
33 | ));
34 |
35 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
36 |
37 | camera
38 | .take_photo(world)
39 | .height(100)
40 | .samples(100)
41 | .shot(Some("rtow_10_3.ppm"))
42 | .unwrap();
43 | }
44 |
--------------------------------------------------------------------------------
/examples/rtow_10_5.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Dielectric, Glass, Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.1, 0.2, 0.5)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)).fuzz(0.3),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
33 | ))
34 | .add(Sphere::new(
35 | Point3::new(-1.0, 0.0, -1.0),
36 | -0.45,
37 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
38 | ));
39 |
40 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
41 |
42 | camera
43 | .take_photo(world)
44 | .height(100)
45 | .samples(100)
46 | .shot(Some("rtow_10_5.ppm"))
47 | .unwrap();
48 | }
49 |
--------------------------------------------------------------------------------
/examples/rtow_11_1.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | let r = (PI / 4.0).cos();
14 |
15 | world
16 | .add(Sphere::new(
17 | Point3::new(-r, 0.0, -1.0),
18 | r,
19 | Lambertian::new(Color::new(0.0, 0.0, 1.0)),
20 | ))
21 | .add(Sphere::new(
22 | Point3::new(r, 0.0, -1.0),
23 | r,
24 | Lambertian::new(Color::new(1.0, 0.0, 0.0)),
25 | ));
26 |
27 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
28 |
29 | camera
30 | .take_photo(world)
31 | .height(100)
32 | .samples(100)
33 | .shot(Some("rtow_11_1.ppm"))
34 | .unwrap();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/rtow_11_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Dielectric, Glass, Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.1, 0.2, 0.5)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
33 | ))
34 | .add(Sphere::new(
35 | Point3::new(-1.0, 0.0, -1.0),
36 | -0.45,
37 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
38 | ));
39 |
40 | let camera = CameraBuilder::default()
41 | .look_from(Point3::new(-2.0, 2.0, 1.0))
42 | .aspect_ratio(2.0)
43 | .build();
44 |
45 | camera
46 | .take_photo(world)
47 | .height(100)
48 | .samples(100)
49 | .shot(Some("rtow_11_2.ppm"))
50 | .unwrap();
51 | }
52 |
--------------------------------------------------------------------------------
/examples/rtow_11_2_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Dielectric, Glass, Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.1, 0.2, 0.5)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
33 | ))
34 | .add(Sphere::new(
35 | Point3::new(-1.0, 0.0, -1.0),
36 | -0.45,
37 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
38 | ));
39 |
40 | let camera = CameraBuilder::default()
41 | .look_from(Point3::new(-2.0, 2.0, 1.0))
42 | .fov(20.0)
43 | .aspect_ratio(2.0)
44 | .build();
45 |
46 | camera
47 | .take_photo(world)
48 | .height(100)
49 | .samples(100)
50 | .shot(Some("rtow_11_2_2.ppm"))
51 | .unwrap();
52 | }
53 |
--------------------------------------------------------------------------------
/examples/rtow_12_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Dielectric, Glass, Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.1, 0.2, 0.5)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
33 | ))
34 | .add(Sphere::new(
35 | Point3::new(-1.0, 0.0, -1.0),
36 | -0.45,
37 | Dielectric::new(Color::new(1.0, 1.0, 1.0), 1.5).reflect_curve(Glass {}),
38 | ));
39 |
40 | let camera = CameraBuilder::default()
41 | .look_from(Point3::new(3.0, 3.0, 2.0))
42 | .fov(20.0)
43 | .focus_to_look_at()
44 | .aperture(2.0)
45 | .aspect_ratio(2.0)
46 | .build();
47 |
48 | camera
49 | .take_photo(world)
50 | .height(100)
51 | .samples(100)
52 | .shot(Some("rtow_12_2.ppm"))
53 | .unwrap();
54 | }
55 |
--------------------------------------------------------------------------------
/examples/rtow_13_1.rs:
--------------------------------------------------------------------------------
1 | #[allow(dead_code)]
2 | mod common;
3 |
4 | fn main() {
5 | common::init_log("info");
6 |
7 | // Change `7` to another number to generate different scene
8 | // Or use `None` to use random seed
9 | let (camera, world) = common::ray_tracing_in_one_weekend::final_scene(Some(7));
10 |
11 | camera
12 | .take_photo(world)
13 | .height(108)
14 | .samples(128)
15 | .shot(Some("rtow_13_1.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtow_2_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{painter::Painter, prelude::*};
2 |
3 | fn main() {
4 | env_logger::init();
5 |
6 | Painter::new(256, 256)
7 | .gamma(false)
8 | .samples(1)
9 | .draw(&Some("rtow_2_2.ppm"), |u, v| Vec3::new(u, v, 0.25))
10 | .unwrap()
11 | }
12 |
--------------------------------------------------------------------------------
/examples/rtow_4_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{camera::CameraBuilder, hittable::collection::HittableList};
2 |
3 | fn main() {
4 | env_logger::init();
5 |
6 | let world = HittableList::default();
7 |
8 | let camera = CameraBuilder::default().build();
9 |
10 | camera
11 | .take_photo(world)
12 | .height(432)
13 | .gamma(false)
14 | .samples(1)
15 | .shot(Some("rtow_4_2.ppm"))
16 | .unwrap();
17 | }
18 |
--------------------------------------------------------------------------------
/examples/rtow_5_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{camera::CameraBuilder, hittable::collection::HittableList, prelude::*};
2 |
3 | fn hit_sphere(center: &Point3, radius: f64, ray: &Ray) -> bool {
4 | let oc = &ray.origin - center;
5 | let a = ray.direction.length_squared();
6 | let b = 2.0 * oc.dot(&ray.direction);
7 | let c = oc.length_squared() - radius * radius;
8 | let discriminant = b * b - 4.0 * a * c;
9 | discriminant > 0.0
10 | }
11 |
12 | fn background(ray: &Ray) -> Color {
13 | if hit_sphere(&Point3::new(0.0, 0.0, -1.0), 0.5, ray) {
14 | return Color::new(1.0, 0.0, 0.0);
15 | }
16 | remda::hittable::collection::world_default_background(ray)
17 | }
18 |
19 | fn main() {
20 | env_logger::init();
21 |
22 | let world = HittableList::default();
23 |
24 | let camera = CameraBuilder::default().build();
25 |
26 | camera
27 | .take_photo(world)
28 | .background(background)
29 | .height(432)
30 | .gamma(false)
31 | .samples(1)
32 | .shot(Some("rtow_5_2.ppm"))
33 | .unwrap();
34 | }
35 |
--------------------------------------------------------------------------------
/examples/rtow_6_1.rs:
--------------------------------------------------------------------------------
1 | use remda::{camera::CameraBuilder, hittable::collection::HittableList, prelude::*};
2 |
3 | fn hit_sphere(center: &Point3, radius: f64, ray: &Ray) -> Option {
4 | let oc = &ray.origin - center;
5 | let a = ray.direction.length_squared();
6 | let b = 2.0 * oc.dot(&ray.direction);
7 | let c = oc.length_squared() - radius * radius;
8 | let discriminant = b * b - 4.0 * a * c;
9 | if discriminant < 0.0 {
10 | None
11 | } else {
12 | Some((-b - discriminant.sqrt()) / (2.0 * a))
13 | }
14 | }
15 |
16 | fn background(ray: &Ray) -> Color {
17 | if let Some(t) = hit_sphere(&Point3::new(0.0, 0.0, -1.0), 0.5, ray) {
18 | if t > 0.0 {
19 | let n = (ray.position_after(t) - Vec3::new(0.0, 0.0, -1.0)).unit();
20 | return (0.5 * (n + Vec3::new(1.0, 1.0, 1.0))).into_color(1, false);
21 | }
22 | }
23 | let unit = ray.direction.unit();
24 | let t = 0.5 * (unit.y + 1.0);
25 | Color::new(1.0, 1.0, 1.0).gradient(&Color::new(0.5, 0.7, 1.0), t)
26 | }
27 |
28 | fn main() {
29 | env_logger::init();
30 |
31 | let world = HittableList::default();
32 |
33 | let camera = CameraBuilder::default().build();
34 |
35 | camera
36 | .take_photo(world)
37 | .background(background)
38 | .height(432)
39 | .gamma(false)
40 | .samples(1)
41 | .shot(Some("rtow_6_1.ppm"))
42 | .unwrap();
43 | }
44 |
--------------------------------------------------------------------------------
/examples/rtow_6_7.rs:
--------------------------------------------------------------------------------
1 | use remda::{camera::CameraBuilder, hittable::collection::HittableList, prelude::*};
2 |
3 | fn hit_sphere(center: &Point3, radius: f64, ray: &Ray) -> Option<(f64, Vec3)> {
4 | let oc = &ray.origin - center;
5 | let a = ray.direction.length_squared();
6 | let half_b = oc.dot(&ray.direction);
7 | let c = oc.length_squared() - radius * radius;
8 | #[allow(clippy::suspicious_operation_groupings)]
9 | let discriminant = half_b * half_b - a * c;
10 | if discriminant < 0.0 {
11 | None
12 | } else {
13 | let t1 = (-half_b - discriminant.sqrt()) / a;
14 | let t2 = (-half_b + discriminant.sqrt()) / a;
15 | if t1 > 0.0 {
16 | let p = ray.position_after(t1);
17 | let n = (p - center) / radius;
18 | Some((t1, n))
19 | } else if t2 > 0.0 {
20 | let p = ray.position_after(t2);
21 | let n = (p - center) / radius;
22 | Some((t2, n))
23 | } else {
24 | None
25 | }
26 | }
27 | }
28 |
29 | fn background(ray: &Ray) -> Color {
30 | let ts = vec![
31 | hit_sphere(&Point3::new(0.0, 0.0, -1.0), 0.5, ray),
32 | hit_sphere(&Point3::new(0.0, -100.5, -1.0), 100.0, ray),
33 | ];
34 | if let Some((_, n)) = ts
35 | .into_iter()
36 | .flatten()
37 | .min_by(|a, b| a.0.partial_cmp(&b.0).unwrap())
38 | {
39 | return (0.5 * (n + Vec3::new(1.0, 1.0, 1.0))).into_color(1, false);
40 | }
41 | let unit = ray.direction.unit();
42 | let t = 0.5 * (unit.y + 1.0);
43 | Color::new(1.0, 1.0, 1.0).gradient(&Color::new(0.5, 0.7, 1.0), t)
44 | }
45 |
46 | fn main() {
47 | env_logger::init();
48 |
49 | let world = HittableList::default();
50 |
51 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
52 |
53 | camera
54 | .take_photo(world)
55 | .background(background)
56 | .height(100)
57 | .gamma(false)
58 | .samples(1)
59 | .shot(Some("rtow_6_7.ppm"))
60 | .unwrap();
61 | }
62 |
--------------------------------------------------------------------------------
/examples/rtow_7_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{camera::CameraBuilder, hittable::collection::HittableList, prelude::*};
2 |
3 | fn hit_sphere(center: &Point3, radius: f64, ray: &Ray) -> Option<(f64, Vec3)> {
4 | let oc = &ray.origin - center;
5 | let a = ray.direction.length_squared();
6 | let half_b = oc.dot(&ray.direction);
7 | let c = oc.length_squared() - radius * radius;
8 | #[allow(clippy::suspicious_operation_groupings)]
9 | let discriminant = half_b * half_b - a * c;
10 | if discriminant < 0.0 {
11 | None
12 | } else {
13 | let t1 = (-half_b - discriminant.sqrt()) / a;
14 | let t2 = (-half_b + discriminant.sqrt()) / a;
15 | if t1 > 0.0 {
16 | let p = ray.position_after(t1);
17 | let n = (p - center) / radius;
18 | Some((t1, n))
19 | } else if t2 > 0.0 {
20 | let p = ray.position_after(t2);
21 | let n = (p - center) / radius;
22 | Some((t2, n))
23 | } else {
24 | None
25 | }
26 | }
27 | }
28 |
29 | fn background(ray: &Ray) -> Color {
30 | let ts = vec![
31 | hit_sphere(&Point3::new(0.0, 0.0, -1.0), 0.5, ray),
32 | hit_sphere(&Point3::new(0.0, -100.5, -1.0), 100.0, ray),
33 | ];
34 | if let Some((_, n)) = ts
35 | .into_iter()
36 | .flatten()
37 | .min_by(|a, b| a.0.partial_cmp(&b.0).unwrap())
38 | {
39 | return (0.5 * (n + Vec3::new(1.0, 1.0, 1.0))).into_color(1, false);
40 | }
41 | let unit = ray.direction.unit();
42 | let t = 0.5 * (unit.y + 1.0);
43 | Color::new(1.0, 1.0, 1.0).gradient(&Color::new(0.5, 0.7, 1.0), t)
44 | }
45 |
46 | fn main() {
47 | env_logger::init();
48 |
49 | let world = HittableList::default();
50 |
51 | let camera = CameraBuilder::default()
52 | .look_from(Point3::new(-0.5, 0.0, -0.7))
53 | .look_at(Point3::new(-0.5, 0.0, -1.0))
54 | .aspect_ratio(39.0 / 36.0)
55 | .build();
56 |
57 | camera
58 | .take_photo(world)
59 | .background(background)
60 | .height(36)
61 | .gamma(false)
62 | .samples(100)
63 | .shot(Some("rtow_7_2.ppm"))
64 | .unwrap();
65 | }
66 |
--------------------------------------------------------------------------------
/examples/rtow_8_2.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Lambertian, LambertianMathType},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Approximates),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Approximates),
23 | ));
24 |
25 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
26 |
27 | camera
28 | .take_photo(world)
29 | .height(100)
30 | .gamma(false)
31 | .samples(100)
32 | .shot(Some("rtow_8_2.ppm"))
33 | .unwrap();
34 | }
35 |
--------------------------------------------------------------------------------
/examples/rtow_8_3.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Lambertian, LambertianMathType},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Approximates),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Approximates),
23 | ));
24 |
25 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
26 |
27 | camera
28 | .take_photo(world)
29 | .height(100)
30 | .samples(100)
31 | .shot(Some("rtow_8_3.ppm"))
32 | .unwrap();
33 | }
34 |
--------------------------------------------------------------------------------
/examples/rtow_8_5.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::Lambertian,
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.5, 0.5, 0.5)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.5, 0.5, 0.5)),
23 | ));
24 |
25 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
26 |
27 | camera
28 | .take_photo(world)
29 | .height(100)
30 | .samples(100)
31 | .shot(Some("rtow_8_5.ppm"))
32 | .unwrap();
33 | }
34 |
--------------------------------------------------------------------------------
/examples/rtow_8_6.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Lambertian, LambertianMathType},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Hemisphere),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.5, 0.5, 0.5)).math_type(LambertianMathType::Hemisphere),
23 | ));
24 |
25 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
26 |
27 | camera
28 | .take_photo(world)
29 | .height(100)
30 | .samples(100)
31 | .shot(Some("rtow_8_6.ppm"))
32 | .unwrap();
33 | }
34 |
--------------------------------------------------------------------------------
/examples/rtow_9_5.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.7, 0.3, 0.3)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Metal::new(Color::new(0.8, 0.8, 0.8)),
33 | ));
34 |
35 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
36 |
37 | camera
38 | .take_photo(world)
39 | .height(100)
40 | .samples(100)
41 | .shot(Some("rtow_9_5.ppm"))
42 | .unwrap();
43 | }
44 |
--------------------------------------------------------------------------------
/examples/rtow_9_6.rs:
--------------------------------------------------------------------------------
1 | use remda::{
2 | camera::CameraBuilder,
3 | hittable::{collection::HittableList, Sphere},
4 | material::{Lambertian, Metal},
5 | prelude::*,
6 | };
7 |
8 | fn main() {
9 | env_logger::init();
10 |
11 | let mut world = HittableList::default();
12 |
13 | world
14 | .add(Sphere::new(
15 | Point3::new(0.0, -100.5, -1.0),
16 | 100.0,
17 | Lambertian::new(Color::new(0.8, 0.8, 0.0)),
18 | ))
19 | .add(Sphere::new(
20 | Point3::new(0.0, 0.0, -1.0),
21 | 0.5,
22 | Lambertian::new(Color::new(0.7, 0.3, 0.3)),
23 | ))
24 | .add(Sphere::new(
25 | Point3::new(1.0, 0.0, -1.0),
26 | 0.5,
27 | Metal::new(Color::new(0.8, 0.6, 0.2)).fuzz(1.0),
28 | ))
29 | .add(Sphere::new(
30 | Point3::new(-1.0, 0.0, -1.0),
31 | 0.5,
32 | Metal::new(Color::new(0.8, 0.8, 0.8)).fuzz(0.3),
33 | ));
34 |
35 | let camera = CameraBuilder::default().aspect_ratio(2.0).build();
36 |
37 | camera
38 | .take_photo(world)
39 | .height(100)
40 | .samples(100)
41 | .shot(Some("rtow_9_6.ppm"))
42 | .unwrap();
43 | }
44 |
--------------------------------------------------------------------------------
/examples/rtrl_2_1.rs:
--------------------------------------------------------------------------------
1 | use remda::prelude::*;
2 |
3 | const N: usize = 1000;
4 |
5 | fn main() {
6 | let mut inside_circle: u64 = 0;
7 | for _ in 0..N {
8 | let x: f64 = Random::range(-1.0..1.0);
9 | let y: f64 = Random::range(-1.0..1.0);
10 | if x.powi(2) + y.powi(2) <= 1.0 {
11 | inside_circle += 1;
12 | }
13 | }
14 | println!(
15 | "Estimate of Pi = {:.12}",
16 | 4.0 * inside_circle as f64 / N as f64
17 | );
18 | }
19 |
--------------------------------------------------------------------------------
/examples/rtrl_2_2.rs:
--------------------------------------------------------------------------------
1 | use remda::prelude::*;
2 |
3 | fn main() {
4 | let mut runs: u64 = 0;
5 | let mut inside_circle: u64 = 0;
6 | loop {
7 | runs += 1;
8 | let x: f64 = Random::range(-1.0..1.0);
9 | let y: f64 = Random::range(-1.0..1.0);
10 | if x.powi(2) + y.powi(2) <= 1.0 {
11 | inside_circle += 1;
12 | }
13 | if runs % 100000 == 0 {
14 | println!(
15 | "Estimate of Pi = {:.12}",
16 | 4.0 * inside_circle as f64 / runs as f64
17 | );
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/rtrl_2_3.rs:
--------------------------------------------------------------------------------
1 | use remda::prelude::*;
2 |
3 | const GRID_LINE_PRE_SIDE: u64 = 10000;
4 |
5 | fn main() {
6 | let mut inside_circle: u64 = 0;
7 | let mut inside_circle_stratified: u64 = 0;
8 |
9 | for i in 0..GRID_LINE_PRE_SIDE {
10 | for j in 0..GRID_LINE_PRE_SIDE {
11 | let x: f64 = Random::range(-1.0..1.0);
12 | let y: f64 = Random::range(-1.0..1.0);
13 | if x.powi(2) + y.powi(2) <= 1.0 {
14 | inside_circle += 1;
15 | }
16 |
17 | let x = -1.0 + 2.0 * (j as f64 + Random::normal()) / GRID_LINE_PRE_SIDE as f64;
18 | let y = -1.0 + 2.0 * (i as f64 + Random::normal()) / GRID_LINE_PRE_SIDE as f64;
19 | if x.powi(2) + y.powi(2) <= 1.0 {
20 | inside_circle_stratified += 1;
21 | }
22 | }
23 | }
24 |
25 | println!(
26 | "Regular Estimate of Pi = {:.12}",
27 | 4.0 * inside_circle as f64 / (GRID_LINE_PRE_SIDE as f64).powi(2)
28 | );
29 | println!(
30 | "Stratified Estimate of Pi = {:.12}",
31 | 4.0 * inside_circle_stratified as f64 / (GRID_LINE_PRE_SIDE as f64).powi(2)
32 | );
33 | }
34 |
--------------------------------------------------------------------------------
/examples/rtrl_3_1.rs:
--------------------------------------------------------------------------------
1 | use remda::prelude::*;
2 |
3 | const N: u64 = 1000000;
4 |
5 | // Calculate \int_{0}^{2}x^2
6 | // Which is 8/3
7 |
8 | fn main() {
9 | let mut sum: f64 = 0.0;
10 |
11 | for _ in 0..N {
12 | sum += Random::range(0.0..2.0_f64).powi(2);
13 | }
14 |
15 | println!("I = {:.12}", 2.0 * sum / N as f64,);
16 | }
17 |
--------------------------------------------------------------------------------
/examples/rtrl_3_3.rs:
--------------------------------------------------------------------------------
1 | use remda::prelude::*;
2 |
3 | const N: u64 = 1000000;
4 |
5 | // Calculate \int_{0}^{2}x^2
6 | // Which is 8/3
7 |
8 | fn pdf(x: f64) -> f64 {
9 | 0.5 * x
10 | }
11 |
12 | // pdf = 0.5x
13 | // P(x) = \int_{0}^{x} 0.5r dr = 1/4 * x^2
14 | // We use x = \sqrt{4 * y} to generate x
15 | // where y is uniform distribution in range [0, 1]
16 | fn generate_x() -> f64 {
17 | Random::range(0.0..4.0f64).sqrt()
18 | }
19 |
20 | fn main() {
21 | let mut sum: f64 = 0.0;
22 |
23 | for _ in 0..N {
24 | let x = generate_x();
25 | sum += x * x / pdf(x);
26 | }
27 |
28 | println!("I = {:.12}", sum / N as f64,);
29 | }
30 |
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | edition = "2018"
2 | fn_args_layout = "Compressed"
3 | newline_style = "Unix"
4 | use_field_init_shorthand = true
5 | use_small_heuristics = "Default"
6 | use_try_shorthand = true
7 |
--------------------------------------------------------------------------------
/src/camera.rs:
--------------------------------------------------------------------------------
1 | use {
2 | crate::{
3 | hittable::{
4 | collection::{HittableList, World},
5 | Hittable,
6 | },
7 | painter::Painter,
8 | prelude::*,
9 | },
10 | std::path::Path,
11 | };
12 |
13 | #[derive(Debug)]
14 | pub struct Camera {
15 | origin: Point3,
16 | lb: Point3,
17 | horizontal_full: Vec3,
18 | vertical_full: Vec3,
19 | horizontal_unit: Vec3,
20 | vertical_unit: Vec3,
21 | aspect_ratio: f64,
22 | aperture: f64,
23 | shutter_speed: f64,
24 | }
25 |
26 | impl Camera {
27 | #[allow(clippy::too_many_arguments, clippy::needless_pass_by_value)] // internal
28 | pub(self) fn new(
29 | look_from: &Point3, look_at: &Point3, vup: &Vec3, fov: f64, aspect_ratio: f64,
30 | aperture: f64, focus_distance: f64, shutter_speed: f64,
31 | ) -> Self {
32 | let fov = fov.to_radians();
33 | let h = (fov / 2.0).tan();
34 | let vh = 2.0 * h;
35 | let vw = vh * aspect_ratio;
36 |
37 | let w = (look_at - look_from).unit();
38 | let horizontal_unit = w.cross(vup).unit();
39 | let vertical_unit = horizontal_unit.cross(&w).unit();
40 |
41 | let horizontal_full = focus_distance * vw * &horizontal_unit;
42 | let vertical_full = focus_distance * vh * &vertical_unit;
43 | let lb = look_from - &horizontal_full / 2.0 - &vertical_full / 2.0 + focus_distance * w;
44 | Self {
45 | origin: look_from.clone(),
46 | lb,
47 | horizontal_full,
48 | vertical_full,
49 | horizontal_unit,
50 | vertical_unit,
51 | aspect_ratio,
52 | aperture,
53 | shutter_speed,
54 | }
55 | }
56 |
57 | #[must_use]
58 | pub fn ray(&self, u: f64, v: f64) -> Ray {
59 | let rd = self.aperture / 2.0 * Vec3::random_unit_disk();
60 | let offset = &self.horizontal_unit * rd.x + &self.vertical_unit * rd.y;
61 | let origin = &self.origin + offset;
62 | let direction = &self.lb + u * &self.horizontal_full + v * &self.vertical_full - &origin;
63 |
64 | Ray::new(origin, direction, self.shutter_speed * Random::normal())
65 | }
66 |
67 | #[must_use]
68 | pub fn take_photo(&self, world: HittableList) -> TakePhotoSettings<'_> {
69 | let world = World::new(world, 0.0..self.shutter_speed);
70 | TakePhotoSettings::new(self, world)
71 | }
72 | }
73 |
74 | #[derive(Debug)]
75 | pub struct TakePhotoSettings<'c> {
76 | camera: &'c Camera,
77 | world: World,
78 | depth: usize,
79 | picture_height: usize,
80 | gamma: bool,
81 | samples: usize,
82 | threads: usize,
83 | parallel: bool,
84 | }
85 |
86 | impl<'c> TakePhotoSettings<'c> {
87 | #[must_use]
88 | pub const fn new(camera: &'c Camera, world: World) -> Self {
89 | Self {
90 | camera,
91 | world,
92 | depth: 8,
93 | picture_height: 108,
94 | gamma: true,
95 | samples: 50,
96 | threads: 0,
97 | parallel: true,
98 | }
99 | }
100 |
101 | pub fn background Color + Send + Sync + 'static>(mut self, bg: BG) -> Self {
102 | self.world.set_bg(bg);
103 | self
104 | }
105 |
106 | #[must_use]
107 | pub const fn depth(mut self, depth: usize) -> Self {
108 | self.depth = depth;
109 | self
110 | }
111 |
112 | #[must_use]
113 | pub const fn height(mut self, height: usize) -> Self {
114 | self.picture_height = height;
115 | self
116 | }
117 |
118 | #[must_use]
119 | pub const fn gamma(mut self, gamma: bool) -> Self {
120 | self.gamma = gamma;
121 | self
122 | }
123 |
124 | #[must_use]
125 | pub const fn samples(mut self, samples: usize) -> Self {
126 | self.samples = samples;
127 | self
128 | }
129 |
130 | #[must_use]
131 | pub const fn threads(mut self, threads: usize) -> Self {
132 | self.threads = threads;
133 | self
134 | }
135 |
136 | #[must_use]
137 | pub const fn parallel(mut self, parallel: bool) -> Self {
138 | self.parallel = parallel;
139 | self
140 | }
141 |
142 | fn ray_color(ray: &Ray, world: &World, depth: usize) -> Vec3 {
143 | if depth == 0 {
144 | return Vec3::default();
145 | }
146 |
147 | if let Some(hit) = world.hit(ray, 0.001..f64::INFINITY) {
148 | let material = hit.material;
149 | let emitted = material
150 | .emitted(hit.u, hit.v, &hit.point)
151 | .unwrap_or_default();
152 | if let Some(scattered) = material.scatter(ray, hit) {
153 | return emitted
154 | + scattered.color * Self::ray_color(&scattered.ray, world, depth - 1);
155 | }
156 | return emitted;
157 | }
158 |
159 | world.background(ray).into()
160 | }
161 |
162 | /// # Errors
163 | /// When open or save to file failed
164 | #[allow(clippy::needless_pass_by_value)] // Directly used public API, add & will make it harder to use
165 | pub fn shot>(&self, path: Option