Monte Carlo ray tracer in Rust

栏目: IT技术 · 发布时间: 4年前

内容简介:This is a Rust implementation of the ray-tracer from Peter Shirley's excellentThis is not by any means a fully featured ray-tracer. Rather, this is something I built in order to learn Rust and ray-tracing. I am sharing it in case it is useful to others try

Rayt

Monte Carlo ray tracer in Rust Monte Carlo ray tracer in Rust

This is a Rust implementation of the ray-tracer from Peter Shirley's excellent books , Ray Tracing in One Weekend , Ray Tracing: The Next Week , and Ray Tracing: The Rest of Your Life .

This is not by any means a fully featured ray-tracer. Rather, this is something I built in order to learn Rust and ray-tracing. I am sharing it in case it is useful to others trying to do the same.

Functionality

Rayt stores and reads scene data in its own format using yaml files. Those are nothing more than a yaml serialisation of the corresponding Rust objects.

There are two modes of operation described in more detail in the next section.

generate
render

Various examples from the books are provided in the form of scenes. The generate mode can be used to quickly regenerate the config files after making changes to them in the code, but for small scenes the files can be easily directly edited as well.

How to run

This code was developed and tested using Rust 1.42 , however it is not using any bleeding edge features of the language so any reasonably recent stable version should be enough to compile it.

To install the binary in your local environment:

cargo install --path ${PATH_TO_THIS_REPO}

Help:

rayt --help
rayt generate --help
rayt render --help

Generate the Cornell box scene yaml file:

rayt --config config/cornell_box.yaml generate --scene CornellBox

To render the Cornell box:

rayt --config config/cornell_box.yaml \
    render --width 512 --rays 1000 --threads 8 --output output/cornell_box.png

Some scenes use assets as textures, for example the final scene from the Ray Tracing: The Next Week book. These assets can be passed in using --asset :

rayt --config config/next_week_final.yaml \
    render --width 512 --rays 1000 --threads 8 --asset assets/earth.jpg --output output/next_week_final.png

The option --threads can be used to control how many threads the renderer should use and the option --rays will determine how many rays (samples) will be taken for each pixel. Approximately 1000 samples should be enough to produce a decent image with some noise from the provided scenes, but more are needed for a clear image. The rendering times will increase quite significantly with the number of samples selected and the size of the image. On my machine rendering next_week_final.yaml with 5000 samples, and a width of 1024 pixels took around 9 hours. Conversely, the cornell_box.yaml with a 1000 samples, and a width of 512 finishes in a few minutes.

A Makefile is included with some convenience targets:

  • make regenerate-scenes will create all the scene config yaml files
  • make render-test will render all scenes using a moderate resolution and number of rays and put the generated images in output/test
  • make cornell-test is the same as make render-test , but only for the Cornell box
  • make regenerate-samples will create high-resolution / high-ray-count versions of the Cornell box and the final image from book 2 and put them in output/samples

Samples

The directory samples contains images generated with a high number of rays, specifically 5000 rays per pixel, to showcase what kinds of images rayt can render.

Assets

The included assets were taken from the following sources:

License

See the LICENSE file that is included with this repository.


以上所述就是小编给大家介绍的《Monte Carlo ray tracer in Rust》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

游戏编程中的人工智能技术

游戏编程中的人工智能技术

布克兰德 / 吴祖增 / 清华大学出版社 / 2006-5 / 39.0

《游戏编程中的人工智能技术》是人工智能游戏编程的一本指南性读物,介绍在游戏开发中怎样应用遗传算法和人工神经网络来创建电脑游戏中所需要的人工智能。书中包含了许多实用例子,所有例子的完整源码和可执行程序都能在随书附带的光盘上找到。光盘中还有不少其他方面的游戏开发资料和一个赛车游戏演示软件。 《游戏编程中的人工智能技术》适合遗传算法和人工神经网络等人工智能技术的各行业人员,特别是要实际动手做应用开......一起来看看 《游戏编程中的人工智能技术》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具