{"id":493,"date":"2024-05-27T15:31:30","date_gmt":"2024-05-27T15:31:30","guid":{"rendered":"https:\/\/vishnusrinivas.com\/?page_id=493"},"modified":"2024-05-28T16:16:21","modified_gmt":"2024-05-28T16:16:21","slug":"raytracer","status":"publish","type":"page","link":"https:\/\/vishnusrinivas.com\/?page_id=493","title":{"rendered":"Raytracer"},"content":{"rendered":"\n<p>In Spring 2024, as part of CS 434: Advanced Graphics, I built a raytracer from scratch in C. I started by implementing a basic ray-casting system, where rays are shot out from the camera and check objects for intersection<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"556\" height=\"570\" src=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.52.33-PM.png\" alt=\"\" class=\"wp-image-494 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.52.33-PM.png 556w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.52.33-PM-293x300.png 293w\" sizes=\"(max-width: 556px) 100vw, 556px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>One sphere is in the scene, rays that exit the camera and hit the sphere are colored white, others are gray.<\/p>\n<\/div><\/div>\n\n\n\n<p>Then, I calculated the normals of the shape where it was hit<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"574\" height=\"486\" src=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.51.54-PM.png\" alt=\"\" class=\"wp-image-495 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.51.54-PM.png 574w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.51.54-PM-300x254.png 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>Here, the sphere is colored according to the normal vectors present at each point of intersection<\/p>\n<\/div><\/div>\n\n\n\n<p>With normals included, I was able to implement basic Phong shading by adding a point light source and calculating the lighting contributions to the color of each pixel<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"806\" height=\"812\" src=\"http:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.50.29-PM.png\" alt=\"\" class=\"wp-image-497 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.50.29-PM.png 806w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.50.29-PM-298x300.png 298w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.50.29-PM-150x150.png 150w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-12.50.29-PM-768x774.png 768w\" sizes=\"(max-width: 806px) 100vw, 806px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>With just Phong shading diffuse effects implemented, the shape of the sphere becomes clear<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"1024\" height=\"813\" src=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-2.00.23-PM-1024x813.png\" alt=\"\" class=\"wp-image-496 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-2.00.23-PM-1024x813.png 1024w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-2.00.23-PM-300x238.png 300w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-2.00.23-PM-768x610.png 768w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-18-at-2.00.23-PM.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>With colored specularity added, local occlusion, diffusion, and specular effects are visible<\/p>\n<\/div><\/div>\n\n\n\n<p>I continued by adding shadow rays for global shadow effects, reflection rays to allow for reflections, and implemented support for multiple objects and light sources<\/p>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"1024\" height=\"1024\" src=\"http:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-1024x1024.png\" alt=\"\" class=\"wp-image-492 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-1024x1024.png 1024w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-300x300.png 300w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-150x150.png 150w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-768x767.png 768w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM-1536x1534.png 1536w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-02-21-at-10.52.16-PM.png 1894w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>In this screenshot, multiple lights can be seen, as well as nested reflections between multiple glossy objects<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-media-text alignwide is-stacked-on-mobile\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" width=\"1024\" height=\"1024\" src=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-1024x1024.png\" alt=\"\" class=\"wp-image-498 size-full\" srcset=\"https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-1024x1024.png 1024w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-300x300.png 300w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-150x150.png 150w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-768x767.png 768w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM-1536x1534.png 1536w, https:\/\/vishnusrinivas.com\/wp-content\/uploads\/2024\/05\/Screenshot-2024-05-27-at-11.29.17-AM.png 1890w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p>In this reflective cornell box, full shadows, reflections, specular and diffuse effects are clearly visible for both sphere objects as well as flat (triangle) objects<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"wp-container-1 wp-block-buttons\">\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link\" href=\"https:\/\/github.com\/vishsrin\/VS-raytracer\">See on Github<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Spring 2024, as part of CS 434: Advanced Graphics, I built a raytracer from scratch in C. I started by implementing a basic ray-casting system, where rays are shot out from the camera and check objects for intersection One sphere is in the scene, rays that exit the camera and hit the sphere are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"ub_ctt_via":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"featured_image_src":null,"_links":{"self":[{"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/pages\/493"}],"collection":[{"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=493"}],"version-history":[{"count":2,"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/pages\/493\/revisions"}],"predecessor-version":[{"id":514,"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=\/wp\/v2\/pages\/493\/revisions\/514"}],"wp:attachment":[{"href":"https:\/\/vishnusrinivas.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}