// Ambient Oclussion

cbuffer cPSScene : register(b2)
{

  struct
  {
    float4x4 m_projectionView;
    float4x4 m_projection;
    float4x4 m_view;
    float4x4 m_shadowProjection;
    float4x4 m_shadowProjection2;
    float4 m_eyepos;
    float4 m_projectionParam;
    float4 m_viewportSize;
    float4 m_exposure;
    float4 m_fogParam[3];
    float4 m_fogColor;
    float4 m_cameraCenterOffset;
    float4 m_shadowMapResolutions;
  } g_psScene : packoffset(c0);

}

cbuffer cPSObject : register(b5)
{

  struct
  {
    float4x4 m_viewWorld;
    float4x4 m_world;
    float4 m_useWeightCount;
    float4 m_localParam[4];
  } g_psObject : packoffset(c0);

}

SamplerState g_samplerPoint_Wrap_s : register(s8);
Texture2D<float4> inImage : register(t0);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main( 
  float4 v0 : SV_Position0,
  float4 v1 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyzw = v1.zwzw * float4(-2,-0,1,0) + v1.xyxy;
  r0.xyzw = max(float4(0,0,0,0), r0.xyzw);
  r0.xyzw = min(g_psObject.m_localParam[0].zwzw, r0.xyzw);
  r1.xyzw = inImage.Sample(g_samplerPoint_Wrap_s, r0.xy).wxyz;
  r0.xyzw = inImage.Sample(g_samplerPoint_Wrap_s, r0.zw).xyzw;
  r2.x = dot(r1.yzw, float3(0.99609375,0.00389099121,1.51991844e-005));
  r2.x = g_psScene.m_viewportSize.w * r2.x;
  r3.xyzw = v1.zwzw * float4(-1,-0,2,0) + v1.xyxy;
  r3.xyzw = max(float4(0,0,0,0), r3.xyzw);
  r3.xyzw = min(g_psObject.m_localParam[0].zwzw, r3.xyzw);
  r4.xyzw = inImage.Sample(g_samplerPoint_Wrap_s, r3.xy).xyzw;
  r3.xyzw = inImage.Sample(g_samplerPoint_Wrap_s, r3.zw).xyzw;
  r4.x = dot(r4.xyz, float3(0.99609375,0.00389099121,1.51991844e-005));
  r1.y = r4.w;
  r2.y = g_psScene.m_viewportSize.w * r4.x;
  r0.x = dot(r0.xyz, float3(0.99609375,0.00389099121,1.51991844e-005));
  r1.z = r0.w;
  r2.z = g_psScene.m_viewportSize.w * r0.x;
  r0.x = dot(r3.xyz, float3(0.99609375,0.00389099121,1.51991844e-005));
  r1.w = r3.w;
  r2.w = g_psScene.m_viewportSize.w * r0.x;
  r0.xy = max(float2(0,0), v1.xy);
  r0.xy = min(g_psObject.m_localParam[0].zw, r0.xy);
  r0.xyzw = inImage.Sample(g_samplerPoint_Wrap_s, r0.xy).xyzw;
  r3.x = dot(r0.xyz, float3(0.99609375,0.00389099121,1.51991844e-005));
  r2.xyzw = -r3.xxxx * g_psScene.m_viewportSize.wwww + r2.xyzw;
  r2.xyzw = float4(1,1,1,1) + abs(r2.xyzw);
  r2.xyzw = float4(0.0670000017,0.241999999,0.241999999,0.0670000017) / r2.xyzw;
  r1.x = dot(r1.xyzw, r2.xyzw);
  r0.w = r0.w * 0.382999986 + r1.x;
  o0.xyz = r0.xyz;
  r0.x = r2.x + r2.y;
  r0.x = r0.x + r2.z;
  r0.x = r0.x + r2.w;
  r0.x = 0.382999986 + r0.x;
  o0.w = r0.w / r0.x;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.25 on Wed Jan 20 13:08:37 2016
//
//
// Buffer Definitions: 
//
// cbuffer cPSScene
// {
//
//   struct PSScene
//   {
//       
//       float4x4 m_projectionView;     // Offset:    0
//       float4x4 m_projection;         // Offset:   64
//       float4x4 m_view;               // Offset:  128
//       float4x4 m_shadowProjection;   // Offset:  192
//       float4x4 m_shadowProjection2;  // Offset:  256
//       float4 m_eyepos;               // Offset:  320
//       float4 m_projectionParam;      // Offset:  336
//       float4 m_viewportSize;         // Offset:  352
//       float4 m_exposure;             // Offset:  368
//       float4 m_fogParam[3];          // Offset:  384
//       float4 m_fogColor;             // Offset:  432
//       float4 m_cameraCenterOffset;   // Offset:  448
//       float4 m_shadowMapResolutions; // Offset:  464
//
//   } g_psScene;                       // Offset:    0 Size:   480
//
// }
//
// cbuffer cPSObject
// {
//
//   struct PSObject
//   {
//       
//       float4x4 m_viewWorld;          // Offset:    0
//       float4x4 m_world;              // Offset:   64
//       float4 m_useWeightCount;       // Offset:  128
//       float4 m_localParam[4];        // Offset:  144
//
//   } g_psObject;                      // Offset:    0 Size:   208
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_samplerPoint_Wrap               sampler      NA          NA    8        1
// inImage                           texture  float4          2d    0        1
// cPSScene                          cbuffer      NA          NA    2        1
// cPSObject                         cbuffer      NA          NA    5        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float       
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb2[23], immediateIndexed
dcl_constantbuffer cb5[10], immediateIndexed
dcl_sampler s8, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xyzw
dcl_output o0.xyzw
dcl_temps 5
mad r0.xyzw, v1.zwzw, l(-2.000000, -0.000000, 1.000000, 0.000000), v1.xyxy
max r0.xyzw, r0.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
min r0.xyzw, r0.xyzw, cb5[9].zwzw
sample_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.xyxx, t0.wxyz, s8
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.zwzz, t0.xyzw, s8
dp3 r2.x, r1.yzwy, l(0.996093750, 0.00389099121, 0.0000151991844, 0.000000)
mul r2.x, r2.x, cb2[22].w
mad r3.xyzw, v1.zwzw, l(-1.000000, -0.000000, 2.000000, 0.000000), v1.xyxy
max r3.xyzw, r3.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
min r3.xyzw, r3.xyzw, cb5[9].zwzw
sample_indexable(texture2d)(float,float,float,float) r4.xyzw, r3.xyxx, t0.xyzw, s8
sample_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.zwzz, t0.xyzw, s8
dp3 r4.x, r4.xyzx, l(0.996093750, 0.00389099121, 0.0000151991844, 0.000000)
mov r1.y, r4.w
mul r2.y, r4.x, cb2[22].w
dp3 r0.x, r0.xyzx, l(0.996093750, 0.00389099121, 0.0000151991844, 0.000000)
mov r1.z, r0.w
mul r2.z, r0.x, cb2[22].w
dp3 r0.x, r3.xyzx, l(0.996093750, 0.00389099121, 0.0000151991844, 0.000000)
mov r1.w, r3.w
mul r2.w, r0.x, cb2[22].w
max r0.xy, v1.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
min r0.xy, r0.xyxx, cb5[9].zwzz
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, r0.xyxx, t0.xyzw, s8
dp3 r3.x, r0.xyzx, l(0.996093750, 0.00389099121, 0.0000151991844, 0.000000)
mad r2.xyzw, -r3.xxxx, cb2[22].wwww, r2.xyzw
add r2.xyzw, |r2.xyzw|, l(1.000000, 1.000000, 1.000000, 1.000000)
div r2.xyzw, l(0.067000, 0.242000, 0.242000, 0.067000), r2.xyzw
dp4 r1.x, r1.xyzw, r2.xyzw
mad r0.w, r0.w, l(0.383000), r1.x
mov o0.xyz, r0.xyzx
add r0.x, r2.y, r2.x
add r0.x, r2.z, r0.x
add r0.x, r2.w, r0.x
add r0.x, r0.x, l(0.383000)
div o0.w, r0.w, r0.x
ret 
// Approximately 37 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
