Skip to content

leoxanigm/miniRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by mathboye and zalemu

wall-e and tin-man

Description

The project uses c programming language to make a minimal raytracer. It is possible to render simple to complex scenes by using a sphere, cylinder and plane. The project uses one ambient light source, one spot light source and one camera to render a scene.

Instructions

  • On terminal type make.
  • To clean temporary object files, type make clean.
  • Then run miniRT with the desired scene file. Eg: ./miniRT scenes/simple_2.rt
  • You can close the render window either by hitting ESC or clicking on the cross

Resources

The project is built on extensive information provided by the book The Ray Tracer Challenge by Jamis Buck and the website ScratchPixel

Some scene files were references from https://github.com/0xEDU/minirt/tree/main/scenes

Object space

Coordinate system attached to a single object where geometry is represented in its simplest form.

For example, a sphere is defined as a unit sphere: center(0, 0, 0), radius 1.

Representing objects this way makes math calculations easier. And we use transformation matrices to place objects in the scene (world space). Defining every object directly in world space would require redoing intersection math for every position, orientation and scale. Using object space to represent out objects helps avoid that.

World space

A shared, global coordinate system where all objects, camera and lights exist.

Shapes

For this project we handle three shapes: sphere, cylinder and plane. The shapes have common attributes like id, type, transformation matrices and material.

Material color is set based on input.

Sphere

We use a unit radius sphere at location (0, 0, 0) for x, y and z coordinates respectively.

The spheres' transformation matrices are set based on location and diameter inputs.

Cylinder

We use a unit radius sphere cylinder at location (0, 0, 0) with infinite height and normal in the positive y direction . Its transformation matrices for location, diameter and height are then set based on inputs.

Plane

We use a plane at location (0, 0, 0) with infinite width and height with normal in the positive y direction. Its transformation for location and rotation are then set based on inputs.

Light and reflection

Phong reflection model

This project uses the phong reflection model to shade shapes. It uses three types of lightings to model a surface reflection model.

  • Ambient reflection simulates light coming from all directions. It colors all points on a surface equally.
  • Diffuse reflection depends on the angle between light source and surface normal.
  • Specular reflection depends on the angle between the reflection vector and camera vector. It is governed by how shiny a surface is.

Phong reflection model By Brad Smith - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=1030364

AI Usage

AI was used:

  • To populate test cases based on a prototype rather than typing each one by hand, saving time.
  • To give detail math formula explanations with examples.

About

a minimal ray tracer in C

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors