Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Goal
Produce a raytracer in Matlab to draw spheres, with the following capabilities:
Methods
Points and direction vectors are represented by homogenous coordinates so that they can be
transformed by composable scale, translation, and rotation matrices.
The camera is a pinhole model, and its matrix encodes its position, size, and direction. Focal
length is encoded seperately from the camera matrix, to accomodate both finite and infinite focal
lengths.
The scene is represented by a struct. It has fields for the camera, the camera's focal length, the
spheres, and the light sources. The spheres and light sources fields are cell arrays of structs.
A light source struct has fields for its color, and either position or direction. It can be given a
position to be a point source, or given a direction vector to be "at infinity".
A sphere struct has fields for its center point, radius, shinyness, opacity, albedo function or color,
and the option for it to have intersections with all complex points. Shininess controls how much
of the sphere's reflection is specular versus Lambertian. If the albedo field is set to a function
handle, the function is evaluated at each point on the surface of the sphere; this can be used to
perform texture mapping.
Results
strictlyreal.png
real.png
real2.png
Strictly real
Real component
imag.png
abs.png
button.png
Imaginary component
Absolute value
sum.png
sum2.png
sum5.png
Real component
- imaginary component
Real component
- 2 imaginary component
Real component
- 5 imaginary component
gloss.png
semigloss.png
semigloss-complex.png
Specular reflection
snowman1.png
snowman2.png
snowman.png
Snowman.
Intersecting spheres.
Rotated camera
beachball.png
beachball-complex.png
beachball-complex2.png
earth.png
Texture mapping
Discussion
Mutual illumination and shadowing
The quality and detail of the normalized real images is astounding. In real2.png and
beachball-complex2.png, the sphere appears to be casting a shadow and a reflection on a
background surface. The image is smooth; there are no hard pixel discontinuities. This was all
made with a generalization of the algorithm that produced the stock strictlyreal.png.
The glow in the real component images (real.png, semigloss-complex.png, beachball-
complex.png) looks like a diffused reflection of the light source. Could it be used to used to
illuminate other spheres in the scene in a realistic way? Furthermore, the shadow visible in the
normalized images (real2.png, beachball-complex2.png) is a negative color in the normal
image. Could that be used to cast a shadow on other objects in the scene?
Some attempts were made to implement the mutual illumination and shadowing as discussed
above, but it will looks like it will require a significant restructuring of the existing code to do so.
This is where the further work lies.
Anti-aliasing
The part of the image with both a real and imaginary part consists of a glow or reflection off the
surface of the sphere, as seen in real2.png. Subtracing a multiple of the imaginary component
from the real component makes the glow smaller, as seen in sum.png, sum2.png and sum5.png.
At a sufficient multiple, the glow only serves to smooth the edge of the sphere, effectively anti-
aliasing it without subpixel calculations.
Desktop backgrounds
No discussion of raytracing is complete without desktop backgrounds (maybe).
The normalized real images of illuminated spheres are aesthetically pleasing and simple, so they
make good desktop backgrounds. High resolution images of the beachball and grey ball are
provided in the scenes directory and online:
http://csug.rochester.edu/u/clehner/raytracing/greyball-1280.png
http://csug.rochester.edu/u/clehner/raytracing/beachball-1280.png