{"id":664,"date":"2005-07-12T00:04:09","date_gmt":"2005-07-12T00:04:09","guid":{"rendered":"https:\/\/astrofra.com\/wordpress\/?p=3"},"modified":"2005-07-12T00:04:09","modified_gmt":"2005-07-12T00:04:09","slug":"poor-man-s-dispersion-shader-rman-version","status":"publish","type":"post","link":"https:\/\/astrofra.com\/wordpress\/index.php\/2005\/07\/12\/poor-man-s-dispersion-shader-rman-version\/","title":{"rendered":"RenderMan | Poor Man&#8217;s Dispersion Shader"},"content":{"rendered":"<table>\n<tbody>\n<tr>\n<td valign=\"top\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"240\" height=\"240\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"name\" value=\"FlashTut\" \/><param name=\"bgcolor\" value=\"#888888\" \/><param name=\"align\" value=\"middle\" \/><param name=\"src\" value=\".\/swf\/dispersion.swf\" \/><param name=\"quality\" value=\"high\" \/><embed type=\"application\/x-shockwave-flash\" width=\"240\" height=\"240\" src=\"https:\/\/www.astrofra.com\/weblog\/swf\/dispersion.swf\" quality=\"high\" align=\"middle\" bgcolor=\"#888888\" name=\"FlashTut\"><\/embed><\/object><\/td>\n<td><\/td>\n<td valign=\"top\">I decided to write this shader after I found this thread on usenet : <a hreflang=\"en\" href=\"http:\/\/groups.google.fr\/group\/comp.graphics.rendering.renderman\/browse_thread\/thread\/346d1027f86ba4da\/33bc37a2c806589f?q=poor+man+dispersion&amp;rnum=4&amp;hl=fr#33bc37a2c806589f\" target=\"_blank\">Poor Man&#8217;s Dispersion<\/a><br \/>\nIt describes a simple way to mimic the dispersion of light such a complex medium such as <strong>crystal<\/strong>.<\/p>\n<p>The main idea behind is to <strong>cast 3 rays<\/strong> of refracted light instead of 1. Each ray will have a slightly different index of refraction (IOR). The 3 resulting values will be <strong>recomposited in the red, green and blue component<\/strong>. This is absolutely not physically accurate, but it works quite well, as seen in the figure below (both images were rendered on a RenderDrive).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img decoding=\"async\" src=\"\/weblog\/images\/Tuts\/disp_evol.jpg\" alt=\"\" \/><\/p>\n<ol>\n<li>As mentionned in the newsgroup, this straight method gives three sharp streaks, instead of a continuous spectrum.<\/li>\n<li>That&#8217;s why we need to add a rand() function to the IOR offset. And here comes the magic of the RenderDrive, that will automatically supersample each raycast until it sufficiently reduces the noise.<\/li>\n<\/ol>\n<p>Here is the <strong>RSL source<\/strong> of the shader. It uses raytracing extensively, please don&#8217;t expect amazingly short rendertimes.<\/p>\n<pre>\nsurface PoorDispersion(float ior = 1.5; float dispersion_iota = 0.25;) \n{ \n\tpoint R, T, Nn, Ni; \n\tfloat krefl, ktran, eta; \n\t\n\tNn = normalize(N); \n\tNi = normalize(I); \n\tfresnel(Ni, Nn, 1.0 \/ ior, krefl, ktran, R, T);\n\t\n\tif (isshadowray() != 0) \n\t{ \n\t\tOi = (1.0 - ktran); \n\t} \n\telse \n\t{ \n\t\teta = ior; Oi = Os; \n\t\teta += (dispersion_iota * float random()); \n\t\tT = refract(Ni, Nn, 1 \/ eta); \n\t\tCi = trace(P, T) * color(1,0,0) * ktran; \n\t\teta += (dispersion_iota * float random()); \n\t\tT = refract(Ni, Nn, 1 \/ eta); \n\t\tCi += trace(P, T) * color(0,1,0) * ktran; \n\t\teta += (dispersion_iota * float random()); \n\t\tT = refract(Ni, Nn, 1 \/ eta); \n\t\tCi += trace(P, T) * color(0,0,1) * ktran; \n\t\tCi += trace(P, R) * krefl; \n\t} \n}\n<\/pre>\n<p>Later on, I tried this shader with the former PRman implementation of Larry Gritz : Entropy. I made a quick comparison :<br \/>\n3. RenderDrive demonstrates its ability to handle crazy raytrace<br \/>\n4. With Entropy the result is really noisy, I should reconsider the brute force approach<\/p>\n<p><img decoding=\"async\" src=\"\/weblog\/images\/Tuts\/disp_rd_vs_entropy.jpg\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to write this shader after I found this thread on usenet : Poor Man&#8217;s Dispersion It describes a simple way to mimic the dispersion of light such a complex medium such as crystal. The main idea behind is to cast 3 rays of refracted light instead of 1. Each ray will have a &hellip; <a href=\"https:\/\/astrofra.com\/wordpress\/index.php\/2005\/07\/12\/poor-man-s-dispersion-shader-rman-version\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">RenderMan | Poor Man&#8217;s Dispersion Shader<\/span> <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":{"footnotes":""},"categories":[2,1],"tags":[],"class_list":["post-664","post","type-post","status-publish","format-standard","hentry","category-3d-techniques","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/664"}],"collection":[{"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=664"}],"version-history":[{"count":0,"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/664\/revisions"}],"wp:attachment":[{"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=664"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=664"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/astrofra.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=664"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}