Skip to content

J-hune/raytracer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raytracer in C++

This project implements a Raytracer in C++ using OpenGL and GLUT libraries to generate realistic renders of 3D scenes. The raytracer supports various shapes and materials, along with advanced lighting techniques such as global illumination and caustics via photon mapping. This allows the simulation of realistic lighting effects, such as reflections, refractions, and light diffusion on surfaces.

Raytracer Preview

Features and Architecture

Light Management and Visual Effects

  • Direct Lighting: Computed using the Phong lighting model, which simulates the impact of light based on the position, orientation, and properties of each material. This model includes:
    • Diffuse Reflection: For light distribution on matte surfaces.
    • Specular Reflection: For shiny highlights on smooth surfaces.
  • Indirect Lighting: Simulated using photon mapping to represent light bouncing between surfaces. This creates a more realistic rendering, as areas in direct shadow can still receive reflected light.
  • Caustics: Complex light effects caused by transparent (glass) or reflective (mirror) materials are accurately simulated using photon mapping, enabling light concentration effects (like light passing through a glass of water).

Material Models and Textures

Object materials are defined to replicate realistic physical properties:

  • Mirror: Perfectly specular reflective surfaces, ideal for reflective objects like mirrors.
  • Glass: A material with both reflection and refraction, calculated using the Fresnel effect to simulate intensity variation based on the angle of incidence.
  • Diffuse Material: A standard material model supporting diffuse and specular reflection (via the Blinn-Phong model).

Textures and Skybox

  • Textures: The raytracer supports applying textures to objects.
  • Skybox: A skybox can be included to simulate background environments, creating a realistic ambiance for the 3D scene.

Photon Mapping

Photon mapping is used to simulate indirect lighting and caustics:

  • Photon Emission: Photons are emitted from light sources and interact with scene materials.
  • Photon Map Storage: Photon interactions with objects are stored and organized in a KDTree, enabling efficient illumination estimation.
  • Illumination Estimation: Using photons near each intersection point, the raytracer calculates indirect lighting and caustics, with a Cone filter applied for smoothing.

Render Examples

Render Breakdown

Final renders result from combining multiple passes:

Direct Lighting (Phong) Indirect Lighting
Direct Lighting Indirect Lighting
Caustics Final Render
Caustics Final Render

Render Examples with Skybox

Skybox with Reflection Skybox with Refraction
Skybox 1 Skybox 2

Additional render examples are available in the /img/github folder.

Compilation and Execution

Prerequisites

  • CMake (version 3.11 or higher)
  • OpenGL and GLUT: For graphical display and real-time visualization.

Compilation Instructions

  1. Clone the repository and create a build directory:

    git clone https://github.com/J-hune/raytracer.git
    cd raytracer
    mkdir build
    cd build
  2. Generate the project using CMake:

    cmake ..
  3. Compile the code:

    make
  4. Run the program:

    ./raytracer

Generated images will be saved in the /build/renders folder.


Licence

This project is licensed under the MIT License. You are free to use, modify, and redistribute it under the terms of this license. For more details, see the LICENSE file.

About

Realistic raytracer in C++ using OpenGL/GLUT with photon mapping for advanced lighting effects, supporting reflections, refractions, and caustics.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors