/ray-tracer

A ray tracer application for rendering scenes with different objects, surfaces and lights. The application uses mathematics and linear algebra to simulate materials and light. Uses SDL2 for pixel rendering

Primary LanguageC++GNU General Public License v3.0GPL-3.0

Ray-Tracing-

An application that implements ray tracing from scratch using mathematics and linear algebra to render object of different shapes,materials, shininess , colors, and reflectivity in 3D scene.

How the application works.

The application first places different object in the a 3D plane. The light sources and camera are placed at specific position whereas the other objects and planes are initially placed at the origin then later transformed and translated using matrix operations.

Different objects and their reflexitivity,shininess and colours are all modelled using linear algebra and mathematics.

Running the code

  • Download the SDL2 from https://www.libsdl.org/download-2.0.php,
  • Clone the project and replace the SDL2PATH variable in the makefile with the absolute path of where the SLD2 folder was extracted,
  • using CMake, run command 'make'

THe following are screenshots of the different stages of development.

The 2D rendering

Screenshot 2022-02-08 161321

Calculating and rendering a 3D sphere on a 2D screen

Rendering 3D image onto a 2D screen

passing_a_3D_ray_into_a_2D_screen

Vector equation of a sphere

finding_the_intersection_point

Simplifying the equation

finding_the_equation_of_circle

Implemented sphere from the maths and rendered into the scene.

Screenshot 2022-02-08 164131

Calculating the shadows and shininess in relation to a source light

Using dot product to get the angle between the light source and a point on the sphere

shiningness_maths

Implementation of the maths.

Screenshot 2022-02-08 193018

Transforming objects using translation, rotations and scaling matrices.

The different matrices that are used to translate, rotate and scale unit sphere centred from the origin.

combined_transformations

Implemented the maths. The three objects are derived from unit radius spheres centred at the origin

Screenshot 2022-02-10 105544

Implementing a plane

Plane vector

plane_vectors

Equation for finding point of intersection with a plane

finding_equation_for_the_intersection

Implementation

Screenshot 2022-02-10 133942

Implemented shadowing on the plane

Screenshot 2022-02-17 141328

Made correction to the shadowing to make it realistic

Screenshot 2022-02-17 143054

Introduced different sources of lights placed at different positions and having different colors.

Screenshot 2022-02-17 174635

Calculated and introduced different materials having different specular, shiness and reflectivity values

Material diffusion vectors and the point of intersections

material_diffusion_calculation

Specular vectors and intersection equations

specular_mathematics

Reflection vectors and the intersection equations

reflectivity_mathematics

implementation

Screenshot 2022-02-27 180440 different_reflexitivity

Introducing Cylinders and Cones

Cylinder_and_cones