assignment 2 & 3
Ray Tracing
Finished project
Spheres, normal triangles, planes, lights, reflection, refraction, and 3 types of sampling.
Spheres1
Adapted sampling threshold=.04
basic n=1
jitter n=3
60 seconds
adaptive
average 8.87 samples per pixel
96 seconds
spheres2
jittered sampling n by n grid. sampmethod 2
n=1
n=3
n=5
From sample images
To show my ray tracer produces standard results with spheres, normal triangles, lights, & shading.
bear
Improved
bottle
Made from triangles
gear
Made from triangles
Hand
Made from triangles
my own scenes
Flower
Stem & leaf normal triangles, directional light, area light (soft shadows)
creepy-ish eye
Spot light (in degrees), spheres, color, refraction, camera
inner=10º, outer=60º
5º, 20º
5º, 10º
5º, 5º
s2.scn
Reflection, refraction, normal triangles, aspect ratio, plane
Art contest entry
s1.scn
Triangle, spheres, area light, spot light, directional light
Basic sampling n by n grid
n=1
n=3
n=5
Thoughts
Additions to scn file:
- plane x y z nx ny nz (position and normal)
- nsamp n (sample n by n grid)
- sampmethod n (0=basic, 1=adaptive, 2=jittered)
- threshold t (for adaptive sampling. difference in luminance on 0-255 scale)
- area_light r g b x y z u v w a d c (color, position, width vector, height vector)
I spent a lot of time on how to hold & pass data around. I have a Point, Vector, Ray, Surface, Light and Color (floats) classes. Each light & surface has its own c++ vector, and I loop through them all where appropriate. Since I use vectors, I didn't need max_vertices and normals, though its in the code.
I ended up using Guy's image plane code from 10/15/18. I use a 'Intersection' struct to hold relevant info if a ray hits a surface. If found, I call applylight(), which calls the lighting code. I followed Guy's pseudo code.
I clamp the color values, and use image.cpp code for file output.
I definitely struggled with this assignment. I messed up lots of things in the beginning, like image plane and sphere intersection, and other simple but hard to find errors. My implementation isn't great, but works pretty well for spheres and triangles with various lights.
Refraction for going into normal triangles works, but is iffy for coming out of them. I think I'm missing something small.
For the area lights, I send rays from random spots in the corner, see how many are blocked, and use a percent amount for the lighting.
Adapted doesn't work as well as I'd like, but I have the right idea. I take 5-50 samples based on the corners, random rays, and luminance. If the difference in samples is greater than the threshold, I take more. I'd implement a grid type system if I had more time, figure out what part of the pixel has greater differences, and shoot more rays only in that sub section. I'd also make pipelining and memory optimizations so the code runs much faster.
Ray tracer is super interesting. I wish I was better at it!