Skip to content

elsayedamine/MINIRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniRT — Ray Tracer by aelsayed

Overview

miniRT is a basic ray-tracer that renders 3D scenes described in a simple .rt file format. It supports a variety of geometric shapes, flexible lighting, material shading with bump mapping, and interactive camera controls. The project uses custom vector and matrix math libraries, multithreaded rendering, and optimized intersection routines for performance. Ray tracing is a fundamental technique in computer graphics for producing highly realistic images by simulating light paths, and it is computationally intensive and mathematically challenging.

Features

  • Geometry: renders planes, rectangles, spheres, cylinders, and cones.
  • Lighting & shading: ambient, diffuse, and specular lighting with control over shininess. Shadows from multiple light sources.
  • Bump mapping: support for texture files (.xpm) on surfaces (walls, pillars, objects) via bump= option in .rt.
  • Multiple lights & cameras: scene may include more than one light source and more than one camera.
  • Camera controls: interactive — rotate, translate (move), zoom, and switch among multiple cameras. Mouse + keyboard supported. Escape (Esc) to exit.
  • Custom math/optimization: vector and matrix operations implemented from scratch; intersection routines optimized; rendering uses thread pools for parallelism.

.rt File Format Example

Here is an example of what a .rt scene file can look like:

A 0.3 25,25,25
c 0,50,300 0,0,-1 70

pl 70,50,30 -1,0,0 25,25,25 bump=scenes/corridor/wall.xpm

sp -70,0,160 50 160,160,160 bump=scenes/corridor/pillar_base.xpm
cy -70,0,160 0,1,0 40 100 160,160,160 bump=scenes/corridor/pillar.xpm

co 0,110,70 0,-1,0 25 20 100,100,100
co 0,110,-70 0,-1,0 25 20 100,100,100

l 0,85,-910 0.3 127,127,127
l 0,85,-1050 0.3 127,127,127

Element Descriptions

  • A: ambient lighting — intensity and color.
  • c: camera — position, orientation vector, and field-of-view angle.
  • pl: plane (or rectangle) — position, normal vector, color, optional bump/texture.
  • sp: sphere — center, diameter (or radius depending on your implementation), color, optional bump/texture.
  • cy: cylinder — base center, orientation vector, radius, height, color, optional bump/texture.
  • co: cone — apex position, orientation vector, base radius, height, color.
  • l: light — position, brightness, and color.

Controls

Object Manipulation

  • Translate object: Left-click on an object, then use W, A, S, D, Q, E to move it.
  • Rotate object: Right-click on an object, then use W, A, S, D, Q, E to rotate it.
  • Resize object: Left-click on an object, then use the scroll wheel to scale it.
  • Adjust shininess: Left-click on an object, then press - or + to decrease or increase its shininess.
  • Move main light source: Use I, J, K, L, U, O to translate the primary light.

Camera Controls

  • Rotate camera: Middle-click anywhere, then use W, A, S, D, Q, E to rotate.
  • Translate camera: Press C, then use W, A, S, D, Q, E to move the camera.
  • Change FOV: Right-click anywhere and use the scroll wheel to zoom in/out.
  • Switch between cameras: Press 0, 1, 2... to select an available camera.

Implementation Details / Architecture

  • Custom vector and matrix math library (no external dependencies) — used for all geometric computations
  • Intersection calculations for all supported shapes implemented manually
  • Lighting model: ambient + diffuse + specular shading with shininess factor
  • Shadows computed per-light source for realistic shading
  • Bump mapping / texture mapping support using .xpm textures
  • Multithreaded rendering using a thread pool for increasing performance

How to Use

  1. Write or use a .rt scene file following the supported format.
  2. Build the project (e.g. make).
  3. Run the program with the path to .rt file as argument.
  4. Use mouse & keyboard to navigate or manipulate the camera and view the scene.
  5. Press Esc to exit.

📷 Gallery

img2 img3 img1 img1

About

A rendering project for generating images based on RAY TRACING approach

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •