|
|
Pre-calculations |
|
The example image on the previous page consisted of only 14 triangles;
but more complex images will have thousands of shapes (if not more).
So, it's important to start considering performance issues right from the beginning.
Analysis of the YRTTriangle.cpp code shows that many of the intermediate calculations there
do not depend on the current ray being cast, but on the coordinates of triangle's vertices.
As such, those calculations can, of course, be done once per rendering, and then the calculated values reused for all rays:
- edge vectors,
- normal vector to the triangle,
- whether the triangle is (close to being) degenerate,
- edge dot products used in intersection checking.
What kind of performance gains can we expect?
With only 12 triangles in the crown (and 2 for the base), the performance gain is equal to 27%; this takes the scene rendering from .78s to .57s.
With 120 triangles, the gain is 35% (5.41s to 3.51s); and with 1200 triangles - 37% (51.99s to 32.52s).
Not bad considering the minimal changes to the code; of course there's more that can be done about performance, but I'll revisit this issue later.
And the sources to the above - in a C++Builder project - can be found
here.
Top
|
Comments |
Alas! No comments yet...
|
|
Top |
|
Top
|
|
|