Skip to content

Richonn/RTX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RTX - Ray Tracer

A ray tracer written in C++17 that renders 3D scenes described via a configuration file. Outputs images in PPM format.

Features

  • Primitives: Sphere, Plane, Cone, Torus
  • Lighting: Ambient, diffuse (Lambert), point lights, directional lights, shadow casting
  • Anti-aliasing: 30 samples per pixel with random jitter
  • Camera: Configurable position, field of view, and resolution
  • Implicit surfaces: Cone and Torus solved via algebraic equation solvers (quadratic, quartic)
  • Scene config: Declarative .cfg files via libconfig++

Dependencies

On macOS:

brew install libconfig

On Ubuntu/Debian:

sudo apt-get install libconfig++-dev

Build

make

This produces the rtx executable.

make clean   # Remove object files
make fclean  # Remove object files and binary
make re      # Full rebuild

Usage

./rtx <scene_file.cfg> > output.ppm

Example:

./rtx config.cfg > render.ppm

The image is written to stdout in PPM format. Redirect it to a file and open it with any image viewer that supports PPM (e.g., GIMP, Preview on macOS, feh on Linux).

Scene Configuration

Scenes are described in libconfig format.

Camera

camera:
{
    resolution = {width = 1920; height = 1080;};
    position   = {x = -1.0; y = 0.0; z = 10.0;};
    rotation   = {x = 0.0; y = 0.0; z = 0.0;};
    fieldOfView = 60.0; # degrees
};

Primitives

primitives:
{
    spheres = (
        {x = 0.0; y = 0.0; z = -1.2; r = 0.5; color = {r = 199; g = 21; b = 133;};}
    );

    planes = (
        {
            position = {x = 0.0; y = -2.0; z = 0.0;};
            vector   = {x = 0.0; y = 1.0;  z = 0.0;}; # normal
            color    = {r = 152; g = 251; b = 152;};
        }
    );

    cones = (
        {x = 2.0; y = 3.0; z = -3.0; r = 3.0; h = 5.0; color = {r = 180; g = 180; b = 180;};}
    );

    tori = (
        {
            center       = {x = -1.0; y = 0.0; z = 1.5;};
            major_radius = 1.0;
            minor_radius = 0.65;
            color        = {r = 200; g = 50; b = 200;};
        }
    );
};

Lights

lights:
{
    ambient = 0.2;
    diffuse = 0.8;

    point = (
        {x = 5.0; y = 5.0; z = 5.0; intensity = 1.0;}
    );

    directional = (
        {x = 0.0; y = -1.0; z = 0.0; intensity = 0.3;}
    );
};

Project Structure

RTX/
├── Makefile
├── config.cfg          # Example scene
├── include/            # Header files
│   ├── Camera.hpp
│   ├── Color.hpp
│   ├── Cone.hpp
│   ├── HitRecord.hpp
│   ├── Image.hpp
│   ├── Light.hpp
│   ├── Lights.hpp
│   ├── Material.hpp
│   ├── Object.hpp
│   ├── Plane.hpp
│   ├── Point3D.hpp
│   ├── Ray.hpp
│   ├── RayTracer.hpp
│   ├── Rectangle3D.hpp
│   ├── Setup.hpp
│   ├── Sphere.hpp
│   ├── Torus.hpp
│   └── Vector3D.hpp
└── src/
    ├── Main.cpp
    ├── Camera/
    ├── Color/
    ├── Image/
    ├── Math/           # Polynomial solvers (cubic, quartic)
    ├── Point3D/
    ├── Ray/
    ├── RayTracer/
    ├── Rectangle3D/
    ├── Setup/
    ├── Shapes/         # Sphere, Plane, Cone, Torus
    └── Vector3D/

Architecture

Component Role
Object Abstract base class for all scene primitives
RayTracer Core rendering loop with shadow and shading logic
Setup Parses .cfg file and builds scene objects
Camera Generates primary rays from a viewpoint
Image Pixel buffer; writes PPM to stdout
poly34 Algebraic solvers for cone/torus intersections

About

C++17 ray tracer — spheres, planes, cones & tori with Lambert shading, shadows and anti-aliasing. Scene-driven via .cfg files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors