Skip to content

Commit

Permalink
Implemented areal light sources and path tracing
Browse files Browse the repository at this point in the history
Common base class renderer introduced. Meshes and spheres can now be
used a s light sources.
  • Loading branch information
Philip Abernethy committed Apr 13, 2016
1 parent 2862820 commit 4b53fcc
Show file tree
Hide file tree
Showing 77 changed files with 1,663 additions and 1,100 deletions.
27 changes: 15 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ endif ()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/extern)

find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()

find_package(CImg REQUIRED)
list(APPEND PROJ_INCLUDE_DIRS ${CImg_INCLUDE_DIRS})
list(APPEND PROJ_LIBRARY_DIRS ${CImg_SYSTEM_LIBS_DIR})
Expand All @@ -39,29 +34,37 @@ include_directories(${CImg_INCLUDE_DIRS})

find_package(pugixml REQUIRED)

find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()

add_library(math STATIC lib/math/vec4.cpp lib/math/vec2.cpp lib/math/mat4.cpp lib/math/helper.cpp)

add_library(sampler STATIC lib/sampler/random_sampler.cpp lib/sampler/sampler.cpp)
target_link_libraries(sampler math)

add_library(geometry STATIC lib/geometry/color.cpp lib/geometry/direction.cpp lib/geometry/normal.cpp
lib/geometry/point.cpp lib/geometry/ray.cpp lib/geometry/transform.cpp lib/geometry/intersection.h
lib/geometry/position.cpp lib/geometry/ray.cpp lib/geometry/transform.cpp lib/geometry/intersection.h
lib/geometry/shapes/shape.cpp lib/geometry/shapes/sphere.cpp lib/geometry/shapes/triangle.cpp
lib/geometry/shapes/mesh.cpp lib/geometry/material/material.h lib/geometry/material/solid_material.cpp
lib/geometry/shapes/mesh.cpp lib/geometry/material/material.cpp lib/geometry/material/solid_material.cpp
lib/geometry/material/phong_material.cpp lib/geometry/material/lambertian_material.cpp
lib/geometry/material/specular_material.cpp lib/geometry/material/textured_material.cpp
lib/geometry/material/transparent_material.cpp)
lib/geometry/material/transparent_material.cpp lib/geometry/shapes/point.cpp)
target_link_libraries(geometry math)

add_library(light STATIC lib/light/light.cpp lib/light/ambient_light.cpp lib/light/parallel_light.cpp
lib/light/point_light.cpp)
lib/light/point_light.cpp lib/light/lambertian_light.cpp lib/light/mesh_light.cpp lib/light/sphere_light.cpp)
target_link_libraries(light geometry)

add_library(camera STATIC lib/camera/camera.cpp lib/camera/perspective_camera.cpp lib/camera/realistic_camera.cpp)
target_link_libraries(camera sampler geometry)

add_library(whitted_rt STATIC lib/whitted_rt.cpp lib/parser.cpp lib/tiny_obj_loader.cpp)
target_link_libraries(whitted_rt camera light pugixml ${CImg_SYSTEM_LIBS})
add_library(renderer STATIC lib/renderer/renderer.cpp lib/renderer/whitted_rt.cpp lib/renderer/pathtracer.cpp)
target_link_libraries(renderer camera light)

add_library(parser STATIC lib/parser.cpp lib/tiny_obj_loader.cpp)
target_link_libraries(parser renderer pugixml ${CImg_SYSTEM_LIBS})

add_executable(Ray_Tracer main.cpp)
target_link_libraries(Ray_Tracer whitted_rt)
target_link_libraries(Ray_Tracer parser)
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# RayTracer
A whitted ray tracer written in C++

This project mainly serves the purposes of making me more familiar with C++ as well as getting me into computer graphics. I hope though, that it is helpful and/or educational for others too and I try to keep the code understandable, rather than highly performant.
This project mainly serves the purposes of making me more familiar with C++ as well as getting me into computer
graphics. I hope though, that it is helpful and/or educational for others too and I try to keep the code understandable,
rather than highly performant.

It is written in C++11 and thus requires a compiler capable of that standard. It uses CImg for image import and export, which at least depends on X11 and pthread libraries. CImg dependencies are handled in its own `.cmake` file. It further depends on [PugiXML](https://github.com/zeux/pugixml) for XML parsing and uses [TinyOBJLoader](https://github.com/syoyo/tinyobjloader) as in-tree library.
It is written in C++11 and thus requires a compiler capable of that standard. It uses CImg for image import and export,
which at least depends on X11 and pthread libraries. CImg dependencies are handled in its own `.cmake` file. For CImg to
be able to handle the `.png` files of this project it requires ImageMagick to be installed. CMAKE expects to find
[PugiXML](https://github.com/zeux/pugixml) in the library path, so either install it system-wide or compile to `/usr/local/lib`.
[TinyOBJLoader](https://github.com/syoyo/tinyobjloader) is used as in-tree library.
28 changes: 14 additions & 14 deletions classes.dot
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ digraph Classes {
label = "{intersection|
+ object : shape *\l
+ dir : normal *\l
+ pos : point *\l
+ pos : position *\l
+ local_pos : vec2 *\l
}"
]
Expand All @@ -42,8 +42,8 @@ digraph Classes {
# transforms : transform\l
# resolution : std::array\<unsigned long, 2\>\l
# data : std::vector\<std::vector\<std::vector\<color\>\>\>\l|
# camera(position : point &,
look_at : point &,
# camera(position : position &,
look_at : position &,
up : direction &,
resolution : std::array<unsigned long, 2> &,
samples : unsigned long &)\l
Expand All @@ -57,8 +57,8 @@ digraph Classes {
label = "{perspective_camera|
# fov : float\l|
+ perspective_camera()\l
+ perspective_camera(position : point &,
look_at : point &,
+ perspective_camera(position : position &,
look_at : position &,
up : direction &,
fov : float &,
resolution : std::array<unsigned long, 2> &,
Expand All @@ -67,9 +67,9 @@ digraph Classes {
]
ray [
label = "{ray|
+ o : point\l
+ o : position\l
+ d : direction\l|
+ ray(o : point &, d : direction &)\l
+ ray(o : position &, d : direction &)\l
}"
]
shape_ [
Expand Down Expand Up @@ -146,7 +146,7 @@ digraph Classes {
parallel_light|
- transforms : transform\l|
+ parallel_light(col : color, dir : direction &)\l
+ get_direction() : direction &\l
+ get_directions() : direction &\l
}"
]
transform [
Expand All @@ -158,7 +158,7 @@ digraph Classes {
+ transform(trans : mat4 &, inv_trans : mat4 &)\l
+ transform(in : transform &)\l
+ operator()(t : transform &) : transform\l
+ operator()(p : point &) : point\l
+ operator()(p : position &) : position\l
+ operator()(v : direction &) : direction\l
+ operator()(n : normal &) : normal\l
+ translate(t : direction &) : void\l
Expand All @@ -181,11 +181,11 @@ digraph Classes {
]
point_ [
label = "{
point||
+ point()\l
+ point(x : float &, y : float &, z : float &)\l
+ point(v : vec4 &)\l
+ point(in : point)\l
position||
+ position()\l
+ position(x : float &, y : float &, z : float &)\l
+ position(v : vec4 &)\l
+ position(in : position)\l
+ operator[](i : int) : float\l
}"
]
Expand Down
37 changes: 18 additions & 19 deletions examples/box.obj
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# Blender3D v249 OBJ File:
# www.blender3d.org
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 0.000000 -0.000000
vn -0.000000 -1.000000 -0.000000
vn 1.000000 0.000000 -0.000000
vn 1.000000 -0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 0.000000 0.000000
vn 0.000000 -1.000000 0.000000
vn 1.000000 0.000000 0.000000
vn 0.000000 0.000000 1.000000
vn 0.000000 0.000000 -1.000000
usemtl Material
s off
f 5/1/1 1/2/1 4/3/1
Expand All @@ -28,8 +27,8 @@ f 3/1/2 8/3/2 4/4/2
f 2/1/3 6/2/3 3/4/3
f 6/2/3 7/3/3 3/4/3
f 1/1/4 5/2/4 2/4/4
f 5/2/5 6/3/5 2/4/5
f 5/1/6 8/2/6 6/4/6
f 8/2/6 7/3/6 6/4/6
f 1/1/7 2/2/7 3/3/7
f 1/1/7 3/3/7 4/4/7
f 5/2/4 6/3/4 2/4/4
f 5/1/5 8/2/5 6/4/5
f 8/2/5 7/3/5 6/4/5
f 1/1/6 2/2/6 3/3/6
f 1/1/6 3/3/6 4/4/6
2 changes: 1 addition & 1 deletion examples/example5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<horizontal_fov angle="55"/>
<resolution horizontal="1024" vertical="1024"/>
<max_bounces n="8"/>
<sampling type="random" n="64"/>
<sampling type="none" n="64"/>
<defocus d="0.004"/>
<focus d="2"/>
<aperture d="0.2"/>
Expand Down
34 changes: 23 additions & 11 deletions examples/example6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<resolution horizontal="512" vertical="512"/>
<max_bounces n="8"/>
<sampling type="random" n="16"/>
<focus d="2"/>
<focus d="10"/>
<defocus d="4"/>
<aperture d="0.2"/>
</camera>
<lights>
<ambient_light>
Expand All @@ -24,19 +26,19 @@
</lights>
<surfaces>
<mesh name="plane_small.obj">
<material type="phong">
<material type="lambertian">
<color r="1.0" g="1.0" b="1.0"/>
<phong ka="0.3" kd="0.9" ks="1.0" exponent="20"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
<translate x="0.0" y="0.0" z="-10.0"/>
</transform>
</mesh>
<mesh name="plane_small.obj">
<material type="phong">
<material type="lambertian">
<color r="1.0" g="1.0" b="1.0"/>
<phong ka="0.3" kd="0.9" ks="1.0" exponent="20"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
Expand All @@ -45,9 +47,9 @@
</transform>
</mesh>
<mesh name="plane_small.obj">
<material type="phong">
<material type="lambertian">
<color r="1.0" g="1.0" b="1.0"/>
<phong ka="0.3" kd="0.9" ks="1.0" exponent="20"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
Expand All @@ -56,9 +58,19 @@
</transform>
</mesh>
<mesh name="plane_small.obj">
<material type="phong">
<material type="lambertian">
<color r="1.0" g="1.0" b="1.0"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
<rotateX theta="180.0"/>
</transform>
</mesh>
<mesh name="plane_small.obj">
<material type="lambertian">
<color r="1.0" g="0.0" b="0.0"/>
<phong ka="0.3" kd="0.9" ks="1.0" exponent="20"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
Expand All @@ -67,9 +79,9 @@
</transform>
</mesh>
<mesh name="plane_small.obj">
<material type="phong">
<material type="lambertian">
<color r="0.0" g="1.0" b="0.0"/>
<phong ka="0.3" kd="0.9" ks="1.0" exponent="20"/>
<lambertian ka="0.3" kd="0.9"/>
</material>
<transform>
<scale x="5.1" y="5.1" z="1.0"/>
Expand Down
Loading

0 comments on commit 4b53fcc

Please sign in to comment.