{"id":136,"date":"2018-04-14T17:17:03","date_gmt":"2018-04-14T14:17:03","guid":{"rendered":"http:\/\/kadircenk.com\/blog\/?p=136"},"modified":"2019-02-07T19:39:44","modified_gmt":"2019-02-07T16:39:44","slug":"trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing","status":"publish","type":"post","link":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/","title":{"rendered":"Trace the Ray &#8211; Part 3 (Transformations, Instancing, Distribution Ray Tracing)"},"content":{"rendered":"<p>Hello trace-masters!<\/p>\n<p>In my third assignment, my task was to implement those capabilities to my raytracer:<\/p>\n<ul>\n<li>Transformations (Scaling, Rotation, Translation)<\/li>\n<li>Instancing<\/li>\n<li>Distribution Ray Tracing\n<ul>\n<li>Depth of Field<\/li>\n<li>Motion Blur<\/li>\n<li>Soft Shadows<\/li>\n<li>Glossy Reflections<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Let&#8217;s examine them together!<\/p>\n<p><!--more--><\/p>\n<p>Apart from those three main capabilities, I have also added those ones:<\/p>\n<ul>\n<li>.PLY file format parsing for meshes (<a href=\"https:\/\/github.com\/ddiakopoulos\/tinyply\" target=\"_blank\" rel=\"noopener\">tinyPLY 2.0<\/a>)<\/li>\n<li>Smooth shading of meshes (by interpolating vertex normals using barycentric coordinates)<\/li>\n<li>Simple camera type, where FovY angle is given instead of image plane L, R, T, B coordinates.<\/li>\n<\/ul>\n<p>Moreover, I rewrote my refraction code segment from zero over again to simulate glass objects. By doing so, I was able to significantly improve my glass rendering quality (screenshots are provided in between the paragraphs).<\/p>\n<h4>Transformations<\/h4>\n<p>To implement trasformations, I have added a 4&#215;4 Matrix4 class, so that I could convert the given transformations into their Matrix4 forms, and transform Points and Normals by multiplying them with those 4&#215;4 transformation matrices.<\/p>\n<p>While parsing the input scene file, I push the Transformations of the Mesh in their given order into a <strong>std::vector&lt;Transformation&gt; <\/strong>then create the composite M matrix by multiplying those transformations with each other. At the end, each Vertex of each Triangle of the given Mesh is multiplied by the composite matrix M to be put into their world coordinates (actually, this is not a good idea from the point of view of instancing, we will see why at the end of this post).<\/p>\n<p>Many of the scenes provided for this assignment includes Transformations; so, without implementing this capability, meshes would not get placed in front of the camera and no rendering would be done.<\/p>\n<p><strong>Note:<\/strong> One must not forget to convert the provided <strong>Rotation angle <\/strong>from degrees to radians, to be able to correctly rotate the shape.<\/p>\n<h4>Depth of Field<\/h4>\n<p>A nice capability that can easily be implemented is Depth of Field (DoF),<strong>\u00a0<\/strong>which can be used to focus the camera on the object of interest, and blur the rest of the scene according to the distance to the focus point.<\/p>\n<p>By reading the\u00a0<strong>ApertureSize\u00a0<\/strong>and the\u00a0<strong>FocusDistance<\/strong> from the input file, I have put the image plane\u00a0FocusDistance far away from the camera, and scaled it by\u00a0<strong>(FocusDistance \/ NearDistance)<\/strong>\u00a0times to be able to protect the field of view of the original camera.<\/p>\n<p>Next, I have created a squre aperture, where each edge is in size of\u00a0ApertureSize, and used the same approach I have used to implement MSAA (Multisample Anti-Aliasing) capability, where\u00a0<strong>NumSamples<\/strong> many ray are send from the camera into random locations of the same pixel on the image plane, but this time sending the rays from random locations of\u00a0<strong>sqrt(NumSamples) x sqrt(NumSamples)\u00a0<\/strong><strong>Aperture Grid<\/strong>, into the center of the same pixel on the image plane.<\/p>\n<p>By doing so, shapes that are very close to the image plane are put into focus successfully. Below is a GIF file that demonstrates DoF<strong>\u00a0<\/strong>capability by putting each of 4 spheres into focus at different renderings (little black line scatterings are caused by Giphy GIF Maker. They are not included in the real rendered images):<\/p>\n<h4><iframe loading=\"lazy\" class=\"giphy-embed\" src=\"https:\/\/giphy.com\/embed\/3XsnarFkLd46pJwQMh\" width=\"480\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/h4>\n<pre>spheres_dof.xml\n(800x800) - 4 images\nEach ~31 secs (\/w 8 thrd, 100 MSAA, DoF)<\/pre>\n<h4>Motion Blur<\/h4>\n<p>Motion blur (MB) is used to give the effect of movement to the shapes. As the aperture is open for some time interval in a real camera, a moving object gets rendered in blur towards the moving direction.<\/p>\n<p>To simulate this in my ray tracer, I have given each MSAA sample ray of one pixel a random\u00a0<strong>Time<\/strong> variable ranging from [0, 1], and used that time variable to move the ray hit position towards the direction of velocity by multiplying\u00a0<strong>ray.time * hitInfo.material.motionBlurXYZVec<\/strong> if the material hit has motion blur effect.<\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"139\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\" data-orig-size=\"750,600\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\" class=\"aligncenter wp-image-139 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\" alt=\"\" width=\"750\" height=\"600\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png 750w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs-300x240.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<pre>cornellbox_boxes_dynamic.xml\n(800x800)\n5 mins 25 secs (\/w 16 thrd, 900MSAA, MB)<\/pre>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"140\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs.png\" data-orig-size=\"750,600\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs.png\" class=\"aligncenter wp-image-140 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs.png\" alt=\"\" width=\"750\" height=\"600\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs.png 750w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_040motionblur5dk22secs-300x240.png 300w\" sizes=\"auto, (max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px\" \/><\/a><\/p>\n<pre>cornellbox_boxes_dynamic.xml\n(800x800)\n5 mins 22 secs (\/w 16 thrd, 900MSAA, MB)<\/pre>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"141\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/cornellbox_dynamic_16thr_900sample0-1araliklimotionblur_6dk46secs191milisecs\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs.png\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs.png\" class=\"aligncenter wp-image-141 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs.png\" alt=\"\" width=\"800\" height=\"800\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs-150x150.png 150w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs-300x300.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs-768x768.png 768w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_dynamic_16thr_900sample0-1aralikliMotionBlur_6dk46secs191milisecs-100x100.png 100w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>cornellbox_dynamic.xml\n(800x800)\n6 mins 46 secs (\/w 16 thrd, 900MSAA, MB)<\/pre>\n<p>Bounding boxes of the shapes need to be extended to cover all the motion blur distance from time 0 to time 1. In my implementation, as I only have the scene BVH itself -which has Triangles and Spheres in the leaf nodes- and no mesh BVHs, what I did was to extend each leaf node&#8217;s bounding box by motionBlur amount. However, this approach put my head in trouble, as for larger meshes that contain millions of triangles (e.g. dragon_dynamic.xml scene), increasing the BBox extents of those tiny triangles dramatically decreased the performance of my BVH searches.<\/p>\n<p><strong>Edit:\u00a0<\/strong>The original scene with 100 MSAA samples is rendered in 4 hours, 8 minutes, and 37 seconds:<\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"159\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/dragon_dynamic\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic.png\" data-orig-size=\"800,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"dragon_dynamic\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic.png\" class=\"aligncenter wp-image-159 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic.png\" alt=\"\" width=\"800\" height=\"480\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic-300x180.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic-768x461.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>dragon_dynamic.xml\n(800x480)\n4h 8m 37s (\/w 8 thrd, 100 MSAA, MB)<\/pre>\n<p>To prevent this problem, each mesh must contain its own BVH in it, and only the most outside BBox of the mesh must be extended to catch the rays in motionBlur distance and test them with the nodes and the leaf triangles of the mesh. If hit is found, then the triangle&#8217;s hitInfo.pos must be extended to hitInfo.pos + motionBlurVec. By doing so, not the BBoxes of those millions of triangles are extended, but only the most outside BBox of the mesh is extended. Using this idea would not cause any harm to the BVH search performance.<\/p>\n<p>I decreased the NumSamples to 4 for the dragon_dynamic.xml scene to be able to get fast renders. Below is the screenshots without \/ with motion blur effect, respectively:<\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"144\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/dragon_dynamic_8thr_100msaa_motionless18dk5secs\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs.png\" data-orig-size=\"800,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"dragon_dynamic_8thr_100MSAA_motionless18dk5secs\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs.png\" class=\"aligncenter wp-image-144 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs.png\" alt=\"\" width=\"800\" height=\"480\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs-300x180.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_100MSAA_motionless18dk5secs-768x461.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>dragon_dynamic.xml\n(800x480)\n18 mins 5 secs (\/w 8 thrd, 100 MSAA, no MB)<\/pre>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"143\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/dragon_dynamic_8thr_4msaa_full_11mins\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins.png\" data-orig-size=\"800,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"dragon_dynamic_8thr_4MSAA_full_11mins\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins.png\" class=\"aligncenter wp-image-143 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins.png\" alt=\"\" width=\"800\" height=\"480\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins-300x180.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/dragon_dynamic_8thr_4MSAA_full_11mins-768x461.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>dragon_dynamic.xml\n(800x480)\n~11 minutes (\/w 8 thrd, 4 MSAA, MB)<\/pre>\n<h4>Soft Shadows<\/h4>\n<p>To implement soft shadows (SS), I needed to parse the light type of <strong>AreaLight<\/strong> from the input file. Until that point, my ray tracer have only had\u00a0<strong>PointLight<\/strong> class.<\/p>\n<p>So, I have converted my\u00a0<strong>PointLight<\/strong> class into\u00a0<strong>Light<\/strong> class, and put all light attributes in it, so that I could keep each\u00a0<strong>PointLight\u00a0<\/strong>and\u00a0<strong>AreaLight\u00a0<\/strong>input in a\u00a0<strong>Light<\/strong> instance. I check\u00a0<strong>EdgeVector1\u00a0<\/strong>and\u00a0<strong>EdgeVector2<\/strong> to figure out if the current light is an area light or a point light during the ray tracing process.<\/p>\n<p>When checking whether the point is in shadow or not, I sent the shadow ray from the point to a random location in the area of the area light, and multiplied the light intensity with the <strong>dot(-shadowRayDir, areaLightNormal)<\/strong> (i.e. cos of the angle between the shadow ray and the area light normal) to arrange that light&#8217;s intensity on the hit point.<\/p>\n<p>Below is a GIF file that shows the difference between<strong> hard shadows and soft shadows<\/strong> by using point lights and area lights, respectively. The brightness difference is caused by the\u00a0<strong>cos(angle)<\/strong> calculation discussed above; point light scene is more bright:<\/p>\n<p><iframe loading=\"lazy\" class=\"giphy-embed\" src=\"https:\/\/giphy.com\/embed\/1yjqZ9OoOj6tFUSdvy\" width=\"480\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"145\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/metal_plates_area_36msaa_arealight\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight.png\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"metal_plates_area_36msaa_arealight\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight.png\" class=\"aligncenter wp-image-145 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight.png\" alt=\"\" width=\"800\" height=\"800\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight-150x150.png 150w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight-300x300.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight-768x768.png 768w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_arealight-100x100.png 100w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>metal_plates_area.xml\n(800x800)\n36 secs (\/w 8 thrd, 36 MSAA, SS, GR)<\/pre>\n<h4>Glossy Reflections<\/h4>\n<p>GR is used to simulate non-perfect,\u00a0 glossy brushed metal surface reflections. It is implemented by perturbing the direction of the reflected ray by a small amount.<\/p>\n<p>First, an orthonormal base is created for the original reflection ray by making its smaller coordinate 1, and using cross products to find the ONB axes. Then, a square area is created by using the\u00a0<strong>Roughness<\/strong> parameter in the input file as the edge length of that square. The reflection ray is then perturbed by\u00a0<strong>-(roughness \/ 2) + rand(0..1)*roughness\u00a0<\/strong>amount at each axis. The former term is used to make the original reflection ray pass through the center of that created square for a good perturbation. The perturbed ray is then used as the reflection ray and sent into the scene.<\/p>\n<p>The image provided at the end of the <strong>Soft Shadows <\/strong>chapter shows an example of glossy reflections. Below is another image which uses PointLight for the same scene (this is also the second image of the GIF file above):<\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"146\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/metal_plates_area_36msaa_pointlight\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight.png\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"metal_plates_area_36msaa_pointlight\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight.png\" class=\"aligncenter wp-image-146 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight.png\" alt=\"\" width=\"800\" height=\"800\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight-150x150.png 150w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight-300x300.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight-768x768.png 768w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/metal_plates_area_36msaa_pointlight-100x100.png 100w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>metal_plates_area.xml\n(800x800)\n28 secs (\/w 8 thrd, 36 MSAA, no SS, GR)<\/pre>\n<h4>Smoothing<\/h4>\n<p>Instead of using the same normal vector for any hit point on a triangle, one can calculate the normal vector of each\u00a0<strong>Vertex<\/strong> of a triangle -by summing up all the normal vectors of the neighbour triangles of that vertex and normalizing the resulting vector-, and use an interpolated version of those 3 vertex normals as the normal vector of the hit point during the Triangle::Intersection routine by using the\u00a0barycentric coordinates of that hit point.<\/p>\n<p>My current implementation of smoothing calculates the vertex normals in a brute force manner by searching the current vertex among all triangles, for all vertices of all triangles. This causes the initial scene parsing procedure to last <strong>~4 minutes\u00a0<\/strong>to be able to correctly compute the vertex normals, but the time complexity of the ray tracing part does not get affected when vertex normals are used instead of triangle normals.<\/p>\n<p>Below is a GIF file that shows of how that small change can produce beautiful images from the same input triangle set (flat and smooth shading):<\/p>\n<p><iframe loading=\"lazy\" class=\"giphy-embed\" src=\"https:\/\/giphy.com\/embed\/2YqVA5DH8lVtNSn4la\" width=\"480\" height=\"480\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"147\" data-permalink=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/killeroo_glass_8thrd\/\" data-orig-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd.png\" data-orig-size=\"800,800\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"killeroo_glass_8thrd\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd.png\" class=\"aligncenter wp-image-147 size-full\" src=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd.png\" alt=\"\" width=\"800\" height=\"800\" srcset=\"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd.png 800w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd-150x150.png 150w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd-300x300.png 300w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd-768x768.png 768w, https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/killeroo_glass_8thrd-100x100.png 100w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><\/p>\n<pre>killeroo_glass.xml\n(800x800)\nTotal render time: 5 mins 8 secs\n~4 minutes of it to calculate vertex normals\n(\/w 8 thrd, 16 MSAA, Smooth)<\/pre>\n<h4>Instancing<\/h4>\n<p>Instancing is used to have meshes that use the same base mesh, but have additional transformations, properties, etc.<\/p>\n<p>During the assignment period, I have parsed\u00a0<strong>MeshInstance<\/strong> meshes as if they themselves are\u00a0<strong>Mesh<\/strong> meshes, by duplicating the triangles of the base mesh for the new mesh instance, and got all output renders provided in this post by using this procedure.<\/p>\n<p>When I started the implementation of instancing capability, I figured out that my BVH implementation idea of &#8220;1 BVH for only the scene itself, consisting of just triangles and spheres, but not differentiating the meshes.&#8221; is a VERY bad idea.<\/p>\n<p>Instancing requires each mesh, mesh instance and sphere to have its own BVH tree, and the scene BVH to point to those inner BVHs, so that when a ray is sent, it could be converted into the local coordinates of each mesh and mesh instance by just multipyling the inverse of the composite transformation matrix of that mesh. When a hitpoint is found, the hitNormal is then multiplied by the inverse transpose of the composite transformation matrix of the mesh to convert it into world coordinates. Hitpoint parameter\u00a0<strong>t<\/strong> stays the same in both coordinate systems; and the direction vector of the main ray should not be normalized for this coordinate space conversion to work.<\/p>\n<p>I have used late days for my assignment to be able to successfully implement instancing capability. I have implemented the ray conversion system from world coordinates to local coordinates for Intersection routines, and built BVH for each mesh, mesh instance (points to the BVH of the base mesh, but it has its own composite transformation matrix), and sphere. The rays are sent to the BVH of each mesh, mesh instance and sphere in a loop; so, the scene itself do not contain a BVH.<\/p>\n<p>However, when the ray tracing process that use instancing begins, I get segmentation fault error when the leaf nodes&#8217; Intersection routines are launched during a Ray &amp; MeshBVH intersection traversal. I am currently working on this bug, when I solve it, I would be able to use instancing correctly in my next assignments.<\/p>\n<h4>What&#8217;s next?<\/h4>\n<p>Along with my next homework tasks, I will also:<\/p>\n<ul>\n<li>Debug and correct my instancing code, so that I could use instancing in a memory-friendly manner.<\/li>\n<li>Improve the performance of Motion Blur BBox calculations by using instancing.<\/li>\n<li>Shorten the time complexity of the smoothing process by implementing a different method which does not require traversing the vertices again and again.<\/li>\n<li>Extend .PLY parser to parse x, y, z vertex coordinates given without nx, ny, nz coordinates (buddha.ply). Currently supporting x, y, z, w quadliterals and x, y, z, nx, ny, nz six-tuple triangle representations.<\/li>\n<\/ul>\n<p>Hope to see you in the next part!<\/p>\n<p>Happy tracing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello trace-masters! In my third assignment, my task was to implement those capabilities to my raytracer: Transformations (Scaling, Rotation, Translation) Instancing Distribution Ray Tracing Depth of Field Motion Blur Soft Shadows Glossy Reflections Let&#8217;s examine them together!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-ray-tracing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk\" \/>\n<meta property=\"og:description\" content=\"Hello trace-masters! In my third assignment, my task was to implement those capabilities to my raytracer: Transformations (Scaling, Rotation, Translation) Instancing Distribution Ray Tracing Depth of Field Motion Blur Soft Shadows Glossy Reflections Let&#8217;s examine them together!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/\" \/>\n<meta property=\"og:site_name\" content=\"kadircenk\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/kadircenk3\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/kadircenk3\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-14T14:17:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-07T16:39:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\" \/>\n<meta name=\"author\" content=\"kadircenk\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/kadircenkalpay\" \/>\n<meta name=\"twitter:site\" content=\"@kadircenkalpay\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kadircenk\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/\"},\"author\":{\"name\":\"kadircenk\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d9546d987c40be9d6ff61c6512b3a25\"},\"headline\":\"Trace the Ray &#8211; Part 3 (Transformations, Instancing, Distribution Ray Tracing)\",\"datePublished\":\"2018-04-14T14:17:03+00:00\",\"dateModified\":\"2019-02-07T16:39:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/\"},\"wordCount\":1849,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d9546d987c40be9d6ff61c6512b3a25\"},\"image\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\",\"articleSection\":[\"Ray Tracing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/\",\"url\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/\",\"name\":\"Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\",\"datePublished\":\"2018-04-14T14:17:03+00:00\",\"dateModified\":\"2019-02-07T16:39:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#primaryimage\",\"url\":\"http:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\",\"contentUrl\":\"http:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/04\\\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Trace the Ray &#8211; Part 3 (Transformations, Instancing, Distribution Ray Tracing)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/\",\"name\":\"kadircenk.com\",\"description\":\"Blog\",\"publisher\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d9546d987c40be9d6ff61c6512b3a25\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/#\\\/schema\\\/person\\\/8d9546d987c40be9d6ff61c6512b3a25\",\"name\":\"kadircenk\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/ss.png\",\"url\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/ss.png\",\"contentUrl\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/ss.png\",\"width\":696,\"height\":696,\"caption\":\"kadircenk\"},\"logo\":{\"@id\":\"https:\\\/\\\/kadircenk.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/ss.png\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/kadircenk3\",\"https:\\\/\\\/www.instagram.com\\\/kadircenkalpay\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/kadir-cenk-alpay\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/kadircenkalpay\",\"https:\\\/\\\/www.youtube.com\\\/kadircenkalpay\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/","og_locale":"en_US","og_type":"article","og_title":"Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk","og_description":"Hello trace-masters! In my third assignment, my task was to implement those capabilities to my raytracer: Transformations (Scaling, Rotation, Translation) Instancing Distribution Ray Tracing Depth of Field Motion Blur Soft Shadows Glossy Reflections Let&#8217;s examine them together!","og_url":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/","og_site_name":"kadircenk","article_publisher":"https:\/\/www.facebook.com\/kadircenk3","article_author":"https:\/\/www.facebook.com\/kadircenk3","article_published_time":"2018-04-14T14:17:03+00:00","article_modified_time":"2019-02-07T16:39:44+00:00","og_image":[{"url":"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png","type":"","width":"","height":""}],"author":"kadircenk","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/kadircenkalpay","twitter_site":"@kadircenkalpay","twitter_misc":{"Written by":"kadircenk","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#article","isPartOf":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/"},"author":{"name":"kadircenk","@id":"https:\/\/kadircenk.com\/blog\/#\/schema\/person\/8d9546d987c40be9d6ff61c6512b3a25"},"headline":"Trace the Ray &#8211; Part 3 (Transformations, Instancing, Distribution Ray Tracing)","datePublished":"2018-04-14T14:17:03+00:00","dateModified":"2019-02-07T16:39:44+00:00","mainEntityOfPage":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/"},"wordCount":1849,"commentCount":0,"publisher":{"@id":"https:\/\/kadircenk.com\/blog\/#\/schema\/person\/8d9546d987c40be9d6ff61c6512b3a25"},"image":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#primaryimage"},"thumbnailUrl":"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png","articleSection":["Ray Tracing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/","url":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/","name":"Trace the Ray - Part 3 (Transformations, Instancing, Distribution Ray Tracing) - kadircenk","isPartOf":{"@id":"https:\/\/kadircenk.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#primaryimage"},"image":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#primaryimage"},"thumbnailUrl":"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png","datePublished":"2018-04-14T14:17:03+00:00","dateModified":"2019-02-07T16:39:44+00:00","breadcrumb":{"@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#primaryimage","url":"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png","contentUrl":"http:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2018\/04\/cornellbox_boxes_dynamic_16thr_900msaa_004motionblur5dk25secs.png"},{"@type":"BreadcrumbList","@id":"https:\/\/kadircenk.com\/blog\/trace-the-ray-part-3-transformations-instancing-distribution-ray-tracing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kadircenk.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Trace the Ray &#8211; Part 3 (Transformations, Instancing, Distribution Ray Tracing)"}]},{"@type":"WebSite","@id":"https:\/\/kadircenk.com\/blog\/#website","url":"https:\/\/kadircenk.com\/blog\/","name":"kadircenk.com","description":"Blog","publisher":{"@id":"https:\/\/kadircenk.com\/blog\/#\/schema\/person\/8d9546d987c40be9d6ff61c6512b3a25"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kadircenk.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/kadircenk.com\/blog\/#\/schema\/person\/8d9546d987c40be9d6ff61c6512b3a25","name":"kadircenk","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2023\/02\/ss.png","url":"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2023\/02\/ss.png","contentUrl":"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2023\/02\/ss.png","width":696,"height":696,"caption":"kadircenk"},"logo":{"@id":"https:\/\/kadircenk.com\/blog\/wp-content\/uploads\/2023\/02\/ss.png"},"sameAs":["https:\/\/www.facebook.com\/kadircenk3","https:\/\/www.instagram.com\/kadircenkalpay","https:\/\/www.linkedin.com\/in\/kadir-cenk-alpay","https:\/\/x.com\/https:\/\/twitter.com\/kadircenkalpay","https:\/\/www.youtube.com\/kadircenkalpay"]}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9NbhO-2c","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":14,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kadircenk.com\/blog\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}