{"id":2433,"date":"2017-06-14T22:04:46","date_gmt":"2017-06-14T22:04:46","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2433"},"modified":"2018-04-04T08:38:29","modified_gmt":"2018-04-04T08:38:29","slug":"playing-with-osl-2-triplanar-roundcube-shader","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2433","title":{"rendered":"Playing with OSL #2: TriPlanar \/ RoundCube Shader"},"content":{"rendered":"<p><a href=\"https:\/\/julius-ihle.de\/?p=2433\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2434\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/06\/osltriplanar.jpg\" alt=\"osltriplanar\" width=\"1280\" height=\"533\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/06\/osltriplanar.jpg 1280w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/06\/osltriplanar-300x125.jpg 300w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/06\/osltriplanar-1024x426.jpg 1024w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/a><\/p>\n<p>I had another go at playing around with OSL. This time I tried making a Tri Planar (or sometimes also called Round Cube or Blended Box Mapping) shader. It was an interesting thing to try out as it involves a bit more work. What I came up with however merely serves as an experimental try-out rather than being useful for production. It has a few common features that you would most likely find in modern rendering or texturing packages.<!--more--><\/p>\n<p>What\u00a0exactly it is is quite nicely explained <a title=\"What's TriPlanar?\" href=\"http:\/\/www.neilblevins.com\/cg_education\/blended_box_mapping\/blended_box_mapping.htm\" target=\"_blank\">HERE<\/a>. You\u00a0&#8220;project&#8221; images from 6 sides around your objects onto it and blend between the transitional areas. The nice thing about it is that you can pretty easily texture objects that way without needing to UV unwrap them. Instead of using the UV&#8217;s as the texture coordinates it&#8217;s using 2 of the positional axis that are perpendicular to the angle you want to project from &#8211; i.e. map the texture onto P.x and P.y to get a nicely undistorted projection when you are looking from the Z axis. This is done for all 3 axis. The result of these 3 projections are then layered on top of each other with a mask based on the normals of the object. In my case I took Mari as an example on how it approaches the layering (X over Y over Z). Additionally you can layer it on top of an input texture in the shader itself.<br \/>\nA common problem on round surfaces is usually that the transitional areas may often be too smooth. To break it up a bit I added an additional input which is mixed into the transitional areas (you can for example plug in a noise to get a rougher transition). If the objects in your scene aren&#8217;t quite oriented the way you want there&#8217;s a cheap rotation control in the shader as well (not very sophisticated as it just layers rotations on top of each other instead of doing it via a matrix).<\/p>\n<p>As it&#8217;s written in OSL it can be used with a variety of renderes. I only tested it in Blender and PRMan, but it should work just the same with 3Delight, VRay, Arnold, Clarisse, etc.<\/p>\n<p>Here&#8217;s a quick demo showing some of the controls:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/221654997\" width=\"640\" height=\"360\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/vimeo.com\/221654997\">Playing with OSL #2: Tri Planar \/ Round Cube<\/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>The compiled oso can be downloaded\u00a0<a title=\"download\" href=\"http:\/\/53035544.de.strato-hosting.eu\/data\/triplanar.oso\" target=\"_blank\">HERE<\/a>.<\/p>\n<p>You can get the original <a title=\"osl code\" href=\"http:\/\/53035544.de.strato-hosting.eu\/data\/triplanar.osl\" target=\"_blank\">HERE<\/a>. Don&#8217;t take this as a good example when you are learning&#8230; I&#8217;m not a programmer, I&#8217;m just goofing around&#8230; :-)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<br \/>\n<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\u00a0<\/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=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2018\/03\/bc_ldgr_qrcode.png\" alt=\"bc_ldgr_qrcode\" width=\"128\" height=\"128\" \/><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I had another go at playing around with OSL. This time I tried making a Tri Planar (or sometimes also called Round Cube or Blended Box Mapping) shader. It was an interesting thing to try out as it involves a bit more work. What I came up with however merely serves as an experimental try-out [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2433","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3MXK6-Df","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2433","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=2433"}],"version-history":[{"count":9,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2433\/revisions"}],"predecessor-version":[{"id":2588,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2433\/revisions\/2588"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}