// SSAO DEPTH calculation - BREAKS some cutscenes

cbuffer cbSampleOffset : register(b1)
{
  float4 g_avSampleOffsets[16] : packoffset(c0);
}

SamplerState SS_ClampPoint_s : register(s2);
Texture2D<float4> g_DepthTex : register(t1);


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


void main(
  float4 v0 : SV_Position0,
  float2 v1 : TEXCOORD0,
  out float oDepth : SV_Depth)
{
  float4 r0;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 iniParams = IniParams.Load(0);
  if(iniParams.y == 0)
   discard;

  r0.xy = g_avSampleOffsets[0].xy + v1.xy;
  r0.x = g_DepthTex.SampleLevel(SS_ClampPoint_s, r0.xy, 0).x;
  r0.yz = g_avSampleOffsets[1].xy + v1.xy;
  r0.y = g_DepthTex.SampleLevel(SS_ClampPoint_s, r0.yz, 0).x;
  r0.x = max(r0.x, r0.y);
  r0.yz = g_avSampleOffsets[2].xy + v1.xy;
  r0.y = g_DepthTex.SampleLevel(SS_ClampPoint_s, r0.yz, 0).x;
  r0.x = max(r0.x, r0.y);
  r0.yz = g_avSampleOffsets[3].xy + v1.xy;
  r0.y = g_DepthTex.SampleLevel(SS_ClampPoint_s, r0.yz, 0).x;
  oDepth = max(r0.x, r0.y);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//   using 3Dmigoto v1.3.16 on Thu Mar 28 21:45:15 2019
//
//
// Buffer Definitions:
//
// cbuffer cbSampleOffset
// {
//
//   float4 g_avSampleOffsets[16];      // Offset:    0 Size:   256
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SS_ClampPoint                     sampler      NA          NA    2        1
// g_DepthTex                        texture  float4          2d    1        1
// cbSampleOffset                    cbuffer      NA          NA    1        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xy          1     NONE   float   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Depth                 0    N/A   oDepth    DEPTH   float    YES
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb1[4], immediateIndexed
dcl_sampler s2, mode_default
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v1.xy
dcl_output oDepth
dcl_temps 1
add r0.xy, v1.xyxx, cb1[0].xyxx
sample_l_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t1.xyzw, s2, l(0.000000)
add r0.yz, v1.xxyx, cb1[1].xxyx
sample_l_indexable(texture2d)(float,float,float,float) r0.y, r0.yzyy, t1.yxzw, s2, l(0.000000)
max r0.x, r0.y, r0.x
add r0.yz, v1.xxyx, cb1[2].xxyx
sample_l_indexable(texture2d)(float,float,float,float) r0.y, r0.yzyy, t1.yxzw, s2, l(0.000000)
max r0.x, r0.y, r0.x
add r0.yz, v1.xxyx, cb1[3].xxyx
sample_l_indexable(texture2d)(float,float,float,float) r0.y, r0.yzyy, t1.yxzw, s2, l(0.000000)
max oDepth, r0.y, r0.x
ret
// Approximately 12 instruction slots used

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