Giter Site home page Giter Site logo

vhiribarren / raytracer-rust Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 3.0 2.89 MB

Toy project to test Rust and understand ray tracer principles.

Home Page: http://workshop.alea.net/raytracer-rust/

License: MIT License

Rust 83.45% HTML 2.25% JavaScript 11.83% CSS 2.19% Shell 0.28%
rust ray-tracer hobby-project webassembly

raytracer-rust's Introduction

Raytracer in Rust

Build Raytracer

Hobby project to test the Rust programming language and understand how a Ray Tracer works.

Used technologies: Rust, SDL2, TOML, WebAssembly, Parcel.js, React, Antd.

Sample

Development can be very erratic since it is a hobby project, however if you like how the current result is, feel free to contribute!

How to start

Tested under MacOS 10.14.6 with Rust 1.40.0.

$ cargo run -- samples/show_room_1.toml

Default compilation option make the rendering process quite slow, you may also test the result using:

$ cargo run --release -- samples/show_room_1.toml

The raytracing directory contains the main engine, as a Rust library.
The app directory is for a standalone app using the library.
The samples directory has some scene description file examples that can be used with the standalone app.

Some options are available in the standalone app:

$ cargo run -- --help

USAGE:
    app [FLAGS] [OPTIONS] <INPUT_FILE>

FLAGS:
        --help              Prints help information
        --no-gui            Do not display the result of the rendering.
        --no-parallel       Do not use multithreading for parallel computation (slower).
        --no-progressive    Do not render in realtime in the window if GUI is activate (quicker).
        --no-status         Do not display textual progressive bar (quicker).
    -V, --version           Prints version information
    -v, --verbose           Verbosity of log messages (one for Debug level, two for Trace level)

OPTIONS:
    -h, --height <height>                Canvas height.
        --strategy-random <RAY_COUNT>    Average of RAY_COUNT random rays sent.
    -w, --width <width>                  Canvas width, default: 1024.

ARGS:
    <INPUT_FILE>    TOML file describing the scene.

Web Browser

The raytracer is compatible with the WebAssembly technology. It can be launched as a web app instead of a native app.

Sample

$ cd webapp
$ npm install
$ npm start         # Start a local web server and launch a web page
$ npm run build     # Build files in the dist/ directory
$ npm run clean     # Remove the dist/ directory

Features

  • Primitives: sphere, plane, infinite plane
  • Cameras: perspective, orthogonal
  • Light: colored light point, spot light
  • Textures: plain, gradient, procedural checked texture
  • Effects: transparency, mirror
  • Anti-aliasing: none, random strategy
  • Shadow when object obstruction
  • Ambiant light
  • Diffuse light reflexion
  • Specular light reflexion
  • Light refraction
  • Ray launcher recursion for transparent/mirror texture
  • Parallel computing
  • WebAssembly compatibility
  • TOML based scene language/configuration description

Scene Description Language

TOML is currently used as a format to describe a ray tracing scene. It gives the following grammar and feeling:

description = "Show Room 1"

[config]
ambient_light = [0.0, 0.0, 0.2] # Red atmosphere

[camera]
type = "perspective"
screen_center = [0.0, 10.0, -10.0]
look_at = [0.0, 0.0, 30.0]
width = 32
height = 18

[[light]]
description = "Tiny red light on left"
type = "point"
source = [-50.0, 20.0, -20.0]
color = [0.8, 0.0, 0.0]

[[light]]
description = "Global white light"
type = "point"
source = [50, 100, -50]
color = [0.8, 0.8, 0.8]

[[object]]
description = "Center checked sphere"
type = "sphere"
center = [0, 0, 0]
radius = 5
texture.type = "checked"
effect.phong = {}

[[object]]
description = "Green transparent sphere on the right"
type = "sphere"
center = [10, 3, 10]
radius = 8
texture.type = "plain"
texture.color = "green"
effect.phong = {}
effect.transparency.refractive_index = 1.3

[[object]]
description = "Red mirror sphere on the left"
type = "sphere"
center = [-10, 3, 10]
radius = 8
texture.type = "plain"
texture.color = "red"
effect.phong = {}
effect.mirror.coeff = 1.0

[[object]]
description = "Yellow transparent sphere behind"
type = "sphere"
center = [0, 10, 35]
radius = 15
texture.type = "plain"
texture.color = "yellow"
effect.phong = {}
effect.transparency.refractive_index = 1.3

[[object]]
description = "Infinite plan"
type = "infinite_plan"
center = [0, -5, 0]
normal =  [0, 1, 0]
texture.type = "checked"
effect.mirror.coeff = 0.8

To do

RayTracing:

  • Better anti-aliasing
  • Color shadow when going through transparent object
  • Box primitive
  • Texture image mapping
  • Object transformation
  • Perlin effect for bump mapping

Rust:

  • More automatic tests

WebAssembly:

  • Multithreading
  • More automatic tests

References

License

MIT License

Copyright (c) 2019, 2020 Vincent Hiribarren

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

raytracer-rust's People

Contributors

dependabot[bot] avatar vhiribarren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

happydpc justeres

raytracer-rust's Issues

Not possible to use serde typetag with WASM

It does not seem possible to use https://github.com/dtolnay/typetag to easily convert from TOML to boxed trait objects for WASM, but it works with native compilation.

The use of https://github.com/mmastrac/rust-ctor might be the reason, since it uses low level file format manipulation to start code execution. There is no such thing in WASM, or at least here is a start section, but even so, the technique would be different than the one currently used by ctor.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.