A physically-based ray tracing renderer written in Rust that simulates realistic light behavior and generates photorealistic images.
📋 Table of Contents
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.
-
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
- Rust (latest stable version)
- Cargo (comes with Rust)
-
Clone the repository:
git clone <repository-url> cd rt
-
Build the project:
cargo build --release
Run the ray tracer with the default scene configuration:
cargo run --releaseThis will:
- Read the scene configuration from
scene.json - Render the scene
- Generate a PPM image file as output
Modify the scene.json file to create your own custom scenes. See the Scene Configuration section for details.
The scene.json file defines all elements of your 3D scene. It uses a JSON structure with the following components:
Defines the viewpoint and orientation:
"camera": {
"origin": { "e": [3.0, 2.2, -4.0] },
"look_at": { "e": [2.0, 0.0, 0.0] }
}Configures the light source:
"light": {
"position": { "e": [2.0, 6.0, -4.0] },
"color": { "e": [1.0, 1.0, 1.0] },
"intensity": 1.0
}Add various geometric primitives to your scene:
"spheres": [...],
"planes": [...],
"cubes": [...],
"cylinders": [...]For detailed information about all configuration options, see the documentation.
Here's an example of a rendered scene:
For comprehensive documentation on:
- Ray tracing concepts
- Detailed JSON schema
- Object properties and parameters
- Color specifications
Please refer to the documentation.md file.
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
rand(0.8.5) - Random number generationserde(1.0.215) - Serialization frameworkserde_json(1.0.133) - JSON parsing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
おはよう世界! 🌅
⭐ Star this repository if you found it helpful! ⭐
Made with ❤️ from 🇸🇳
