Skip to content

IsAvaible/Rust-Tiny-Renderer

Repository files navigation

Rust Tiny Renderer

A 3D rendering engine written from scratch in Rust. This project parses and renders .obj 3D model files using a custom software rasterizer, outputting the final image as a .ppm bitmap.


Features

  • Renders 3D .obj models to .ppm images.
  • Custom implementation of:
    • Vector math (Vec2, Vec3)
    • Line drawing and triangle rasterization
    • Back-face culling
    • Z-buffering (optional)
  • Basic lighting with diffuse shading

Example Output

Default output


Project Structure

src/
├── main.rs                       # Entry point
├── graphics_api.rs               # Core image buffer, color representation, and file output
├── two_dimensional_draw_api.rs   # 2D primitives (lines, fills)
├── three_dimensional_draw_api.rs # 3D triangle drawing and z-buffering
├── wireframe_rendering.rs        # Loads and renders an example OBJ model
├── vectors.rs                    # Vec2/Vec3 implementations with vector math
├── helper_functions.rs           # Utility functions

Usage

1. Build the project

cargo build --release

2. Run the renderer

cargo run --release

By default, this renders the model african_head.obj and outputs the image to out.ppm.

3. View the output

You can open .ppm files using image viewers like:


Input/Output

  • Input: .obj model (default: african_head.obj)
  • Output: .ppm image (default: out.ppm)

Example: Triangle Rasterization

Each triangle is:

  • Lit using a hard-coded light vector and Lambertian shading
  • Back-face culled
  • Converted to screen space
  • Drawn using a scanline rasterizer

Credits

This project was created as a Rust-based implementation of the Tiny Renderer tutorial by ssloy, following its lessons to build a 3D software rasterizer from scratch.


Potential Future Improvements

  • Support more complex shading (Phong, Gouraud)
  • Texture mapping support
  • Camera transformations
  • Scene file input
  • Parallel rendering

About

A simple 3D rendering engine written from scratch in Rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages