{"id":753,"date":"2013-09-04T04:45:58","date_gmt":"2013-09-04T04:45:58","guid":{"rendered":"http:\/\/lousodrome.net\/blog\/light\/?p=753"},"modified":"2013-09-06T19:24:29","modified_gmt":"2013-09-06T19:24:29","slug":"a-glsl-version-of-smallpt","status":"publish","type":"post","link":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/","title":{"rendered":"A GLSL version of smallpt"},"content":{"rendered":"<p><a href=\"http:\/\/www.kevinbeason.com\/smallpt\/\">smallpt <\/a>is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the <a href=\"https:\/\/docs.google.com\/open?id=0B8g97JkuSSBwUENiWTJXeGtTOHFmSm51UC01YWtCZw\">detailed explanation slides<\/a> by David Cline, I experimented porting it to GLSL on <a href=\"https:\/\/www.shadertoy.com\/\">Shadertoy<\/a>.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.shadertoy.com\/embed\/4sfGDB\" height=\"375\" width=\"500\" allowfullscreen=\"\" frameborder=\"0\"><\/iframe><\/p>\n<p>This proved to be an interesting experiment that brought a few lessons.<\/p>\n<ul>\n<li>Path tracing is fun, easy to implement, and good looking.<\/li>\n<li>It is also slow to converge, so trying to <a href=\"https:\/\/twitter.com\/Zavie\/status\/375104065111212033\">get your rays toward the light source is a big win<\/a>.<\/li>\n<li>GLSL support in WebGL is still nowhere near robust: valid code will or will not work depending on the platform, the browser, and <a href=\"http:\/\/www.geeks3d.com\/20130611\/webgl-how-to-enable-native-opengl-in-your-browser-windows\/\">whether the OpenGL layer is native or not<\/a>. The statements &#8220;break&#8221; and &#8220;continue&#8221; in particular seem often to break everything.<\/li>\n<\/ul>\n<p>You can <a href=\"https:\/\/www.shadertoy.com\/view\/4sfGDB\">see the shader and tweak it here<\/a>. By default it uses 6 samples per pixel, and 3 bounces, which allows it to run smoothly on average hardware. I found 40 samples per pixel and 5 bounces to give nice results while maintaining interactive framerate.<\/p>\n<div id=\"attachment_760\" style=\"width: 545px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.shadertoy.com\/view\/4sfGDB\"><img aria-describedby=\"caption-attachment-760\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-760   \" title=\"Path tracing, 40 samples per pixel, 5 bounces\" alt=\"Path tracing, 40 samples per pixel, 5 bounces\" src=\"\/blog\/wp-content\/images\/path-tracing-refraction-40-6.png\" width=\"535\" height=\"390\" \/><\/a><p id=\"caption-attachment-760\" class=\"wp-caption-text\">Path tracing, 40 samples per pixel, 5 bounces<\/p><\/div>\n<p><strong>Update<\/strong>: since <a href=\"http:\/\/glsl.heroku.com\/\">GLSL Sandbox<\/a> has a feature, reading from the previous frame buffer, that Shadertoy is missing at the moment, I thought it&#8217;d be interesting try it to have the image converging over time. <a href=\"http:\/\/glsl.heroku.com\/e#10908.0\">A little hacking later,<\/a> a minute or so worth of rendering got me this kind of result: Given the effort, I am really pleased by the result.<\/p>\n<div id=\"attachment_760\" style=\"width: 510px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.shadertoy.com\/view\/4sfGDB\"><img aria-describedby=\"caption-attachment-760\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-760   \" title=\"Path tracing, 40 samples per pixel, 5 bounces\" alt=\"Path tracing, 40 samples per pixel, 5 bounces\" src=\"\/blog\/wp-content\/images\/path-tracing-glsl-sandbox.png\" width=\"500\" height=\"375\" \/><\/a><p id=\"caption-attachment-760\" class=\"wp-caption-text\">Path tracing, unknown number of samples per pixel, 7 bounces<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>smallpt is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the detailed explanation slides by David Cline, I experimented porting it to GLSL on Shadertoy. This proved to be &hellip; <a href=\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[214,224,58,112,125,52,443,399,184,185,126,75,76,398,442,57,225],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>A GLSL version of smallpt &ndash; Light is beautiful<\/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:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A GLSL version of smallpt &ndash; Light is beautiful\" \/>\n<meta property=\"og:description\" content=\"smallpt is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the detailed explanation slides by David Cline, I experimented porting it to GLSL on Shadertoy. This proved to be &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\" \/>\n<meta property=\"og:site_name\" content=\"Light is beautiful\" \/>\n<meta property=\"article:published_time\" content=\"2013-09-04T04:45:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-09-06T19:24:29+00:00\" \/>\n<meta name=\"author\" content=\"Julien Guertault\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Zavie\" \/>\n<meta name=\"twitter:site\" content=\"@Zavie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Julien Guertault\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\"},\"author\":{\"name\":\"Julien Guertault\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"headline\":\"A GLSL version of smallpt\",\"datePublished\":\"2013-09-04T04:45:58+00:00\",\"dateModified\":\"2013-09-06T19:24:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\"},\"wordCount\":257,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"keywords\":[\"BeautyPi\",\"Cornell box\",\"diffuse\",\"Fresnel\",\"global illumination\",\"GLSL\",\"GLSL Sandbox\",\"live demo\",\"Monte Carlo\",\"path tracing\",\"ray tracing\",\"reflection\",\"refraction\",\"shader\",\"Shadertoy\",\"specular\",\"sphere\"],\"articleSection\":[\"Rendering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\",\"url\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\",\"name\":\"A GLSL version of smallpt &ndash; Light is beautiful\",\"isPartOf\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#website\"},\"datePublished\":\"2013-09-04T04:45:58+00:00\",\"dateModified\":\"2013-09-06T19:24:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/lousodrome.net\/blog\/light\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A GLSL version of smallpt\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#website\",\"url\":\"http:\/\/lousodrome.net\/blog\/light\/\",\"name\":\"Light is beautiful\",\"description\":\"Thoughts of a graphics programmer, demoscener and spare time photographer\",\"publisher\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/lousodrome.net\/blog\/light\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\",\"name\":\"Julien Guertault\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g\",\"caption\":\"Julien Guertault\"},\"logo\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/lousodrome.net\/blog\/light\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A GLSL version of smallpt &ndash; Light is beautiful","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:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/","og_locale":"en_US","og_type":"article","og_title":"A GLSL version of smallpt &ndash; Light is beautiful","og_description":"smallpt is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the detailed explanation slides by David Cline, I experimented porting it to GLSL on Shadertoy. This proved to be &hellip; Continue reading &rarr;","og_url":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/","og_site_name":"Light is beautiful","article_published_time":"2013-09-04T04:45:58+00:00","article_modified_time":"2013-09-06T19:24:29+00:00","author":"Julien Guertault","twitter_card":"summary_large_image","twitter_creator":"@Zavie","twitter_site":"@Zavie","twitter_misc":{"Written by":"Julien Guertault","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#article","isPartOf":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/"},"author":{"name":"Julien Guertault","@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"headline":"A GLSL version of smallpt","datePublished":"2013-09-04T04:45:58+00:00","dateModified":"2013-09-06T19:24:29+00:00","mainEntityOfPage":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/"},"wordCount":257,"commentCount":0,"publisher":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"keywords":["BeautyPi","Cornell box","diffuse","Fresnel","global illumination","GLSL","GLSL Sandbox","live demo","Monte Carlo","path tracing","ray tracing","reflection","refraction","shader","Shadertoy","specular","sphere"],"articleSection":["Rendering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/","url":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/","name":"A GLSL version of smallpt &ndash; Light is beautiful","isPartOf":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#website"},"datePublished":"2013-09-04T04:45:58+00:00","dateModified":"2013-09-06T19:24:29+00:00","breadcrumb":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/lousodrome.net\/blog\/light\/2013\/09\/04\/a-glsl-version-of-smallpt\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/lousodrome.net\/blog\/light\/"},{"@type":"ListItem","position":2,"name":"A GLSL version of smallpt"}]},{"@type":"WebSite","@id":"http:\/\/lousodrome.net\/blog\/light\/#website","url":"http:\/\/lousodrome.net\/blog\/light\/","name":"Light is beautiful","description":"Thoughts of a graphics programmer, demoscener and spare time photographer","publisher":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/lousodrome.net\/blog\/light\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f","name":"Julien Guertault","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g","caption":"Julien Guertault"},"logo":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/"},"url":"https:\/\/lousodrome.net\/blog\/light\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts\/753"}],"collection":[{"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/comments?post=753"}],"version-history":[{"count":0,"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts\/753\/revisions"}],"wp:attachment":[{"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/media?parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/categories?post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/tags?post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}