{"id":234,"date":"2020-01-05T14:31:15","date_gmt":"2020-01-05T06:31:15","guid":{"rendered":"https:\/\/zhangjiajian.com\/?p=234"},"modified":"2020-01-14T05:00:39","modified_gmt":"2020-01-13T21:00:39","slug":"rendering-translucent-object-using-optix","status":"publish","type":"post","link":"https:\/\/zhangjiajian.com\/?p=234","title":{"rendered":"Rendering Translucent Object using OptiX"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>This project is finished as the final project of the Computer Graphics course in 2018 Spring. At that time the latest  NVIDIA<sup>\u00ae<\/sup>&nbsp;GeForce RTX<sup>\u2122<\/sup>  GPU hasn&#8217;t been published yet. I then chose the OptiX framework to apply the Ray Tracing functions of GPU.<\/p>\n\n\n\n<p>Translucent object can be hard to render. However, with the full use of GPU\u2019s computing power, this task can be achieved in a simple and quick way. OptiX is a framework designed by NVIDIA used to easily get parallel calculation in ray tracing process. In our project, the render can even be done in real-time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Theory<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote\"><p> The light distribution in highly scattering media tends to become isotropic. This is true even if the initial light source distribution and the phase function are highly anisotropic. <\/p><cite>  A Practical Model for Subsurface Light Transport&nbsp;&nbsp; Henrik Wann Jensen &nbsp;&nbsp;Stephen R. Marschner <\/cite><\/blockquote>\n\n\n\n<p>We can assume that after a light shooting into the surface, it will\nrandomly go to all the direction. This is the same for the ray we tracing from\nthe camera. Translucent objects have such kind of nature. We can simulate this\nprocess and as far as possible to reach the real effect.<\/p>\n\n\n\n<p> The algorithm is simple. When a ray hit the surface of a translucent object, we first calculate the direct light emission of the hit point.  Then from the hit point, shoot rays  into the object in different direction.   We call the new rays as a scatter ray.  The rays are sampled uniformly in a hemisphere space. Find the insect point of the scatter ray,  calculate the direct light emission of the insect point, add it to the result of the hit point multiplied by a decrease function.  In the function there is a parameter set for different sizes and materials of the object.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"180\" src=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-1024x180.png\" alt=\"\" class=\"wp-image-260\" srcset=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-1024x180.png 1024w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-300x53.png 300w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-768x135.png 768w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-830x146.png 830w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-230x40.png 230w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-350x62.png 350w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas-480x84.png 480w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixformulas.png 1417w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Result<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"919\" height=\"833\" src=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult.png\" alt=\"\" class=\"wp-image-261\" srcset=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult.png 919w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-300x272.png 300w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-768x696.png 768w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-830x752.png 830w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-230x208.png 230w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-350x317.png 350w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixresult-480x435.png 480w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><\/figure><\/div>\n\n\n\n<p>For the two blocks, we set\nthe transparency of the them as a low value, so it looks like marble. For the\ndragon and bunny model, we set a higher transparency so the look like jade. For\nthe princess model, we can see even under the cover of the skirt, the\nperformance of legs is still acceptable. The performance of the skirt is also\nproved that the algorithm is robust for narrow, thin and detailed object.<\/p>\n\n\n\n<p>The time used for rendering is also short. Under GTX960M 4G, Intel Core i5 2.3GHz, the dragon and princess used about 30 seconds and the bunny uses only less than 20s. All the images shoot 256 rays per pixel and 15 scatter rays per hit point. If we shoot about 4 rays per pixel we can get a real-time rendering result with a DPS around 10.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code &amp; Project Accessment<\/h2>\n\n\n\n<p>The whole project can be found in my <a href=\"https:\/\/github.com\/handsomeJian\/Rendering-Translucent-Object-Using-OptiX\">github repo<\/a>.<\/p>\n\n\n\n<p>The core code for the scattering process is shown below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"391\" src=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-1024x391.png\" alt=\"\" class=\"wp-image-262\" srcset=\"https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-1024x391.png 1024w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-300x115.png 300w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-768x294.png 768w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-830x317.png 830w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-230x88.png 230w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-350x134.png 350w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode-480x183.png 480w, https:\/\/zhangjiajian.com\/wp-content\/uploads\/2020\/01\/optixcode.png 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This project is finished as the final project of the Computer Graphics course in 2018 Spring. At that time the latest NVIDIA\u00ae&nbsp;GeForce RTX\u2122 GPU hasn&#8217;t been published yet. I then chose the OptiX framework to apply the Ray Tracing functions of GPU. Translucent object can be hard to render. However, with the full use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":263,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[6],"_links":{"self":[{"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/posts\/234"}],"collection":[{"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=234"}],"version-history":[{"count":8,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":390,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/posts\/234\/revisions\/390"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=\/wp\/v2\/media\/263"}],"wp:attachment":[{"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhangjiajian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}