You are on page 1of 3

HW5

December 3, 2017
Andrew Emrazian - u0349111
CS 4600 – Computer Graphics

Part 1 – Ray Casting

1 Vector3f trace(
2 const Vector3f &rayOrigin,
3 const Vector3f &rayDirection,
4 const std::vector<Sphere> &spheres)

Implementing this function highlights most of purpose of ray tracing. For each pixel, shoot a ray to determine which
sphere (if any) are intersected. To do this, I made use of the Sphere::intersect function and stored the shortest
distance along with the corresponding sphere. Once all the spheres were visited, I determined the point (P) of the
intersection.
First, I returned red if there was an intersection. Then, I returned the color of the sphere.

Part 2 – Shadow Rays

Using the trace function, I added tracing from point P on the sphere to each light source in direction L to determine if P
is lit by the source.

1
Part 3 – Illumination Models

Frist, I replace the pixel color determined from part 2 with a diffusion model component as presented in lecture 14
shading slides.
1 Vector3f diffuse(const Vector3f &L, // direction vector from P to light source
2 const Vector3f &N, // normal at this point on the surface
3 const Vector3f &diffuseColor,
4 const float kd // diffuse reflection constant
5 )

The body is implemented with the following model

ED = Ii ∙ CD ∙ k d ∙ max(cos 𝛼𝛼, 0)
Ii - Intensity of light i - 1/ light count
CD – diffuse color (RGB) - diffuseColor
k D – diffuse coefficient (material) – kd
cos 𝛼𝛼 = L ∙ N – dot product of light direction and surface normal – L.dot(N)

2
Lastly, add the specular component by implementing the Phong reflection model
1 Vector3f phong(const Vector3f &L, // direction vector from P to light source
2 const Vector3f &N, // normal at this point on the surface
3 const Vector3f &V, // direction pointing towards the viewer
4 const Vector3f &diffuseColor,
5 const Vector3f &specularColor,
6 const float kd, // diffuse reflection constant
7 const float ks, // specular reflection constant
8 const float alpha) // shininess constant

The body is implemented with the following model

ES = Ii ∙ CS ∙ k S ∙ max(cos 𝛽𝛽, 0)h


Ii - Intensity of light i - 1/ light count
CS – highlight color (RGB) - specularColor
k S – specular coefficient (material) – ks
cos 𝛽𝛽 = R ∙ V – dot product of light direction and surface normal – R.dot(V)
R = 2N (N ∙ L) - L
h – shininess constant – alpha

You might also like