{"id":2849,"date":"2023-04-23T19:21:06","date_gmt":"2023-04-23T19:21:06","guid":{"rendered":"http:\/\/julius-ihle.de\/?p=2849"},"modified":"2023-04-24T07:54:56","modified_gmt":"2023-04-24T07:54:56","slug":"playing-with-osl-7-text-node","status":"publish","type":"post","link":"https:\/\/julius-ihle.de\/?p=2849","title":{"rendered":"Playing with OSL #7: Text Node"},"content":{"rendered":"<p><a href=\"https:\/\/julius-ihle.de\/?p=2849\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-2852 size-full\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text.jpg\" alt=\"osl_text\" width=\"1280\" height=\"533\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text.jpg 1280w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text-300x125.jpg 300w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text-1024x426.jpg 1024w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/a><\/p>\n<p>Having text live in your shaders can be a great way to add decals, burn-ins, etc. to your renders. I&#8217;ve gone on a bit of an adventure to implement an OSL shader which can be used to display arbitrary text right in your shader.<\/p>\n<p><!--more--><\/p>\n<p>Unfortunately implementing a .ttf reader is way above my head, so I had to resort to a more primitive solution. I&#8217;m using a library of images of all the common characters found on an english keyboard layout. These are read back into the shader based on the text input. Having special characters (such as ~#!$?&amp;) in file-names however is a big nono, so I resorted to unicode character naming conversion, where a single integer represents a given character. <a title=\"ascii characters\" href=\"https:\/\/www.cs.cmu.edu\/~pattis\/15-1XX\/common\/handouts\/ascii.html\" target=\"_blank\">ASCII characters<\/a> are the most important ones, which I have included in the package in a few common fonts. If you would like to use a font other than the ones provided in the package, I&#8217;m also supplying an example Nuke script in which you can just change the font and output in the required manner for the shader to read it properly:<\/p>\n<div style=\"width: 984px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2849-1\" width=\"984\" height=\"1084\" loop preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_nuke-2023-04-23_19.56.39.mp4?_=1\" \/><a href=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_nuke-2023-04-23_19.56.39.mp4\">https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_nuke-2023-04-23_19.56.39.mp4<\/a><\/video><\/div>\n<p>&nbsp;<\/p>\n<p>The idea is to supply the shader with the rendered image sequence of the unicode characters in the <code>font_source<\/code> parameter replacing the unicode numbers with a hash, like so:<br \/>\n<code>\/home\/julius\/shaders\/util\/unicode_characters\/Arial\/#.tx<\/code><br \/>\nNote that some DCC&#8217;s convert the <code>#<\/code> to the current frame number, which can be avoided by escaping it, eg by prepending a backslash: <code>\\#<\/code><br \/>\nIf the input font path is not valid, you will get a warning in the terminal and the shader will output the color specified in the <code>false_color<\/code> parameter.<\/p>\n<p>The text to render can be anything you like, provided you have a corresponding unicode character rendered. New lines can be added via <code>\\n<\/code> (some DCC&#8217;s might need <code>\\\\n<\/code>).<br \/>\n<a href=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_img1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-2851 size-full\" src=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_img1.png\" alt=\"osl_text_img1\" width=\"920\" height=\"412\" srcset=\"https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_img1.png 920w, https:\/\/julius-ihle.de\/wp-content\/uploads\/2023\/04\/osl_text_img1-300x134.png 300w\" sizes=\"auto, (max-width: 920px) 100vw, 920px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Apart from that you have a couple of options for placing it on the UV&#8217;s and general text editing stuff (alignment, leading, kerning, etc).<\/p>\n<p>One thing I find this particularly useful for is pipeline automation&#8230; automated burnins on slates, etc. The assets from example turntable setup in the demo below is from the awesome team at <a title=\"CAVE Academy\" href=\"https:\/\/caveacademy.com\/\" target=\"_blank\">CAVE Academy<\/a>. Make sure you check them out!<\/p>\n<p>You can download it <a title=\"download jiText\" href=\"https:\/\/github.com\/julsVFX\/osl\/tree\/main\/jiText\" target=\"_blank\">HERE<\/a><\/p>\n<p>Demo can be seen here:<br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/820321839?h=a9bd7fb8d5\" width=\"640\" height=\"400\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p><a href=\"https:\/\/vimeo.com\/820321839\">OSL Text 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><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<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having text live in your shaders can be a great way to add decals, burn-ins, etc. to your renders. I&#8217;ve gone on a bit of an adventure to implement an OSL shader which can be used to display arbitrary text right in your shader.<\/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-2849","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3MXK6-JX","jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2849","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=2849"}],"version-history":[{"count":7,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2849\/revisions"}],"predecessor-version":[{"id":2860,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=\/wp\/v2\/posts\/2849\/revisions\/2860"}],"wp:attachment":[{"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julius-ihle.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}