{"id":2829,"date":"2022-12-29T12:12:08","date_gmt":"2022-12-29T12:12:08","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2829"},"modified":"2022-12-29T22:27:33","modified_gmt":"2022-12-29T22:27:33","slug":"playing-with-osl-6-fake-refraction-parallax","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2829","title":{"rendered":"Playing with OSL #6: Fake Refraction Parallax"},"content":{"rendered":"<p><a href=\"http:\/\/julius-ihle.de\/?p=2829\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2830 size-large\" src=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/osl_fake_parallax-1024x426.jpg\" alt=\"osl_fake_parallax\" width=\"1000\" height=\"416\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/osl_fake_parallax-1024x426.jpg 1024w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/osl_fake_parallax-300x125.jpg 300w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/osl_fake_parallax.jpg 1280w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Sometimes getting complex refactive behavior through surfaces can be a tricky challenge. If you&#8217;re trying to recreate something like cracks inside of ice it can be a challenge to get this behavior as it can involve a lot of iterations in on the internal geometry and shader adjustments. Often it will also take a long while to render if you&#8217;re doing actual refractions. If you need something simpler tough there are ways to do that in the shader directly<\/p>\n<p><!--more--><\/p>\n<p>I got the initial idea for this from <a title=\"unreal ice shader\" href=\"https:\/\/www.youtube.com\/watch?v=X5WASspig3g\" target=\"_blank\">Ben Cloward&#8217;s ice shader test<\/a> in Unreal. It&#8217;s a very smart approach in which you get the appearance of the surface texture extending into the volume of the geometry that you are applying the shader to. Given this approach I wrote an OSL shader that does the same thing. I mainly created it for the purpose of shading ice-like internal structures but it can potentially be extended for other use cases as well.<\/p>\n<p><a href=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/ui.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2831\" src=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/ui.png\" alt=\"ui\" width=\"409\" height=\"245\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/ui.png 409w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2022\/12\/ui-300x180.png 300w\" sizes=\"auto, (max-width: 409px) 100vw, 409px\" \/><\/a><\/p>\n<p>You can supply a texture file into the <code>filename<\/code> parameter. The texture will be applied to the surface UV&#8217;s with periodic tiling. With the default values it creates a duplicate of the supplied texture &#8220;inside&#8221; the objects that the shader is applied to at the specified <code>depth<\/code>. The <code>invert_depth<\/code> parameter will drastically change the look. Depending on the source texture you are using it can give the appearance of occluded cracks vs a &#8220;see through&#8221; repetition of the surface texture. A <code>roughness<\/code> parameter is also available which you can use to simulate the texture getting more murky the deeper it goes &#8220;into&#8221; the object. This is not a physical parameter but just a simple texture blur. If you want a smoother appearance of continuous streaks as the texture goes into the surface you can increase the number of <code>steps<\/code>. This can simulate continuous from the surface down to the specified depth. Keep in mind that this is the number of texture calls, so having high values here can potentially make it quite slow.<br \/>\nUnfortunately this time it won&#8217;t work with Blender as I couldn&#8217;t find a proper way to get the derivatives &amp; UV&#8217;s to work as expected :( If anyone has the time to look into it please feel free to do so!<\/p>\n<p>As always having a visual demo is probably a good idea, so here it comes:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/784975059?h=25178ea7fe\" width=\"640\" height=\"360\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/vimeo.com\/784975059\">OSL Fake Parallax Shader<\/a> from <a href=\"https:\/\/vimeo.com\/julsvfx\">Julius Ihle<\/a> on <a href=\"https:\/\/vimeo.com\">Vimeo<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>You can download it from <a title=\"Download\" href=\"https:\/\/github.com\/julsVFX\/osl\" target=\"_blank\">HERE<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #808080;\">_________________________________________________<\/span><br \/>\n<span style=\"color: #808080;\"><span style=\"font-size: small;\"> If this post has helped you in any way you can express your gratefulness by using the <em>Donate <\/em>Button below to buy me a coffee! :)<\/span><\/span><br \/>\n<a href=\"https:\/\/www.paypal.com\/cgi-bin\/webscr?cmd=_s-xclick&amp;hosted_button_id=VH5RW3YDWDJSQ\" target=\"_blank\" rel=\"nofollow\"><img decoding=\"async\" src=\"https:\/\/www.paypal.com\/en_US\/i\/btn\/x-click-but21.gif\" alt=\"\" \/><\/a><\/p>\n<div class=\"moz-text-html\" lang=\"x-unicode\">\n<div><span style=\"font-size: small;\"><span style=\"color: #808080;\">3M5xNSV7g2NzVpHMqzYKhgoKJZ8CWa644m<\/span><\/span><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2576\" src=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2018\/03\/bc_ldgr_qrcode.png\" alt=\"bc_ldgr_qrcode\" width=\"128\" height=\"128\" \/><\/div>\n<div><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Sometimes getting complex refactive behavior through surfaces can be a tricky challenge. If you&#8217;re trying to recreate something like cracks inside of ice it can be a challenge to get this behavior as it can involve a lot of iterations in on the internal geometry and shader adjustments. Often it will also take a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2829","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2829"}],"version-history":[{"count":5,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2829\/revisions"}],"predecessor-version":[{"id":2837,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2829\/revisions\/2837"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}