<?xml version="1.0" encoding="utf-8"?>

<!--    SmartSSAO Shadertest - http://www.smart-page.net/blog/2009/10/05/realtime-ssao-with-after-effects-and-pixel-bender/    -->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
    
     <mx:Script>
        <![CDATA[

            [Embed(source="assets/shaders/SmartSSAO_fl.pbj", mimeType="application/octet-stream")]
            private var SmartSSAO:Class;
                        
            private var shader:Shader;
                        
            private function dofilter():void {
                
                zmap.blendMode=BlendMode.MULTIPLY;
                shader = new Shader(new SmartSSAO() as ByteArray);
                
                update();
            }    
            
            private function update():void {
                
                shader.data.A_bias.value[0]         = A_bias_slider.value;
                shader.data.B_radius.value[0]         = B_radius_slider.value;
                shader.data.C_bleed.value[0]         = C_bleed_slider.value;
                shader.data.D_lightxy.value[0]         = D_lightx_slider.value;
                shader.data.D_lightxy.value[1]         = D_lighty_slider.value;
                shader.data.E_noise.value[0]         = E_noise_slider.value;
                shader.data.F_brightness.value[0]     = F_brightness_slider.value;
                shader.data.G_contrast.value[0]     = G_contrast_slider.value;
                
                zmap.filters = [new ShaderFilter(shader),new BlurFilter(blur_slider.value, blur_slider.value)];    
                
                var ct:ColorTransform = new  ColorTransform();
                ct.redOffset = colored_checkbox.selected ? 255 : 0;
                zmap.transform.colorTransform = ct;
                
                rgbmap.visible = rgbshow_checkbox.selected;
                
                zmap.visible=showssao_checkbox.selected;
            }                    
        ]]>
    </mx:Script>
    
    <mx:Image 
        id="rgbmap" 
        x="280"
        y="15"
        source="@Embed(source='assets/images/rgbbudda.jpg')" 
        creationComplete="dofilter()"
    />
    <mx:Image  
        id="zmap" 
        x="280"
        y="15"
        source="@Embed(source='assets/images/zbudda.jpg')" 
        creationComplete="dofilter()"
    />
    
    <mx:Label x="10" y="10" text="A_bias:"/>
    <mx:HSlider id="A_bias_slider" x="100"    y="5" value="30" minimum="0" maximum="100" snapInterval="1" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="25" text="B_radius:"/>
    <mx:HSlider id="B_radius_slider" x="100" y="20" value="3" minimum="0" maximum="10" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="40" text="C_bleed:"/>
    <mx:HSlider id="C_bleed_slider" x="100" y="35" value="1.0" minimum="0.01" maximum="2.0" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="55" text="D_lightX:"/>
    <mx:HSlider id="D_lightx_slider" x="100" y="50" value="0.0" minimum="-1.0" maximum="1.0" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="70" text="D_lightY:"/>
    <mx:HSlider id="D_lighty_slider" x="100" y="65" value="0.0" minimum="-1.0" maximum="1.0" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="85" text="E_noise:"/>
    <mx:HSlider id="E_noise_slider" x="100" y="80" value="0.02" minimum="-0.1" maximum="0.1" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="100" text="F_brightness:"/>
    <mx:HSlider id="F_brightness_slider" x="100" y="95" value="1.0" minimum="0.0" maximum="2.0" snapInterval="0.01" liveDragging="true" change="update()"/>
    <mx:Label x="10" y="115" text="G_contrast:"/>
    <mx:HSlider id="G_contrast_slider" x="100" y="110" value="5.0" minimum="0.0" maximum="5.0" snapInterval="0.01" liveDragging="true" change="update()"/>
    
    <mx:Label x="10" y="140" text="blur:"/>
    <mx:HSlider id="blur_slider" x="100" y="135" value="7.0" minimum="0.0" maximum="30.0" snapInterval="1" liveDragging="true" change="update()"/>
    
    <mx:CheckBox id="showssao_checkbox" x="105" y="165" width="150" label="show SSAO?" selected="true" change="update()"/> 
    <mx:CheckBox id="colored_checkbox" x="105" y="185" width="150" label="color SSAO?" selected="true" change="update()"/> 
    <mx:CheckBox id="rgbshow_checkbox" x="105" y="205" width="150" label="show rgb-map?" selected="true" change="update()"/> 
    
</mx:Application>