C++ Ray Tracer

We were tasked with creating a raytracer. Images are followed by the command line which produced them, as well as the scene file describing the setup. All times were calculated using the linux time program. All images on this page were output using my raytracer.

Three spheres and a Triangle

reflection
Command: ./raytrace scenes/spherestri.scene
Time: 6.030s
Features: Reflections, Shadows, Phong Shading, Antialiasing
Comments: This photo was inspired by the Raytracing Implementation Journal. It shows off shadows quite well
Scene File Show
material 
	name purp 
	ka 0.1 0.1 0.1
	kd 1 0 1
	ks 1 1 1
	power 50.0
end

material 
	name	yellow
	ka 0.1  0.1  0.1
	kd 1 1 0
	ks 1 1 1
	power 50.0
end 

material 
	name	lightblue
	ka 0.1  0.1  0.1
	kd 0 1 1
	ks 1 1 1
	power 50.0
end 

material 
	name	blue
	ka 0.1  0.1  0.1
	kd 0.1 0.1 0.1
	ks 1 1 1
	kr 1 1 1
	power 50.0
end 

#scene 
output spheretri.png
bgcolor .9 .9 .9 
resolution 3

#ul/ll/lr/ur x y z
ul -1 1 -3
ur 1 1 -3
lr 1 -1 -3
ll -1 -1 -3


#height/width pixels
height 1000
width 1000

#camera x y z
camera 0 0 0

#light point/directional x y z r g b
light directional 0.57735027  0.57735027  -0.57735027 0 0 1
light directional 0.57735027  -0.57735027  -0.57735027 1 1 1

#objects
#sphere r x y z 
use purp
sphere
	radius 3
	center 0 0 -20
end

use yellow
sphere
	radius 1
	center -2 2 -15
end

use lightblue
sphere
	radius 1
	center -2 -2 -15
end

use blue
triangle
	v1 5 5 -17
	v2 1 4 -20
	v3 6 -1 -20
end

Five spheres with Reflection

reflection
Command: ./raytrace scenes/reflections.scene
Time: 7.714s
Features: Reflections, Shadows, Phong Shading, Antialiasing
Comments: This photo was inspired by the Raytracing Implementation Journal
Scene File Show
material 
	name	red 
	ka		.1 0 0  
	kd		1 0 0 
	ks		.8 .8 .8 
	kr		.9 .9 .9 
	power	32 
end

material 
	name	blue
	ka		0 0 0  
	kd		0 0 1
	ks		.8 .8 .8 
	kr		.9 .9 .9 
	power	32 
end 

material 
	name	green
	ka		.1 0 0  
	kd		0 1 0 
	ks		.8 .8 .8 
	kr		.9 .9 .9 
	power	32 
end 

material 
	name	yellow
	ka		.1 0 0  
	kd		1 1 0 
	ks		.8 .8 .8 
	kr		.9 .9 .9 
	power	32 
end 

material 
	name	lightblue 
	ka		.1 0 0  
	kd		0 1 1 
	ks		.8 .8 .8 
	kr		.9 .9 .9 
	power	32 
end  

#scene 
output reflection.png
bgcolor .9 .9 .9
resolution 3

#ul/ll/lr/ur x y z
ul -1 1 -3
ur 1 1 -3
lr 1 -1 -3
ll -1 -1 -3


#height/width pixels
height 1000
width 1000

#camera x y z
camera 0 0 0

#light point/directional x y z r g b
light directional -0.57735027  0.57735027  0.57735027 1 1 1
light directional 0.57735027  -0.57735027  -0.57735027 1 1 1

#objects
#sphere r x y z 
use red

sphere 
	radius 2 
	center 0 0 -17
end

use blue

sphere 
	center 4 0 -17
	radius 1.5 
end 

use yellow

sphere 
	radius 1.5 
	center -4 0 -17
end

use green

sphere 
	radius 1.5 
	center 0 -4 -17
end


use lightblue

sphere 
	radius 1.5 
	center 0 4 -17
end

Three Ellipsoids

reflection
Command: ./raytrace scenes/mirrors.scene
Time: 32.797s
Features: Linear Transformations, Reflections, Shadows
Comments:
Scene File Show
material 
	name	red
	ka		.1 .1 .1 
	kd		.9 .1 .1
	ks		1 1 1 
	kr		1 1 1 
	power	32 
end

material 
	name	blue
	ka		.1 .1 .1 
	kd		.1 .1 .9
	ks		1 1 1 
	kr		1 1 1 
	power	32 
end

material 
	name	yellow
	ka		.1 .1 .1
	kd		.9 .9 .1
	ks		1 1 1 
	kr		.5 .5 .5 
	power	32 
end

material 
	name	gm
	ka	.1 .1 .1 
	kd	.8 .8 .8
	ks	1 1 1
	kr 1 1 1
	power 32
end


#scene 
output mirrors.png
resolution 5

#ul/ll/lr/ur x y z
ul -1 1 -3
ur 1 1 -3
lr 1 -1 -3
ll -1 -1 -3


#height/width pixels
height 1000
width 1000

#camera x y z
camera 0 0 0


#light point/directional x y z r g b
light directional 0 -.25 0 1 1 1

#use material


#objects
#sphere r x y z 

use red
sphere 
	radius 1
	center 0 0 -17
	scale 2 1 1
	rotate 0 0 45
	translate -2 0 0
 end

use blue
sphere 
	radius 1
	center 0 0 -17
	scale 3 1 1
	rotate 0 0 -45
	translate 1 1 0
end

use yellow
sphere 
	radius 1
	center 0 0 0
	scale 1 1 4
	rotate 20 30 0
	translate -1 4 -17
end

use gm
triangle
	v1 0 -1 0
	v2 100 -1 -100
	v3 -100 -1 -100
end

Five Ellipsoids

reflection
Command: ./raytrace scenes/elipse.scene
Time: 11.506s
Features: Linear Transformations, Reflections, Shadows
Comments: This photo was inspired by the Raytracing Implementation Journal
Scene File Show

camera 0 0 0
ll -1 -1 -3
lr 1 -1 -3
ur 1  1 -3
ul -1 1 -3
width 1000
height 1000
resolution 3
verbose 1
output elipse.png

light directional 0.57735027 -0.57735027 -0.57735027 1 1 1
light directional -0.57735027  0.57735027  0.57735027 1 1 1

material
	name red
	ka .1 .1 .1
	kd 1 0 0
	ks 1 1 1
	kr .9 .9 .9
	power 50
end

material
	name green
	ka .1 .1 .1
	kd 0 1 0 
	ks 1 1 1
	kr .9 .9 .9
	power 50
end

material
	name blue
	ka .1 .1 .1
	kd 0 0 1
	ks 1 1 1
	kr .9 .9 .9
	power 50
end

material
	name yellow
	ka .1 .1 .1
	kd 1 1  0
	ks 1 1 1
	kr .9 .9 .9
	power 50
end

material
	name lightblue
	ka .1 .1 .1
	kd 0 1 1
	ks 1 1 1
	kr .9 .9 .9
	power 50
end

use red
sphere
	radius 1
	scale 4 2 2
	translate 0 0 -17
end

use green
sphere
	radius 1
	scale .5 1.5 1
	rotate 0 -45 -45
	translate -2 4 -17
end

use blue
sphere
	radius 1
	scale .5 1.5 1
	rotate 0 -45 45
	translate -2 -4 -17
end

use yellow
sphere
	radius 1
	scale .5 1.5 1
	rotate 0 45 -135
	translate 2 4 -17
end

use lightblue
sphere
	radius 1
	scale .5 1.5 1
	rotate 0 45 135
	translate 2 -4 -17
end

Antialiasing

Resolution Time Image
1 0.354s reflection
2 1.067s reflection
3 2.305s reflection
4 4.008s reflection
5 6.093s reflection
Command: ./raytrace scenes/antialias.scene
Features: Antialiasing
Comments: The number of rays sent out per pixel is the resolution value squared. As we can see in the first image, we apply a small amount of jitter to each ray, whih further reduces aliasing.
Scene File Show

material 
	name rock 
	ka	.1 .1 .1
	kd	.9 .2 .2 
	ks	.8 .8 .8 
	power 32
end

material 
	name yellow 
	ka	.1 .1 .1 
	kd	.2 1 1 
	ks	.4 .3 .2
	power 32
end

material 
	name green
	ka	.1 .1 .1
	kd	.0 .9 0 
	ks	.8 .8 .8 
	power 32
end

#scene 
#change the resolution here
output aa1.png
resolution 1

#ul/ll/lr/ur x y z
ul -1 1 -1
ur 1 1 -1
lr 1 -1 -1
ll -1 -1 -1


#height/width pixels
height 500
width 500

#camera x y z
camera 0 0 10


#light point/directional x y z r g b
light directional 1 0 -1 .9 .6 .6
light directional -1 -1 -1 .5 .3 .3

#use material
use rock

#objects
#sphere r x y z 
sphere 
	radius 1 
	center 0 0 -2.5
end

use yellow
sphere 
	radius .5 
	center .5 .5 -1.5
end

use green
sphere 
	radius .5 
	center -.5 -.5 -1.5
end

Rendering .obj

reflection
Time: 5m45.038s
Command: ./raytrace scenes/teapot.scene
Features: Loading and rendering .obj files
Comments: My .obj parser does not support vector normals
Scene File Show
material 
	name rock 
	ka .1 0 0  
	kd .8 .2 .2 
	ks .8 .8 .8 
	power 32
end

#scene 
output teapot.png
bgcolor .9 .9 .9
resolution 1
verbose 1

#ul/ll/lr/ur x y z
ul -4 6 -1
ur 4 6 -1
lr 4 -2 -1
ll -4 -2 -1


#height/width pixels
height 1000
width 1000

#camera x y z
camera 0 0 10

light directional 1 0 -1 .6 .6 .6
light directional -1 -1 -1 .3 .3 .3

#use material
use rock

#objects
object 
	path obj/teapot.obj
	rotate 0 -25 0
	translate -.4 0 0
end


Angel

reflection
Time: 66m38.493s
Command: ./raytrace scenes/angel.scene
Comments: Rendering this file is pretty slow without acceleration structures
Scene File Show

material 
	name rock 
	ka .1 0 0  
	kd .8 .2 .2 
	ks .8 .8 .8 
	power 32
end


#scene 
output blank.png
bgcolor .9 .9 .9
resolution 1
verbose 1

#ul/ll/lr/ur x y z
ul -1 2 -1
ur 1 2 -1
lr 1 0 -1
ll -1 0 -1


#height/width pixels
height 500
width 500

#camera x y z
camera 0 0 10


#light point/directional x y z r g b
light directional 1 0 -1 .6 .6 .6
light directional -1 -1 -1 .3 .3 .3

#use material
use rock

object 
	path obj/angel.obj
end