Ray Tracing in One Weekend:

Part One - An Introduction

Path traced sphere render.

It took me long enough, but I finally dipped my toes into the waters of computer graphics earlier this year. Continue reading to learn about what ray tracing is and why I decided to explore it.


Contents


What is Ray Tracing?

Minecraft (2011 Initial Release, 2020 Path Tracing Update) Minecraft (2011 Initial Release, 2020 Path Tracing Update)

Put simply, ray tracing is a rendering technique that can accurately simulate the lighting of a scene.

Ray tracing generates an image by determining the color of each pixel of the image in a mathematically formulated scene. In the simplest example, the color of each one of these pixels is determined by sending a ray from the camera into the scene, and back to its light source.

The ray will potentially collide with - and bounce off of - scene objects. Each of these scene objects has intrinsic properties, such as reflectivity, refractive index, and roughness. The interactions of the ray among all these objects are combined with the light source to determine the final color and intensity of the pixel. This process is repeated for the whole image, pixel by pixel.

You may be thinking: “Why send a ray from the camera instead of from the light source?” The reason is a matter of efficiency; rather than sending rays out from the light in all directions, it’s much more effective to only trace the bare minimum - which in our simplistic example - is one ray for each pixel of the image.

Ray Tracing Illustration


What is Path Tracing?

Path traced glass dragon

Path tracing is similar to ray tracing, but much more intensive. Hundreds to thousands of rays are traced through each pixel of the image, with numerous bounces off of - or through - objects, before reaching the light source (or hitting a specified “bounce limit”) to generate more accurate color and lighting information.

Minecraft (2011 Initial Release, 2020 Path Tracing Update)

Path tracing, as you may have guessed, is more accurate a simulation than ray tracing, simulating soft shadows, caustics, and global illumination. However, it is more “brute-force.” Without enough rays through each pixel or simulated bounces for each ray, the final image will be ridden with noise.

Also - fun fact: I learned recently path tracing requires light sources to have physical size instead of “point lights” used in ray tracing or rasterized graphics… which brings me to my next point…


What is Rasterization?

Rasterization is the vast majority of games have used in to display 3D scenes on 2D screens. Using rasterization, objects are represented with virtual triangles (aka polygons). These triangles all have corners, and these vertices contain data of such attributes as position, color, texture, and the surface normal (orientation).

The triangles are eventually converted to pixels when being rendered. Each pixel can be assigned an initial color value from the data stored in the triangle vertices. Further pixel processing or “shading” including changing color based on how lights in the scene hit, and applying one or more textures, combine to generate the final color applied to a pixel.

Vertices being converted to pixels

Rasterization is used in real-time computer graphics and while still computationally intensive, it is less so compared to ray tracing.

The following images are from rasterized game engines
Super Mario 64 (1996) F-Zero X (1998) The Legend of Zelda: Ocarina of Time (1998)
Solid Snake of Metal Gear Solid (1998) Crash Bandicoot (1996) Tekken (1995)
Assassin's Creed Unity (2015)

A Happy Medium (For Now)

Rasterization and ray tracing can be combined! Rasterization can determine visible objects relatively quickly, while ray tracing can be used to improve the quality of reflections, refractions, and shadows.

Hybrid ray tracing


Practical Applications of Ray Tracing

Applications of ray tracing are many and varied:

Control(2019) Battlefield V(2018) Battlefield V(2018) (2019) (Ray traced building) Ray traced acoustics (Ray traced building)


An Abbreviated Graphics Timeline

I was born in 1995 - an exciting year for computer graphics. Toy Story - the first entirely computer-animated feature film - would be released. Homer Simpson, of The Simpsons fame, would be computer-animated for a Treehouse of Horror Halloween episode. The Sony Playstation would be released in the United States.

Toy Story Homer Simpson Playstation

Technology had come a long way since 1980’s Battlezone, which with its wireframe vector graphics, was one of the first big “3D” successes in any medium. Thankfully, I was able to play a version of Battlezone at a young age, and naturally noticed (and took a major interest in) the increasing fidelity of computer-generated graphics growing up.

Battlezone(1980) Missle Command(1980) Donkey Kong(1981) Tempest(1981) Pole Position(1982) Mario Bros.(1983) Dragon's Lair(1983) Marble Madness(1984) Paperboy(1985) Super Mario Bros.(1985) The Legend of Zelda(1986) Metroid(1986) Castlevania II: Simon's Quest(1987) Mike Tyson's Punch-Out(1987) Mega Man 2(1988) John Madden Football(1988) SimCity(1989) Super Mario Bros. 3(1990) Super Mario World(1990) F-Zero(1990) Another World(1991) Wolfenstein 3D(1992) Virtua Racing(1992) Mortal Kombat(1992) Alone in the Dark(1992) Virtua Fighter(1993) Aladdin(1993) Doom(1993) Donkey Kong Country(1994) Panzer Dragoon(1995) Quake(1996) Super Mario 64(1996) Crash Bandicoot(1996) Star Fox 64(1997) Gran Turismo(1997) Half-Life(1998) Metal Gear Solid(1998) Sonic Adventure(1998) Shenmue(1999) Madden 2001(2000) Gran Turismo 3: A-Spec(2001) Grand Theft Auto III(2001) Metal Gear Solid 2: Sons of
Liberty(2001) Super Smash Brothers
Melee(2001) Jet Set Radio Future(2002) Super Mario Sunshine(2002) Splinter Cell(2002) The legend of Zelda: The Wind
    Waker(2003) Viewtiful Joe(2003) Far Cy(2004) Half-Life 2(2004) F.E.A.R.(2005) Call of Duty 2(2005) Rockstar Games Presents Table
    Tennis(2006) Dead Rising(2006) Crysis(2007) Heavenly Sword(2007) Halo 3(2007) Team Fortress 2(2007) Grand Theft Auto 4(2008) Mirror's Edge(2008) Flower(2009) Uncharted 2: Among
    Thieves(2009) God of War III(2010) Gran Turismo 5(2010) Red Dead
    Redemption(2010) Witcher 2: Assassin of
    Kings(2011) Uncharted 3: Drake's
    Deception(2011) Rage(2011) Journey(2012) Max Payne 3(2012) Killzone: Shadow Fall(2013) Ryse: Son of Rome(2013) Sunset Overdrive(2014) Far Cry 4(2014) The Order: 1886(2015) Star Wars: Battlefront(2015) Firewatch(2016) Uncharted 4: A Thief's End(2016) Resident Evil 7(2017) Horizon: Zero Dawn(2017) Hellblade: Senua's Sacrifice(2017) Shadow of the Colossus(2018) God of War(2018) Red Dead Redemption 2(2018) Ace Combat 7: Skies Unknown(2019) Control(2019) Call of Duty: Modern Warfare(2019) Death Stranding(2019)


Why Explore Ray Tracing?

To put it succinctly, I chose to learn more about ray tracing for the following reasons:


#graphics #ray-tracing-in-one-weekend