{"id":2266,"date":"2017-01-03T21:35:36","date_gmt":"2017-01-03T21:35:36","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2266"},"modified":"2018-04-04T08:38:56","modified_gmt":"2018-04-04T08:38:56","slug":"osl-3d-shading-masks","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2266","title":{"rendered":"Playing with OSL #1: 3D Shading Masks"},"content":{"rendered":"<p><a href=\"https:\/\/julius-ihle.de\/?p=2266\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-2267\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_pmask.jpg\" alt=\"osl_pmask\" width=\"800\" height=\"333\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_pmask.jpg 1280w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_pmask-300x125.jpg 300w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_pmask-1024x426.jpg 1024w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>I have recently started getting into Shader Writing in OSL (actually rather Pattern Writing just to not get frustrated too quickly :-) ). To start things off I wrote a simple Pattern that lets you create a life 3d mask in your shading network that can be used to alter different shading effects in very particular areas of an object without the need to paint texture masks. On top of that being OSL it should work in any renderer that supports it (e.g. PRMan\/RIS, Cycles in Blender, VRay, etc).<\/p>\n<p><!--more--><\/p>\n<p>The Pattern itself only has a few simple controls:<\/p>\n<figure id=\"attachment_2268\" aria-describedby=\"caption-attachment-2268\" style=\"width: 443px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_PMask_UI.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2268 size-full\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_PMask_UI.png\" alt=\"osl_pmask_ui\" width=\"443\" height=\"570\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_PMask_UI.png 443w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2017\/01\/osl_PMask_UI-233x300.png 233w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/a><figcaption id=\"caption-attachment-2268\" class=\"wp-caption-text\">PMask OSL Pattern inside Maya with RenderMan (PxrOSL Node)<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Here&#8217;s a quick explanation:<br \/>\n<span style=\"text-decoration: underline;\">Mapping<\/span> &#8211; determines whether to use world- or object-space for the 3d mask (choose <em>PWorld<\/em> or <em>PRef<\/em>). Unfortunately the PxrOSL node in Maya ignores shader metadata for creating a nice dropdown menu here (Blender users might be luckier :)).<br \/>\n<span style=\"text-decoration: underline;\">Radius<\/span> &#8211; The X, Y, Z (-&gt; R, G, B) scale of the spherical mask.<br \/>\n<span style=\"text-decoration: underline;\">Whitepoint<\/span> &#8211; Values below 1 will move the core towards the outside edge<br \/>\n<span style=\"text-decoration: underline;\">Blackpoint<\/span> &#8211; Values above 0 will move the outside edge towards the core<br \/>\n<span style=\"text-decoration: underline;\">Gamma<\/span> &#8211; Can be used to increase or decrease the falloff<\/p>\n<p>All of these parameters are mappable, too! In the case of this Tool this has some very nice benefits.<\/p>\n<p>The first one is that you can create a locator for example and map its translation to the Pos input. If you are using <em>PWorld<\/em> as your Mapping type it will use the world space coordinates so wherever you move the locator the mask will go as well. However assuming you are not animating the locator this will be a static mask in worldspace and any objects which are animated will swim through the mask.<br \/>\nIf you want your mask to follow your object you can set the Mapping to <em>PRef<\/em>. This will use the coordinates of the objects translation and deformation from a reference position (zero&#8217;d out transforms) and will make the mask stick to the object wherever it&#8217;s going. Keep in mind that the Origin for the position (0,0,0) is always wherever the object has zero&#8217;d out transforms. This means that you might need an offset if you have frozen your transforms at one point. Another alternative would be to parent or constraint a locator to a moving object and leave the Mapping set to <em>PWorld<\/em>.<br \/>\nTo double-check the coordinates the OSL node allows you to output <em>PWorld<\/em> and <em>PRef<\/em> for debugging purposes (you can take the RGB color values of a point in the render as your Pos value).<\/p>\n<p>Also most of the time a simple sphere is not very desirable, so you can also map the radius with other procedurals or textures to break up its shape.<\/p>\n<p>Because this is based on position data it&#8217;s completely independent of the object&#8217;s UV&#8217;s.<\/p>\n<p>You can download it <a title=\"download compiled .oso\" href=\"http:\/\/53035544.de.strato-hosting.eu\/data\/PMask.oso\">HERE<\/a>.<\/p>\n<p>Here&#8217;s a quick demo video:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/197934849\" width=\"640\" height=\"338\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/vimeo.com\/197934849\">3D Position Masks in OSL for Shading Networks<\/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>&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 have recently started getting into Shader Writing in OSL (actually rather Pattern Writing just to not get frustrated too quickly :-) ). To start things off I wrote a simple Pattern that lets you create a life 3d mask in your shading network that can be used to alter different shading effects in very [&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_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[11,99,91,93,25,97,32,12,98,96,24,92,100],"class_list":["post-2266","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-arnold","tag-blender","tag-cgi","tag-computer-graphics","tag-lighting","tag-look-development","tag-lookdev","tag-maya","tag-open-shading-language","tag-shading","tag-vfx","tag-visual-effects","tag-vray"],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3MXK6-Ay","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2266","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=2266"}],"version-history":[{"count":10,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2266\/revisions"}],"predecessor-version":[{"id":2591,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2266\/revisions\/2591"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}