Posts

Part 7: Object Lights & Path Tracing

Image
In the last (and the most challenging) part of this ray tracer, two main features are added: 1. Object Lights Until now, the ray tracer was only supporting lights that are not visible in the scene such as PointLight , AreaLight etc. No ray intersection tests were being performed for the light objects. In this version, two types of object lights ( LightMesh and LightSphere ) are added. These lights provide illumination for the scene and they are also objects that are included in the BVH and being tested against intersections with the sent rays. For the implementation, there are a few points to note: - For object lights, I used multiple inheritance. LightMeshes inherit from both Light and Mesh classes, while LightSpheres inherit from both Light and Sphere classes. These classes also have a property keeping the radiance of the light object defined in the xml. - Two new attributes are added to the Hit class: isLight to indicate whether the object hit is a light source, radiance to keep th...

Part 6: BRDFs

Image
The sixth part of the ray tracer contains less complicated features compared to the previous parts. BRDFs control how much light is reflected from a surface for each incoming and outgoing light direction. They are used for computing diffuse and specular shadings at a given point. Until now, only Blinn-Phong shading model was supported. In this part, the following types of BRDFs are implemented: 1. Phong BRDF 2. Modified Phong BRDF 3. Normalized Modified Phong BRDF 4. Blinn-Phong BRDF 5. Modified Blinn-Phong BRDF 6. Normalized Modified Blinn-Phong BRDF 7. Torrance-Sparrow BRDF The only difference of the modified versions from the original versions of the Phong and Blinn-Phong BRDFs is that the cosine terms in the denominators are removed while the rest stays the same. Normalization is performed in order to ensure that the BRDFs are energy conserving. The formulas also ensure that the summation of diffuse reflectance constant (kd) and specular reflectance constant (ks) is less than or e...

Part 5: HDR Imaging & Advanced Lighting

Image
For the fifth part of the ray tracer, the following features are implemented: 1. HDR Imaging and Tonemapping Until now, only PNG format was supported for saving rendered scenes. RGB values obtained by shading calculations are fractional and they are not limited to any range. However, for saving them in PNG format, the values were being clamped to 0-255 range and converted to integers, which results in removing a considerable amount of details from the image. With HDR imaging , RGB values are no longer clamped and they can be represented with floating points by saving the scenes in EXR format. The RGB values obtained from ray tracing can directly be used for HDR images, but they have to be tonemapped to be saved in PNG format. For tonemapping, Photographic Tonemapping by Reinhard (global operator) is implemented. With the HDR imaging support, the ray tracer is also able to use HDR texture images in EXR format. In order to read HDR images, tinyexr is used, while for writing HDR images ...