writing a raytracer


SuperJer just had some time to spare and before getting bored he started to write a raytracer from scratch and write about it on the intertubes:

“Ray-tracing works sort of like a camera in real life, but in reverse. With a camera (or your eyes, for that matter), rays of light from the environment enter the lens and hit the film/digital chip/meaty eye cells. Something magical happens where the light hits and we get an image!
With ray tracing, we start at each point on our “film” or image, and blast a ray out of our camera lens and see what it hits. What it hits determines the color and brightness at that spot on the film. Of course by “film” I mean digital image, and by “spot” I mean pixel.
I decided my entire program would be centered around one function, called raytrace(). The idea is this: You give raytrace() a starting point and a direction, and it follows that ray until it collides with something in my virtual environment. It returns the color of the object it collided with.
When generating a 3D image, raytrace() will find the color for just ONE pixel in the result image. By running raytrace once for each pixel, we can get the whole scene! Ray-tracing is kind of slow because, for example, in a 1 megapixel image you’d have to run it 1 million times.”

He even has put up some pictures and videos:

You can even get the whole sourcecode (C++ with no dependencies whatsoever) from his site. Continue at source…

Source: http://www.superjer.com/pixelmachine/

Comments are closed.