|
Post by sbphillips on Aug 24, 2020 23:05:52 GMT
Need some input on tips & tricks to speed up my rendering.
I've built my ray tracer using Python 3. This is my first Python effort. Most everything is done uses classes to implement the various pieces. Unfortunately it is really slow, especially at larger dimensions. It took hours to render the first image in Chapter 11 - Reflection & Refraction at 800x400. I've seen references to speeding up the code on this site, but I have been unable to implement any of the concepts. I've seen one site where Numpy was used to speed up another ray tracer, but again I don't know enough to implement it to my code. I've read that using OOP is slower in Python because of the overhead. Any comments? I would appreciate any somewhat detailed implementation details.
I've got an old laptop with a single core and two threads so multiprocessing won't get the times down to anything reasonable. Could others provide their programming language and render time?
|
|
|
Post by Jamis on Aug 25, 2020 4:27:55 GMT
One of the biggest ways to speed up your render is to make sure you're caching your inverted matrices. Having to recalculate the inverse of a matrix every time it is referenced is a _lot_ of wasted effort. I've seen some people report speed-ups of several orders of magnitude, just from caching their inverted matrices. If you haven't done that yet, that might be a good place to start.
|
|
|
Post by linuxdeveloper on Jan 24, 2021 9:49:38 GMT
I wrote my ray-tracer in Python as well and I also was seeing multi-hour rendering times. As Jamis says caching inverted matrices was a huge improvement! I am now able to render frames of size 1600 x 800 in approximately 30 minutes. I am hoping to be able to improve things even further by utilizing a profiler.
Anyone have any recommendations of the best free profiler for Python?
|
|
|
Post by mystic on Dec 29, 2021 17:48:29 GMT
One of the biggest ways to speed up your render is to make sure you're caching your inverted matrices. Having to recalculate the inverse of a matrix every time it is referenced is a _lot_ of wasted effort. I've seen some people report speed-ups of several orders of magnitude, just from caching their inverted matrices. If you haven't done that yet, that might be a good place to start. Wow, thank you so much for the tip! Rendering chapter 6 of the book at 500x500 used to take 10+ minutes, but now it only takes 10 seconds!
|
|
|
Post by sbphillips on Dec 30, 2021 17:40:45 GMT
Is your code available somewhere or can you explain what changes you made?
|
|
|
Post by javoronok on Apr 26, 2022 7:52:19 GMT
We usually refer to Python as a programming language with dynamic typing. In a Python program, everything is an object; in other words, every time Python code processes data, it needs to unpack an object wrapper. Inside the for loop, each iteration needs to unpack the objects, check the type, and calculate the reciprocal. All those 3 seconds are spent checking types. So to speed up data for Python, we decided to use the services of salvagedata.com since we couldn't find a way out of this situation by ourselves.
|
|