Skip to content

hadeaninc/rust-raytracer-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-tracer-example

"Ray tracing in one weekend" implementation in Rust that runs distributed on the cloud with Hadean. Forked from this implementation.

Makes use of:

  • Hadean for distributing on the cloud
  • futures::executor and crossbeam for multicore
  • bvh for raytracing acceleration
  • glam for math
  • minifb for windowed output

Final render

Build

ln -s ~/.hadean/sdk/crates/hadean hadean-sdk-symlink to set up a symlink to the Hadean SDK crate which Cargo.toml is configured to use. If you don't have the Hadean SDK you can need to remove the line from your Cargo.toml - unfortunately Cargo doesn't support optional dependencies without checking they exist!

cargo build --release to build the application. Release builds recommended for speed!

Local Usage

cargo run --release -- serve to run the web server on a single machine.

cargo run --release --features gui -- window to run the windowed GUI on a single machine.

Note - if you are running under WSL, you will need to ensure that you have an X-server running. You also may need to get gcc, g++ and pkg-config from your package manager.

Running with Hadean

Hadean allows you to run your application locally or distributed on the cloud, with no recompilation. First you need the Hadean SDK. Once you've got it:

$ cargo build --features 'distributed'
[...]
$ hadean run --config hadean-config.toml target/release/hadean-raytracer serve
[2021-09-14T17:17:42Z INFO ] Starting application...
[2021-09-14T17:17:42Z INFO ] 127.0.0.1.18004.0: Server starting on 0.0.0.0:28888
[...]

You can now visit the rendering interface webpage at http://localhost:28888!

Running on a Hadean Cluster

For this you'll need a remote cluster configured for use with the Hadean Platform SDK which is explained here.

For this specific repository the deploy and run commands are structured like this:

hadean cluster -n <cluster name> deploy ./target/release/hadean-raytracer to deploy the application to the remote cluster.

hadean cluster -n <cluster name> run ./hadean-config.toml to run the application on the remote cluster. This is configured to run as a web server.

If you want to scale this beyond one machine, change the line in src/main.rs that says let cpus = num_cpus::get() - 1; to let cpus = 14; and watch it scale up! Note that machines can take a while to start up on the cloud - you'll know when more than one machine is in use because your web server will list multiple IP addresses in the cluster status.

Viewing the remote web server's output

To see the output of a remote raytracer run you'll need to grab the IP address of the machine that is running the web server. This can be obtained from the messages printed out by the remote run. The first line of a remote run looks like this:

[2021-09-14T15:13:17Z INFO ] 51.132.180.74.20004.0: Server starting on 0.0.0.0:28888

In this line of output the IP address is represented by the numbers 51.132.180.74. You'll need to change this to match your remote machine's IP address.

To the IP address you need to add :28888 which is the port of the web server: <IP of your remote machine>:28888 eg. 51.132.180.74:28888. Paste this into a browser and you will see the rendered output.

About

Ray tracing in one weekend in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 76.2%
  • HTML 23.8%