Skip to content

This project has not finished yet, and I will put 3D Visualization in future.

Notifications You must be signed in to change notification settings

fjordyo0707/RaytracingAndVisualize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raytracing using OpenCV

Author: Cheng-Yu, Fan

Check Github: https://github.com/fjordyo0707/RaytracingAndVisualize

Dependencies

OpenCV (version >3.0)
Cmake (version >2.8)
C++11

Results

Phong Model

                    Ambient                                               Diffusion                                               Specular

alt textalt textalt text

Shadow

alt text

Reflection

alt text

More complicate structure

alt text

Soft Shadow and Anti-aliasing

alt text

Explantion for how I sample and Runtime

Anti-aliasing: For one pixel, I sample four ray and interpolate with bicubic method.

Soft Shahow: I sample 1000 points on a disc within a light sphere, and instead of setting Id to zero, I set it with Id*(1-{ratioOfShadow}) The Runtime for this complicated image(mytest.txt) takes about 4 minutes on my laptop.

The simple image(input.txt) takes about 1~2 minutes.

Install Denpendencies

MacOS

$ brew install cmake
$ brew install opencv
$ brew install pkg-config

Linux (Ubuntu)

$ sudo apt-get update
$ sudo apt-get install cmake
$ sudo apt-get install libopencv-dev python-opencv

Windows

Go here Cmake to install cmake.

Install OpenCV depend on your IDE or compiler.

Run

Notice

  1. This code does recursion until not hitting anything, so it may take some time if you have too many objects!

  2. This code isn't fully optimized, so may look a bit dirty!

  3. Runtime will take few minutes!

Unix (recommend)

$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./bin/output <path/to/input.txt> <path/to/output.png> 
# For example : $ ./bin/output ../test/mytest.txt ../img/output.png

Win (not recommend)

(Optional) Download the prebuild OpenCV and use Visual Studio

  1. Open your IDE
  2. Set OpenCV to your path environment
  3. Link

Input Data Format(.txt)

Eye position: E x y z

View direction: V Dx Dy Dz Ux Uy Uz

Field of view: F angle

Resolution: R w h

Sphere: S Ox Oy Oz r

Triangle: T x1 y1 z1 x2 y2 z2 x3 y3 z3

Light position: L x y z r

Material: M r g b Ka Kd Ks exp Reflect

About

This project has not finished yet, and I will put 3D Visualization in future.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published