JOSH LELAND | PHANTOM BADGER
Copyright © All Rights Reserved
Graphics 2's first assessment was an introduction to Ray Tracing rendering. The above is my final submission, this module is currently being assessed so there will be no download for this piece of software for now.
Our assessment tasked us with fulfilling the following criteria with our work:
An optional addition to the project was to modify the framework we had been given to create an Orthographic camera view, something I managed to accomplish towards the end of the assignment.
Ray Tracing is a form of rendering that is not run at real-time, it is done by firing a series of simulated light rays from the camera, and using what they intersect with to determine the colour of the pixel at that position on screen. The inverse of this is through the use of Projection with the Rasterisation Pipeline, which features the use of triangular geometric models called polygons.
On this page Im going to break down how I accomplished the above tasks;
First of all it is important to note that a Ray is represented by the equation P(t) = S + vt, where P(t) is a given point along the ray, S is the origin of the ray, v is the vector, and t is time.
Hit Detection with planes was relatively simple. If a ray intersects a plane at point P(t) then it satisfies the equation:
(S+vt) . n + d = 0
where n is the plane's normal and d is the plane's offset.
It starts getting a bit more tricky after that however, and a lot more Math intensive.
A Ray's intersection with a Sphere can be analysed using the equation
((S+vt) - C) . ((S+vt) - C) = r2
Where C is the centre of the circle and r is the radius. This may seem simple, but when it comes to calculating the t value from this equation we get:
t= (-v . (S - C) (+-) SquareRoot((v . (S - C))2 - (v . v)((S - C) . (S - C) - r2 )) / v . v
although, with the proper formatting, this does look a lot less daunting!
And arguably, triangular intersection is harder than that! Triangular intersection involves checking whether a ray collides with an infinite plane constrained by 3 given points. The result requires the use of 'Barycentric Co-ordinates,' and this website can explain it far better than I can: http://www.blackpawn.com/texts/pointinpoly/
Okay!, thats the basic hit detection done, Im not going to go into depth on the Diffuse or Specular equations, as this website doesnt have nearly enough formatting tools to present it in a way that isnt confusing and silly. For Diffusion I used the Lambert model, and for Diffuse I used the Blinn-Phong model.
Reflection and Refraction posed a challenge, if not just because it was difficult to discern how to translate the equations into code, the equation used to find the vector of a reflected ray is given by:
Reflection = v - 2(v . n)n
And Refraction was given by:
Refraction = r1/r2 i - (n1/n2cosThetai + SquareRoot(1- sin2Thetai)n
Where r1 and r2 represent the refractive coefficients of each material, and i represents the vector going into the material, with j representing the vector refracted by the material (conveniently, this equation was formed so we wouldnt need j, just its refractive coefficient).
One of the final additions I made was a simple anti-aliasing quality, originally the ray tracer used one ray per pixel, with my latest addition, it now does 9 and averages the colour between them, (one ray in the center, one in each corner and one in the middle of each side).
And thats the fundamentals of how I created my Ray Tracer! I hope you learnt something from my weird explanation-type-thing.