Crate crystal_ball

source ·
Expand description

Crystal Ball is a path tracing library written in Rust.

It uses rayon for parallelization and can save the rendered image in various formats thanks to the image crate.

Note that Crystal Ball is a hobby project and will most likely see a lot of API changes in future versions.

§Features

  • Multithreaded CPU rendering
  • Save rendered images in various formats
  • Environment textures
  • General purpose PBR material
  • Shapes: spheres and triangle meshes
  • Easily create your own textures, materials, and shapes
  • Load glTF files
  • Depth of field
  • Bounding Volume Hierarchies
  • Optional denoising using Open Image Denoise

§Usage

§Basic Example

A basic example rendering two spheres.

use std::default::Default;
use std::sync::Arc;

use crystal_ball::prelude::*;

fn main() -> Result<(), Error> {
    let objects = vec![
        Object::new(
            Arc::new(Sphere::new()),
            Arc::new(PbrMaterial {
                base_color: Color::new(1.0, 0.45, 0.31),
                ..Default::default()
            }),
        ),
        Object::new(
            Arc::new(
                Sphere::new()
                    .translate(Vec3::new(0.0, -101.0, 0.0))
                    .scale_xyz(Vec3::splat(100.0)),
            ),
            Arc::new(PbrMaterial::default()),
        ),
    ];

    let scene = Scene {
        objects,
        camera: Camera::default().translate(Vec3::new(0.0, 0.0, 5.0)),
        ..Default::default()
    };

    let engine = RenderEngine::default();
    let image = engine.render(&scene);

    image.write("basic.png")?;

    Ok(())
}

Take a look at the examples to see how to use Crystal Ball’s different features.

§Coordinate System

Crystal Ball uses a right-handed coordinate system where

  • +X points right
  • +Y points up
  • +Z points to the screen

§Feature Flags

§Optional Features

Namedescription
oidnImage denoising using Open Image Denoise

Modules§

  • Data types and functions related to colors and images.
  • Data types and functions related to materials.
  • Data types and functions related to math with focus on vectors.
  • Commonly used structs and traits for easy access.
  • Data types and functions related to rendering.
  • Geometric shapes that can be placed into the scene.
  • Utility data types and functions used throughout Crystal Ball.

Derive Macros§