Thursday, November 1, 2012

Simple and Easy Ray Tracer

This is possibly one of the simplest ray tracer, written not to technically achieve anything, but to understand the basic theory. This code is minimal, written in C, uses just the algorithms needed to trace, very less pointers usage, and no use of any external libraries other than ones which come packaged with Gcc by default. The code implements the following lighting models: ambient, diffuse, specular, hard shadows, reflections and one sided refractions. Please find the download link after a sample output, it is shared with the most relaxed license.

    Download [Zip, 16kb]    

This was done for a one day workshop at BITS Pilani Hyderabad Campus few days ago (for their technical fest ATMOS). The challenge was to teach introduction to computer graphics and the basic theory of ray tracer, in one day, to a wide range of undergraduate students who may not be coming from a computer science background. I hope the students gained something and found it interesting.

Our team: Adi Shayan, Sneha Venkatraman, Yash Agrawal, Shiben Bhattacharjee, Naveen Kumar, Nitish Tripathi


  1. that's a v. geeky post! nice :-)

  2. Hi, can you explain a little bit how the objects creation works? , the sphere's ecuation is X^2 + Y^2 + Z^2 = r2, and in your code are many triangles, in the camera struct they are some position and look (obviously), but these vectors hori, vert, up.

    1. Hi, it's a bit difficult to understand your comment but from what I can get out: the sphere creation code uses "Hierarchical Triangular Mesh" method instead of trigonometric methods.