Day 14 - Ray Tracing II

Ray + Sphere Collision Review

Starting Code

  • a = dot(d,d)
  • b = 2 * dot(d, sub(o,center))
  • c = dot(sub(o, center), sub(o,center)) - (r * r)

t=b±b24ac2at=\frac{-b\pm\sqrt{b^2-4ac}}{2a}

Getting the collision Point

Two possible values for t

What is both less than 0?

What if one greater than 0?

What is both greater than 0?

Shading the sphere

Calculate the nomrmal at the collision point

Calculate the diffuse ilumination

Add the ambient component

Adding spheres

Run the ray tracer in a for loop

Store the location of the closest collision and the object at that location

If there is no collision, ose the background color.

Ending Code