<!--
Copyright 2016 Autodesk, Inc. All rights reserved. 

Use of this software is subject to the terms of the Autodesk 
license agreement provided at the time of installation or download, 
or which otherwise accompanies this software in either electronic 
or hard copy form.
-->
<fragment  uiName="Maya_SSAOFragment_Imp" name="Maya_SSAOFragment_Imp" type="sceneEffect" class="ScriptFragment" version="1.0" feature_level="30" >
    <description>
<![CDATA[
Screen-space ambient occlusion compositor]]>
</description>
    <properties>
        <target  name="final" />
        <target  name="finalDesc" />
        <float4  name="viewport" />
        <camera  name="camera" />
        <target  name="sceneBuffer" />
        <float4  name="scissorRect" />
        <target  name="frontFaceNormal" />
        <target  name="frontFaceDepth" />
        <target  name="backFaceDepth" />
        <int  name="SampleCount" />
        <float  name="SampleRadius" />
        <int  name="BlurAmount" />
        <bool  name="BlurDouble" />
        <float  name="CompositeFactor" />
        <float3  name="CompositeColor" />
    </properties>
    <values>
<float4 name="viewport" value="0.000000,0.000000,1.000000,1.000000"  />
<float4 name="scissorRect" value="0.000000,0.000000,1.000000,1.000000"  />
<int name="SampleCount" value="16"  />
<float name="SampleRadius" value="0.028107"  />
<int name="BlurAmount" value="8"  />
<bool name="BlurDouble" value="true"  />
<float name="CompositeFactor" value="0.940000"  />
<float3 name="CompositeColor" value="0.000000,0.000000,0.000000"  />
    </values>
    <outputs>
        <target  name="output" />
    </outputs>
    <parametershare>
    </parametershare>
    <implementation render="OGS" language="ScriptInterpreter" version="0.1" >
        <scriptCommands>
            <AcquireTarget name="localAOBuffer" format="EFORMAT_B8G8R8A8" size="@finalDesc.size" relSize="1.0,1.0" msaa="0" />
            <AcquireTarget name="localBlurBuffer" format="EFORMAT_B8G8R8A8" size="@finalDesc.size" relSize="1.0,1.0" msaa="0" />
            <SetEffect name="MainEffect" path="SSAO_Main" technique="" macrolist="NUM_SAMPLES=@SampleCount,DOUBLE_LAYER=@backFaceDepth" />
            <SetEffectParameter effect="MainEffect" name="gProjection" value="@camera.ProjectionMatrix" />
            <SetEffectParameter effect="MainEffect" name="gPerspectiveFlag" value="@camera.PerspectiveFlag" />
            <SetEffectParameter effect="MainEffect" name="gSampleRadius" value="@SampleRadius" />
            <SetEffectParameter effect="MainEffect" name="gRandomSamp" value="PointWrap" />
            <SetTexture effect="MainEffect" name="gNormalTex" value="" texture="@frontFaceNormal" />
            <SetEffectParameter effect="MainEffect" name="gNormalSamp" value="PointClamp" />
            <SetTexture effect="MainEffect" name="gDepthTex" value="" texture="@frontFaceDepth" />
            <SetEffectParameter effect="MainEffect" name="gDepthSamp" value="PointClamp" />
            <If value="@backFaceDepth" />
            <SetTexture effect="MainEffect" name="gDepthTex2" value="" texture="@backFaceDepth" />
            <SetEffectParameter effect="MainEffect" name="gDepthSamp2" value="PointClamp" />
            <EndIf />
            <SetTarget index="0" value="localAOBuffer" />
            <SetViewport value="0.0,0.0,1.0,1.0" />
            <Render name="Quad" />
            <SetTexture effect="MainEffect" name="gNormalTex" value="" texture="" />
            <SetTexture effect="MainEffect" name="gDepthTex" value="" texture="" />
            <If value="@backFaceDepth" />
            <SetTexture effect="MainEffect" name="gDepthTex2" value="" texture="" />
            <EndIf />
            <SetEffect name="BlurEffect" path="SSAO_Blur" technique="" macrolist="BLUR_AMOUNT=@BlurAmount" />
            <SetEffectParameter effect="BlurEffect" name="gProjection" value="@camera.ProjectionMatrix" />
            <SetEffectParameter effect="BlurEffect" name="gPerspectiveFlag" value="@camera.PerspectiveFlag" />
            <SetEffectParameter effect="BlurEffect" name="gSampleRadius" value="@SampleRadius" />
            <SetEffectParameter effect="BlurEffect" name="gBlurDirection" value="1.0,0.0" />
            <SetTexture effect="BlurEffect" name="gSourceTex" value="" texture="localAOBuffer" />
            <SetEffectParameter effect="BlurEffect" name="gSourceSamp" value="PointClamp" />
            <SetTexture effect="BlurEffect" name="gDepthTex" value="" texture="@frontFaceDepth" />
            <SetEffectParameter effect="BlurEffect" name="gDepthSamp" value="PointClamp" />
            <SetTexture effect="BlurEffect" name="gNormalTex" value="" texture="@frontFaceNormal" />
            <SetEffectParameter effect="BlurEffect" name="gNormalSamp" value="PointClamp" />
            <SetTarget index="0" value="localBlurBuffer" />
            <Render name="Quad" />
            <SetEffectParameter effect="BlurEffect" name="gBlurDirection" value="0.0,1.0" />
            <SetTexture effect="BlurEffect" name="gSourceTex" value="" texture="localBlurBuffer" />
            <SetTarget index="0" value="localAOBuffer" />
            <Render name="Quad" />
            <If value="@BlurDouble" />
            <SetEffectParameter effect="BlurEffect" name="gBlurDirection" value="1.0,0.0" />
            <SetTexture effect="BlurEffect" name="gSourceTex" value="" texture="localAOBuffer" />
            <SetTarget index="0" value="localBlurBuffer" />
            <Render name="Quad" />
            <SetEffectParameter effect="BlurEffect" name="gBlurDirection" value="0.0,1.0" />
            <SetTexture effect="BlurEffect" name="gSourceTex" value="" texture="localBlurBuffer" />
            <SetTarget index="0" value="localAOBuffer" />
            <Render name="Quad" />
            <EndIf />
            <SetTexture effect="BlurEffect" name="gSourceTex" value="" texture="" />
            <SetTexture effect="BlurEffect" name="gDepthTex" value="" texture="" />
            <SetTexture effect="BlurEffect" name="gNormalTex" value="" texture="" />
            <SetEffect name="CompositeEffect" path="SSAO_Composite" technique="" macrolist="USE_SCENE_BUFFER=@sceneBuffer" />
            <SetEffectParameter effect="CompositeEffect" name="gCompositeFactor" value="@CompositeFactor" />
            <SetEffectParameter effect="CompositeEffect" name="gCompositeColor" value="@CompositeColor" />
            <SetTexture effect="CompositeEffect" name="gSourceTex" value="" texture="localAOBuffer" />
            <SetEffectParameter effect="CompositeEffect" name="gSourceSamp" value="PointClamp" />
            <AssignTarget destName="localSSAOFinal" srcName="@final" format="@finalDesc" />
            <SetTarget index="0" value="localSSAOFinal" />
            <If value="@sceneBuffer" />
            <Declare name="localState3" type="stateSetter" />
            <SetStateCommand commandName="SetRenderState" name="localState3" parameter="BlendOff" />
            <SetStateCommand commandName="SetRenderState" name="localState3" parameter="ZOff" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="FillMode" value="EFillSolid" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="CullMode" value="ECullNone" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="ColorInterpolationEnable" value="true" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="ScissorEnable" value="true" />
            <SetStateCommand commandName="CommitNewState" name="localState3" />
            <SetTexture effect="CompositeEffect" name="gSceneTex" value="" texture="@sceneBuffer" />
            <SetEffectParameter effect="CompositeEffect" name="gSceneSamp" value="PointClamp" />
            <Render name="Quad" useDefault="false" />
            <Else />
            <Declare name="localState3" type="stateSetter" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="SetBlendEnable" value="true" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="BlendOperation" value="Add" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="DestinationBlend" value="SourceAlpha" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="SourceBlend" value="Zero" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="AlphaBlendOperation" value="Add" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="AlphaDestinationBlend" value="One" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="AlphaSourceBlend" value="Zero" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="CullMode" value="ECullNone" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="ScissorEnable" value="false" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="DepthEnable" value="false" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="DepthWriteEnable" value="false" />
            <SetStateCommand commandName="SetStateParameter" name="localState3" parameter="DepthFunction" value="Always" />
            <SetStateCommand commandName="CommitNewState" name="localState3" />
            <Render name="Quad" useDefault="false" />
            <EndIf />
            <SetTexture effect="CompositeEffect" name="gSourceTex" value="" texture="" />
            <If value="@sceneBuffer" />
            <SetTexture effect="CompositeEffect" name="gSceneTex" value="" texture="" />
            <EndIf />
            <SetStateCommand commandName="RestorePreviousState" name="localState3" />
            <SetParameter name="@output" value="localSSAOFinal" />
            <RestoreOverrideEffect />
        </scriptCommands>
    </implementation>
</fragment>

