Post by tew468 on Jan 7, 2020 19:32:40 GMT
I am using the python Behave module (a cucumber-like module for Python) to implement and run the .feature file tests for my Python3 implementation of the code.
In the interest of community, I'm sharing what I've gotten to run so far through chapter 8 (spheres only, with shadows),
as well as some simple analysis, in the hope of sparing someone else a dented wall and forehead.
The code and feature/step files is at github.com/tewarfel/RayTracerChallenge_1.git
I make no claims of optimality or clarity, but am simply archiving the current state for my future reference.
I'm happy to share with anyone who is interested.
Per the book, the key data structures are 4-element floating-point vectors (representing 3D directional vectors and 3D points in space), 3-element floating-point vectors (representing a color), and 4x4 floating-point matrices representing 3D transform operations.
The 3 and 4-element floating-point vector data structures (named Vec3 and Vec4, respectively) are subclassed from the Python Collections "namedtuple" object. This allows their data to be accessed either as a 1-D array or list of vector elements (e.g. vect1[0], vect1[1]), or by "vector.element" names (e.g. vect1.x, vect1.y). The 4x4 float matrices are handled as Numpy Ndarrays. This simplifies implementation of matrix/vector multiplication by allowing use of the numpy matmul(), as well as simplifying vector/scalar operations.
For the "putting it together" example (end of chapter 7) with shadow addition (from chapter 8), I rendered the scene onto a 100 pixel wide by 50 pixel tall canvas.
System was a 2013 MacPro with 32GB RAM, 6-core 3.5GHz Intel Xeon E5 processor (Ivy Bridge), running macOS High Sierra, version 10.13.6. Python version was 3.7.5
Per the book, the key data structures are 4-element floating-point vectors (representing 3D directional vectors and 3D points in space), 3-element floating-point vectors (representing a color), and 4x4 floating-point matrices representing 3D transform operations.
The 3 and 4-element floating-point vector data structures (named Vec3 and Vec4, respectively) are subclassed from the Python Collections "namedtuple" object. This allows their data to be accessed either as a 1-D array or list of vector elements (e.g. vect1[0], vect1[1]), or by "vector.element" names (e.g. vect1.x, vect1.y). The 4x4 float matrices are handled as Numpy Ndarrays. This simplifies implementation of matrix/vector multiplication by allowing use of the numpy matmul(), as well as simplifying vector/scalar operations.
For the "putting it together" example (end of chapter 7) with shadow addition (from chapter 8), I rendered the scene onto a 100 pixel wide by 50 pixel tall canvas.
System was a 2013 MacPro with 32GB RAM, 6-core 3.5GHz Intel Xeon E5 processor (Ivy Bridge), running macOS High Sierra, version 10.13.6. Python version was 3.7.5
Key findings:
- Without profiling or reference counting, execution time was 34 seconds.
- Without profiling (but with Vec3/Vec4 reference counting), execution time was 36 seconds.
- With profiling and Vec3/Vec4 reference counting, program execution time was 158 seconds, but running time was 14 minutes. (not sure why - I'm new to using yappi within Pycharm)
- Call graph profile analysis (multiple runs) shows between 89-96% of time is spent in "namedtuple".
- Reference tracking showed that total number of Vec4 instances was 288,147 but that a maximum of only 18 were active at any one time.
- Similarly, the total number of Vec3 instances was 33,381 but that a maximum of only 16 were active at any one time.
While a faster Vec3/Vec4 implementation would speed things up, I'm going to hold off for now while continuing to implement a few more renderer capabilities, and re-benchmark after I get planes, cubes, and triangles working with reflection / refraction.
-Tom