Table of Contents
This chapter describes our implementation of ray-tracer, along with some related topics.
We don't even try to explain here how ray-tracing algorithms work, as this is beyond the scope of this document. Moreover, the ray-tracer is not the most important part of our engine right now (OpenGL real-time rendering is). This means that while our ray-tracer has a couple of nice and unique features, admittedly it also lacks some common and important ray-tracer features, and it certainly doesn't even try to compete with many other professional open-source ray-tracing engines existing.
Many practical details related to using our ray-tracer are mentioned in rayhunter documentation. Many sample images generated by this ray-tracer are available in the rayhunter gallery.
The basic data structure for ray-tracing is an octree based on
triangles, that is TTriangleOctree
instance.
If you want to ray-trace a scene, you have to first build
such octree and pass it to a procedure that
does actual ray-tracing. Note that the quality of the octree is critical
to the speed of the ray-tracer. Fast ray-tracer requires
much deeper octree, with less items in leafs (LeafCapacity
property) than what is usually sufficient for example
for collision detection in real-time game.
To calculate triangles for your octree you should use the
Triangulate
method of VRML geometry nodes.
Triangles enumerated by this method should be inserted into the octree.
If you use TCastleSceneCore
class to load
VRML models (described in Section 3.10, “VRML scene”)
you have a comfortable method CreateTriangleOctree
available that takes care of it all, returning the ready octree
for a whole scene.
The Triangulation
method is also admittedly responsible
for some lacks in our ray-tracer. For example, ray-tracer doesn't handle
textures, because triangulation callback doesn't return texture coordinates.
Also normal vectors are not interpolated because triangulation callback
doesn't return normal vectors at the triangle corners.
This is all intended to be fixed one day, but for now ray-tracer is not
that important for our engine.