Skip to content

Simple code for ray tracing and ray marching to understand the topic

License

Notifications You must be signed in to change notification settings

Eryk-Mozdzen/Ray_Tracing_CPU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ray Tracing & Ray Marching Algorithm on CPU

Simple ray tracer created for fun and to develop object programing skills. Code uses SFML library to menage basic objects like sf::RenderWindow, sf::Color and sf::Image

YouTube demonstration:

Ray Tracing result (left) and ray marching result (right).

Usage

Windows:

git clone https://github.com/Eryk-Mozdzen/Ray_Tracing_CPU.git
cd Ray_Tracing_CPU/example-ghx
git submodule init SFML
git submodule update

mkdir build
cd build
cmake .. -G "Unix Makefiles"
make
example-ghx.exe

Linux:

sudo apt install libudev-dev
sudo apt install libopenal-dev
sudo apt install libvorbis-dev
sudo apt install libflac-dev
sudo apt install libgl1-mesa-dev
sudo apt install xorg-dev

git clone https://github.com/Eryk-Mozdzen/Ray_Tracing_CPU.git
cd ./Ray_Tracing_CPU/example-ghx
git submodule init SFML
git submodule update

mkdir ./build
cd ./build
cmake .. 
make
./example-ghx

Example usage of all functions is presented in code with comments, but for short explanation:

Custom drawable object

Lib does not have any pre-made classes to draw on scene. User must declare his own objects inheriting from Object class and overrite Collision intersect(const Ray &ray) const or Collision distance(const Vector3 &point) method on it.

Method must return Collision struct wih correct values in each field.

Collision struct contains:

  • .point type Vector3 (should contain coordinates of point in 3d space where collision occurs)
  • .normal type Vector3 (should contain surface norma vector in collision point)
  • .material type Material (should contain material specifications of the object)
  • .distance type double (should contain distance dorm ray origin to collision point)
  • .exist type bool (should contain result of intersection test, exacly the same what method return)

Classes

Material class describes character of given material in context to Phong reflection model.

Transform3 class is standard transformation matrix 4x4 to describe translation and rotation in 3d space.

View class describes position and direction of "virtual camera" on scene. It also contains distance from eye to trajectory plane.

Scene class is the core of algorithm. It contains informations about all objects and lights on screen.

To do:

  • overall optimalization
  • transparent materials and light refraction effect
  • use of algorithm

About

Simple code for ray tracing and ray marching to understand the topic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published