Pathtracing algorithm with code and example renderings