Skip to content
/ rt Public

A physically-based ray tracing renderer written in Rust that simulates realistic light behavior to generate photorealistic images from JSON-defined 3D scenes.

Notifications You must be signed in to change notification settings

TanakAiko/rt

Repository files navigation

Ray Tracer (RT)

Rust Cargo Ray Tracing JSON

A physically-based ray tracing renderer written in Rust that simulates realistic light behavior and generates photorealistic images.

📋 Table of Contents

🎨 About

This ray tracer implements a rendering technique that simulates the physical behavior of light as it interacts with objects in a 3D scene. By tracing rays of light from a virtual camera through each pixel, the renderer calculates realistic lighting, shadows, and reflections to produce high-quality images.

✨ Features

  • Multiple Primitive Types

    • Spheres
    • Planes
    • Cubes
    • Cylinders
  • Realistic Lighting

    • Point light sources with configurable intensity
    • Color-tinted lighting
    • Shadow casting
  • Flexible Camera System

    • Configurable camera position and orientation
    • Look-at target positioning
  • JSON-based Scene Definition

    • Easy scene configuration
    • Hot-swappable scene files
    • Human-readable format
  • PPM Image Output

    • Standard image format output
    • Configurable resolution

🚀 Installation

Prerequisites

  • Rust (latest stable version)
  • Cargo (comes with Rust)

Setup

  1. Clone the repository:

    git clone <repository-url>
    cd rt
  2. Build the project:

    cargo build --release

💻 Usage

Basic Usage

Run the ray tracer with the default scene configuration:

cargo run --release

This will:

  1. Read the scene configuration from scene.json
  2. Render the scene
  3. Generate a PPM image file as output

Custom Scene

Modify the scene.json file to create your own custom scenes. See the Scene Configuration section for details.

🎬 Scene Configuration

The scene.json file defines all elements of your 3D scene. It uses a JSON structure with the following components:

Camera

Defines the viewpoint and orientation:

"camera": {
    "origin": { "e": [3.0, 2.2, -4.0] },
    "look_at": { "e": [2.0, 0.0, 0.0] }
}

Light

Configures the light source:

"light": {
    "position": { "e": [2.0, 6.0, -4.0] },
    "color": { "e": [1.0, 1.0, 1.0] },
    "intensity": 1.0
}

Objects

Add various geometric primitives to your scene:

"spheres": [...],
"planes": [...],
"cubes": [...],
"cylinders": [...]

For detailed information about all configuration options, see the documentation.

📸 Examples

Here's an example of a rendered scene:

Ray Traced Scene

📚 Documentation

For comprehensive documentation on:

  • Ray tracing concepts
  • Detailed JSON schema
  • Object properties and parameters
  • Color specifications

Please refer to the documentation.md file.

📁 Project Structure

rt/
├── src/
│   ├── main.rs           # Entry point
│   ├── camera.rs         # Camera implementation
│   ├── color.rs          # Color utilities
│   ├── ray.rs            # Ray mathematics
│   ├── hittable.rs       # Hit detection trait
│   ├── hittable_list.rs  # Collection of hittable objects
│   ├── sphere.rs         # Sphere primitive
│   ├── plane.rs          # Plane primitive
│   ├── cube.rs           # Cube primitive
│   ├── cylinder.rs       # Cylinder primitive
│   ├── light.rs          # Lighting calculations
│   ├── vec3.rs           # 3D vector mathematics
│   ├── output.rs         # Image generation
│   ├── param.rs          # Parameters
│   └── common.rs         # Common utilities
├── scene.json            # Scene configuration
├── documentation.md      # Detailed documentation
├── Cargo.toml           # Rust dependencies
└── README.md            # This file

🛠️ Dependencies

  • rand (0.8.5) - Random number generation
  • serde (1.0.215) - Serialization framework
  • serde_json (1.0.133) - JSON parsing

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

おはよう世界! 🌅

⭐ Star this repository if you found it helpful! ⭐

Made with ❤️ from 🇸🇳

About

A physically-based ray tracing renderer written in Rust that simulates realistic light behavior to generate photorealistic images from JSON-defined 3D scenes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages