Skip to content
davsam97Public

About

Ray tracer in C from scratch: 4 primitives, Phong lighting, shadows, UV textures, bump mapping, interactive camera.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

miniRT

A ray tracer built from scratch in C: scene parsing, camera projection, ray/primitive intersection, Phong lighting, shadows, textures and bump mapping — rendered live in a window with MiniLibX.

42 School project — final grade 125 / 100.

Project result

Features

Rendering

  • Ray/primitive intersection: sphere, plane, cylinder, cone
  • Camera with configurable position, orientation and field of view
  • Ambient + diffuse (Lambertian) lighting, Phong specular highlights
  • Hard shadows, multiple point lights, colored lights

Materials

  • Solid colors or XPM textures, with analytic UV mapping per primitive (spherical, cylindrical, planar)
  • Checkerboard pattern on any primitive
  • Bump mapping from XPM heightmaps, using a per-hit TBN (Tangent/Bitangent/Normal) frame

Live interaction

  • Move/rotate the camera, or pick an object with a click and move/rotate it instead
  • Mouse wheel to move along the vertical axis, scroll-independent of camera orientation
  • Zoom via field of view, adjustable on the fly
  • Toggle individual pipeline stages at runtime (color, lights, shadows, specular, bump)

Parsing

  • Custom .rt scene file format: camera, ambient light, point lights, primitives, optional textures/bump maps/checkerboard
  • Strict, uniform field validation shared across all object types

Build

make          # build miniRT
make bonus    # build miniRT_bonus
make clean    # remove object files
make fclean   # remove object files and binaries
make re       # rebuild from scratch

The binary links against MiniLibX (X11) and statically builds an in-house libft.

Usage

./miniRT scenes/<filename>.rt
A  0.2  255,255,255
C  0,0,-5  0,0,1  70
L  -2,5,-3  0.8  255,255,255
sp  0,0,0  2  255,0,0
pl  0,-2,0  0,1,0  100,200,100
cy  1,0,3  0,1,0  1  3  0,0,255
Input Action
ESC / red cross Close the window
Arrow keys Move the camera (or the selected object)
WASDQE Rotate the camera (or the selected object)
Mouse wheel Move up / down
+ / - Change the camera's field of view
Left click Select the object under the cursor
Right click Deselect
Numpad 1-8 Toggle a rendering stage (color, lights, shadows, specular, bump...)
Numpad 9 / 0 Enable / disable all rendering stages

Project structure

The codebase is organized by feature: every module keeps its .c files and its own header side by side, and shares the scene's data model through a single header.

srcs/
├── app/            window & event loop, input handling, camera control, HUD
├── math/           vector math (dot, cross, normalize, reflect...)
├── parse/          .rt scene file tokenizing & parsing
├── raytrace/       ray/primitive intersection and normals (sphere, plane, cylinder, cone)
├── render/         lighting, shadows, bump mapping, per-pixel color
├── scene_object.h  shared scene/object data model
├── common.h        shared base types (vectors, image buffer)
└── main.c
libft/              in-house standard library replacement
minilibx-linux/     window & graphics backend (X11)

Dependency tracking is handled with -MMD -MP, so only the object files that actually depend on a changed header are rebuilt. The whole codebase is 42 Norm compliant.

Authors

About

Ray tracer in C from scratch: 4 primitives, Phong lighting, shadows, UV textures, bump mapping, interactive camera.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages