Skip to main content

Posts

Showing posts from August, 2019

Simple Ray Tracer - Part 2

The previous Code already provides the base of our ray tracer. In this post I will provide 3 examples on how can we extend this functionality. Ray trace with two light sources The following snippet describes how two light sources will affect how the sphere is rendered Vec3 intersect, normal; double depth = IntersectSphere(p0, p1, s, intersect, normal); if (depth < 1 ) { Vec3 finalColor1 = l1.CalculateDiffuse(intersect, normal, s.color); Vec3 finalColor2 = l2.CalculateDiffuse(intersect, normal, s.color); Vec3 finalColor (finalColor1.x + finalColor2.x, finalColor1.y + finalColor2.y, finalColor1.z + finalColor2.z); finalColor.Clamp( 0.f , 1.f ); DrawPixel(x, y, finalColor); } else { DrawPixel(x, y, s_bgColor); } To recap, we first identify the intersection between the line segment and the sphere (Moved to a function). If the intersection lies within the drawing box (depth betw

Simple Ray Tracer - Part 1

With the advent of newer and faster video cards, real time Ray Tracing is the hype. Although Ray Tracing has been used in the Visuals Industry (Cinematography, architecture, design) for many years, it hasn't been used in games for performance reasons. The number of calculations needed to render an image exceeds the time constrains games require. So, what's Ray Tracing? Wikipedia provides a very good introduction to the subject [ wiki ] ... rendering technique for generating an image by tracing the path of light as pixels in an image plane and simulating the effects of its encounters with virtual objects  ... The purpose of this post is to create the simplest 3D Ray Tracer I can think of.  This means that there are several constrains we will follow: Orthogonal Projection: All rays are cast parallel to each other Sphere: For simplicity, a sphere requires relatively simple math to calculate intersections and Normals Only one object will be rendered.  This r