Hello. I'm really enjoying the book. Currently finishing up the Reflection and Refraction chapter. Would like to reproduce the "before Fresnel" and "after Fresnel" pictures on page 159 (PDF version). Would it be possible to post description of the scene, including materials and light information? Thanks!
It's not EXACTLY the same image from the book (the light source is in a different position, for one thing; I must have done some fiddling with the file after producing the image for the book), but it's close. Running it just now on my reference implementation, it produces the following image:
BTW, the 300x300 render completes in about 8 minutes. I'm using Python and have not done any code optimization. I did use multiprocessor library (on 12 cores). Does 8 minutes for this image sound too slow?
That looks great! As for 8 minutes, that seems a bit on the long side. My Ruby version renders the 300x300 image in 24 seconds. Mine is somewhat optimized, but there's quite a bit of optimizations that could yet be done. I'm curious where your renderer is spending most of that time.
>> My Ruby version renders the 300x300 image in 24 seconds
Wow! I'm glad I asked . Are you using any kind of parallel processing?
>> I'm curious where your renderer is spending most of that time.
Me too. I'll have to figure out how to do profiling in Python and will post here the results. I should have started the profiling stuff earlier, but the book is so interesting that I don't want to take any detours!
Also, I'm guessing that my renderer is so slow because Python is an interpreted language.
Yeah, that 24s render was done with six processes running in parallel. The biggest wins generally come from caching the results of matrix inversions, though. Are you caching your inverted matrices? If not, that's probably some low-hanging fruit that can really make a big difference.
> Also, I'm guessing that my renderer is so slow because Python is an interpreted language.
That can be part of it, but Ruby is interpreted, too, and that's where I got the 24s render. With the right optimziations, and the worst bottlenecks removed, I would expect Python to run pretty quick.
>> The biggest wins generally come from caching the results of matrix inversions
Yes, that's exactly what the profiler showed. After caching matrix inversion in shapes, I got 55 seconds for the 300x300 image. Replacing the self-made matrix inversion with built-in (from python numpy library) reduced the time to 27 seconds, but that would be cheating
The next bottleneck (according to the profiler) is multiplying matrix by a vector, although I don't see how that could be improved. Perhaps reducing float precision. But I'm not trying to write the world's fastens renderer. It's fast enough for me
Thanks again for a the wonderful book! I hope you are secretly working on another programming challenge book.
Hi Steve. My code is still work in progress I have seen Python code from another user on this forum who very kindly posted his Python code on github. It's much better than what I have right now. Here is his post: forum.raytracerchallenge.com/post/650
As far as speed improvements, I did set a separate class attribute for inverse matrix in Shape. Otherwise, the tracer would have to do the very expensive inverse matrix calculation of the same matrix for each ray intersection. This optimization takes just a couple of lines of code and gives you 5+ times speed improvements.