{"id":2788,"date":"2021-09-15T19:42:58","date_gmt":"2021-09-15T19:42:58","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2788"},"modified":"2021-09-16T14:01:03","modified_gmt":"2021-09-16T14:01:03","slug":"playing-with-osl-5-arnold-reflection-alpha-utilities","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2788","title":{"rendered":"Playing with OSL #5: Arnold Reflection Alpha + Utilities"},"content":{"rendered":"<p><a href=\"http:\/\/julius-ihle.de\/?p=2788\"><img class=\"lazyload aligncenter wp-image-2789 size-large\" data-original=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/arnold_refl_aovs-1024x426.jpg\" alt=\"arnold_refl_aovs\" width=\"1000\" height=\"416\" \/><\/a><\/p>\n<p>When trying to integrate CG renders into real life footage one common hurdle is to treat reflections properly. Often times in your plate you will have elements that have bright reflections (eg windows, plastic chairs, shiny tables, etc) in which your CG elements need to reflect. Rendering a simple reflection pass however often times does not really cut it<\/p>\n<p><!--more--><\/p>\n<p>See the example below. If you were to add a usual reflection pass to it the result does not really make sense:<\/p>\n<p><a href=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/03_renderrefl.jpg\"><img class=\"lazyload aligncenter size-full wp-image-2790\" data-original=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/03_renderrefl.jpg\" alt=\"03_renderrefl\" width=\"458\" height=\"512\" \/><\/a><\/p>\n<p>This is because the reflection is simply added in this case. While adding reflections is technically correct, the problem is that we already have reflections in the plate. The window behind the table has a large contribution to the specular reflection on the table. If you look at the cup on the right what is happening is that the cups reflection is blocking the highlights from the window. As the cup is neither emissive nor very bright it&#8217;s reflection is a lot darker.<\/p>\n<p>We&#8217;d need to do something similar to the reflection of the CG render. A common trick is to render a separate reflection of the same element but with a constant white shader. This has several drawbacks tough:<br \/>\nMost renderers don&#8217;t support arbitrary utility outputs in traced results. This means the render would need to be a separate layer<br \/>\n&#8211;&gt; more render layers to manage for the Lighting TD<br \/>\n&#8211;&gt; longer rendering times<br \/>\n&#8211;&gt; Comp has to deal with more separate renders<br \/>\n&#8211;&gt; even more layers to manage if additional utility passes are requested (reflected Position, Normals, userdata, etc.)<\/p>\n<p>Ideally you would have the alpha and any additional arbitrary outputs as an AOV instead of a separate render to remedy all of the drawbacks mentioned above.<\/p>\n<p>&nbsp;<\/p>\n<p>I therefore wrote a simple OSL shader. This however probably only works reliably in more recent versions of Arnold. You can assign it to your set geometry and anything that will reflect in it will sample whichever shading component you specify. This supports OSL builtins (eg <code>P<\/code> and <code>N<\/code>) as well as arbitrary userdata (eg <code>Pref<\/code>). If you use <code>dist<\/code> or <code>distance<\/code> as a special keyword for the trace_component it will output the distance of the reflection from the current shading point, which can be used in comp to fake roughness. If the given component is not found it will reflect the <code>trace_color<\/code> (eg to be used as an alpha for reflections).<br \/>\nIf your set geometry contains multiple shapes you can add them to a trace set and specify that same trace set in the shader and untick <code>inclusive<\/code>. This will allow only reflections from your anything other than the set geometry.<br \/>\n<a href=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/07UIv002.png\"><img class=\"lazyload aligncenter wp-image-2798 size-full\" data-original=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/07UIv002.png\" alt=\"\" width=\"464\" height=\"167\" \/><\/a><\/p>\n<p>The shader will output rgb data which means you can pipe it into custom AOVs for example with the help of <code>aov_write<\/code> shading nodes:<br \/>\n<a href=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/08_mayav002.png\"><img class=\"lazyload aligncenter wp-image-2799 size-large\" data-original=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/08_mayav002-1024x610.png\" alt=\"\" width=\"1000\" height=\"596\" \/><\/a><\/p>\n<p>With a little bit of comp love you can get quite promising results:<br \/>\n<a href=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/comp.png\"><img class=\"lazyload aligncenter size-full wp-image-2802\" data-original=\"http:\/\/julius-ihle.de\/wp-content\/uploads\/2021\/09\/comp.png\" alt=\"comp\" width=\"458\" height=\"512\" \/><\/a><\/p>\n<p>You can give it a whirl by downloading the jiTraceAOVs shader from my <a title=\"github\" href=\"https:\/\/github.com\/julsVFX\/osl\">github<\/a><\/p>\n<p>Here&#8217;s a bit more indepth demo + a simple comp example:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/605842818\" width=\"640\" height=\"360\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/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 class=\"lazyload\" data-original=\"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 class=\"lazyload alignleft size-full wp-image-2576\" data-original=\"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","protected":false},"excerpt":{"rendered":"<p>When trying to integrate CG renders into real life footage one common hurdle is to treat reflections properly. Often times in your plate you will&hellip;<\/p>\n<p><a href=\"https:\/\/julius-ihle.de\/?p=2788\" class=\"more-link post-excerpt-readmore\"><span class=\"more-link-inner\">Read more<\/span><span class=\"more-link-brd\"><\/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":[1],"tags":[],"class_list":["post-2788","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2788","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=2788"}],"version-history":[{"count":7,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2788\/revisions"}],"predecessor-version":[{"id":2803,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2788\/revisions\/2803"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}