{"id":125,"date":"2007-10-02T10:41:21","date_gmt":"2007-10-02T17:41:21","guid":{"rendered":"http:\/\/labs.zeh.com.br\/blog\/?p=125"},"modified":"2007-11-15T16:44:49","modified_gmt":"2007-11-15T23:44:49","slug":"seeing-shades-of-the-future","status":"publish","type":"post","link":"https:\/\/labs.zeh.com.br\/blog\/?p=125","title":{"rendered":"Seeing shades of the future"},"content":{"rendered":"<p>Other than fixes to broken features and other small things, there are two huge features I see in the future of Flash: hardware-accelerated 3D support, and pixel shader support. This dream became closer to reality yesterday, as Adobe announced <a href=\"http:\/\/www.unitzeroone.com\/blog\/misc\/hot_news_adobe_announces_flash.html\">some of the new features<\/a> of Flash Player 10 (codenamed &#8220;Astro&#8221;) at <a href=\"http:\/\/www.adobemax2007.com\/\">Adobe Max 2007<\/a> (see a video <a href=\"http:\/\/aralbalkan.com\/1048\">here<\/a>).<\/p>\n<p>What caught my attention &#8211; other than the &#8220;real&#8221; 3d for planes &#8211; is the fact that now they&#8217;ll have their own language for pixel shaders.<\/p>\n<p><!--more-->Codenamed Hydra, and apparently created <a href=\"http:\/\/llvm.org\/ProjectsWithLLVM\/#adobe-hydra\">by these guys<\/a>, the language is the basis of <a href=\"http:\/\/labs.adobe.com\/wiki\/index.php\/AIF_Toolkit\">Adobe Image Foundation<\/a>, Adobe&#8217;s new image processing platform, to be supported by their whole line of products. With its C-like syntax, it&#8217;s also analogous to other shader languages, such as OpenGL&#8217;s <a href=\"http:\/\/en.wikipedia.org\/wiki\/GLSL\">GLSL<\/a> and DirectX&#8217;s <a href=\"http:\/\/en.wikipedia.org\/wiki\/High_Level_Shader_Language\">HLSL<\/a>, so shader programmers will feel right at home.<\/p>\n<p>However, what&#8217;s cool about it is that Hydra will allow developers to write their own shaders and execute them inside the Flash Player, as they were executing normal filters such as Blur and Glow. By running Hydra code at the lowest level possible, developers will be able to use the available computer power at its best, so this opens a huge new era for graphic effects inside Flash movies, and one that has already been known for many people specially on the game development industry.<\/p>\n<p>The big question, however, is whether there will be hardware acceleration on Hydra shaders. The presentation mentioned running those shaders with &#8220;the performance of native filters that are already in the Flash Player&#8221;, with no mention of GPU support for either; the LLVM documentation mentions Hydra can run both at CPU and GPU level, and while the AIF toolkit can only be executed on computers with a recent GPU (Pixel Shader 3 is required), it doesn&#8217;t mention whether specific products such as Astro will make use of the GPU acceleration path or not.<\/p>\n<p>Regardless, even if it only means software support, a whole new field will open for Flash developers. Several people <a href=\"http:\/\/www.unitzeroone.com\/blog\/flash\/another_update_on_flash_10_hyd.html\">have already been experimenting<\/a> with the toolkit, so I saved some time to test it out and port some of the shaders and C++ code I had been creating for some college work. Here&#8217;s a sample, before and after the shader is applied:<\/p>\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/labs.zeh.com.br\/blog\/i\/hydra_threshold.jpg\" alt=\"Adjustable threshold with Hydra\" \/><\/p>\n<p>This employs an adjustable threshold &#8211; unlike a straight threshold filter, you can set the black and white threshold, and everything in-between those two values is featured as a grayscale point &#8211; that ends up allowing for a kind of anti-aliased threshold, or a very strong <em>levels<\/em> adjustement.<\/p>\n<p>Here&#8217;s the source in Hydra:<\/p>\n<pre>kernel AdjustableThreshold {\r\n    parameter float blackThreshold < \r\n        minValue:float(0);\r\n        maxValue:float(1);\r\n        defaultValue:float(0.4);\r\n    >;\r\n\r\n    parameter float whiteThreshold < \r\n        minValue:float(0);\r\n        maxValue:float(1);\r\n        defaultValue:float(0.5);\r\n    >;\r\n\r\n    void evaluatePixel(in image4 src, out pixel4 dst) {\r\n        float4 inputColor = sampleNearest(src, outCoord());\r\n        float brightness = (inputColor.r + inputColor.g + inputColor.b) \/ 3.0;\r\n        \r\n        dst = inputColor;\r\n\r\n        if (brightness < blackThreshold) {\r\n            \/\/ Below threshold\r\n            dst.r = dst.g = dst.b = 0.0;\r\n        } else if (brightness > whiteThreshold) {\r\n            \/\/ Above threshold\r\n            dst.r = dst.g = dst.b = 1.0;\r\n        } else {\r\n            \/\/ Between the threshold\r\n            dst.r = dst.g = dst.b = (brightness - blackThreshold) \/ (whiteThreshold - blackThreshold);\r\n        }\r\n\r\n    }\r\n}<\/pre>\n<p>The black threshold must always be lower than the white threshold.<\/p>\n<p>Astro&#8217;s support for Hydra has some limitations, however, so it can&#8217;t have IF statements or loops. Some of it can be worked around with inline selections, so the code below do the same thing, but it seems to be Astro-compatible:<\/p>\n<pre>kernel AdjustableThreshold {\r\n    parameter float blackThreshold < \r\n        minValue:float(0);\r\n        maxValue:float(1);\r\n        defaultValue:float(0.4);\r\n    >;\r\n\r\n    parameter float whiteThreshold < \r\n        minValue:float(0);\r\n        maxValue:float(1);\r\n        defaultValue:float(0.5);\r\n    >;\r\n\r\n    void evaluatePixel(in image4 src, out pixel4 dst) {\r\n        float4 inputColor = sampleNearest(src, outCoord());\r\n        float brightness = (inputColor.r + inputColor.g + inputColor.b) \/ 3.0;\r\n        \r\n        dst = inputColor;\r\n        \r\n        float grayscale = (brightness - blackThreshold) \/ (whiteThreshold - blackThreshold);\r\n        float ifAboveBlack = brightness > whiteThreshold ? 1.0 : grayscale;\r\n        dst.r = dst.g = dst.b = brightness < blackThreshold ? 0.0 : ifAboveBlack;\r\n    }\r\n}<\/pre>\n<p>Maybe this is not the best example of AIF's new capabilities, as it's not just about color manipulation, and there's a bit of unneeded overhead on how the colors are calculated (should use a lookup table instead of calculating the color for every pixel). However, what's cool about this is that I simply ported my code directly from a quick HLSL test I had, and it works pretty much the same, with just a few adjustments needed for syntax (and working around the IF\/loop issue, which I admit was a let down).<\/p>\n<p>Anyhow, max will have an AIF-specific presentation tomorrow (wednesday). Hopefully by then we'll be able to answer, with 100% certainty, whether Astro will use GPU-accelerated hydra processing or not.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Other than fixes to broken features and other small things, there are two huge features I see in the future of Flash: hardware-accelerated 3D support, and pixel shader support. This dream became closer to reality yesterday, as Adobe announced some of the new features of Flash Player 10 (codenamed &#8220;Astro&#8221;) at Adobe Max 2007 (see [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,2,1,20],"tags":[],"_links":{"self":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/125"}],"collection":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=125"}],"version-history":[{"count":0,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/125\/revisions"}],"wp:attachment":[{"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.zeh.com.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}