{"id":2755,"date":"2021-01-05T15:48:55","date_gmt":"2021-01-05T15:48:55","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2755"},"modified":"2021-05-02T14:25:02","modified_gmt":"2021-05-02T14:25:02","slug":"playing-with-osl-4-udim-mask","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2755","title":{"rendered":"Playing with OSL #4: UDIM Mask"},"content":{"rendered":"<p><a href=\"https:\/\/julius-ihle.de\/?p=2755\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2756\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/01\/b_udimmask-1024x426.png\" alt=\"b_udimmask\" width=\"1000\" height=\"416\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/01\/b_udimmask-1024x426.png 1024w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/01\/b_udimmask-300x125.png 300w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/01\/b_udimmask.png 1280w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><br \/>\nIt&#8217;s been a while&#8230; Busy days :)<\/p>\n<p>Occasionally there might be the need for LookDev Artists to adjust areas of a shader based on different UDIMs. If an asset has a continuous mesh that is only separated by UDIMs (eg nails on a character or decorative parts of clothing) it can be useful to create masks for specific UDIMs in the shading network to isolate areas of interest.<br \/>\n<!--more--><\/p>\n<p>It is relatively straight forward to get the integer values of each UDIM in a shader by just creating a Nodegraph that resembles the UDIM formula:<br \/>\n<code><strong><em>1000+(floor(u)+1)+(floor(v)*10)<\/em><\/strong><\/code><\/p>\n<p>You can output the result into a compare node in your renderer of choice and check whether it matches against a certain UDIM. While this is fine for 1 or 2 UDIMs it gets quite cumbersome with many UDIMs.<\/p>\n<p>As I like playing with OSL I put together a version that allows you to create masks from a specified list of UDIMs. It expects a comma-separated list of UDIM tiles. You can also specify ranges. Eg <strong><em>1001,1003-1006,1015,125<\/em><\/strong> will select the following UDIMs: 1001,1003,1004,1005,1006,1015,1025.<br \/>\nYou can also just output the raw UDIM tiles integers if you want to create more complex masks downstream.<\/p>\n<p>There are just a few caveats:<br \/>\n1) The input is a string, so internally it&#8217;s checking against a regex to see if the passed input is a valid list of UDIMs. This can potentially be expensive in larger shading networks.<br \/>\n2) At the moment there&#8217;s a hard-coded maximum of 10 entries that are allowed for performance reasons (note that ranges such as 1001-1005 count as 1 entry). You can edit the <code>#define MAX_TILES 10<\/code> in the supplied .osl file if you need more.<br \/>\n3) At the moment I could only test it with Arnold. Not sure if Blender supports UDIMs properly in this way. RenderMan should work as well.<\/p>\n<p>You can download it <a title=\"Download\" href=\"https:\/\/github.com\/julsVFX\/osl\">HERE<\/a> from github.<\/p>\n<p>Here&#8217;s a quick demo:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/497299703\" width=\"640\" height=\"360\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/vimeo.com\/497299703\">OSL UDIM Mask<\/a> from <a href=\"https:\/\/vimeo.com\/julsvfx\">Julius Ihle<\/a> on <a href=\"https:\/\/vimeo.com\">Vimeo<\/a>.<\/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=\"https:\/\/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","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a while&#8230; Busy days :) Occasionally there might be the need for LookDev Artists to adjust areas of a shader based on different UDIMs. If an asset has a continuous mesh that is only separated by UDIMs (eg nails on a character or decorative parts of clothing) it can be useful to create [&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":[],"class_list":["post-2755","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3MXK6-Ir","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2755","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=2755"}],"version-history":[{"count":8,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2755\/revisions"}],"predecessor-version":[{"id":2772,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2755\/revisions\/2772"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}