//water on screen depth

cbuffer SceneWideParameterConstantBuffer : register(b0)
{
  float4x4 ViewProjection : packoffset(c0);
  float4x4 ViewProjectionPrev : packoffset(c4);
  float4x4 View : packoffset(c8);
  float4x4 Projection : packoffset(c12);
  float4x4 ViewInverse : packoffset(c16);
  float4x4 ProjInverse : packoffset(c20);
  float3 EyePosition : packoffset(c24);
  float cameraNearTimesFar : packoffset(c24.w);
  float cameraFarMinusNear : packoffset(c25);
  float time : packoffset(c25.y);
  float2 cameraNearFar : packoffset(c25.z);
  float2 ViewportWidthHeight : packoffset(c26);
  float2 screenWidthHeightInv : packoffset(c26.z);
  float2 screenWidthHeight : packoffset(c27);
  float2 ProjectionJitter : packoffset(c27.z);
  float2 ProjectionJitterPrev : packoffset(c28);
  uint checkerBoardID : packoffset(c28.z);
  float m_pad : packoffset(c28.w);
  uint PointLightCount : packoffset(c29);
  uint SpotLightCount : packoffset(c29.y);
  uint FoliageSpheresCount : packoffset(c29.z);
  uint m_padExtra : packoffset(c29.w);
  float4 FogParameters0 : packoffset(c30);
  float4 FogParameters1 : packoffset(c31);
  float4 FogParameters2 : packoffset(c32);
  float4 FogParameters3 : packoffset(c33);
  float4 FogPlanes : packoffset(c34);
  float3 CubeSunDir : packoffset(c35);
  float CamExposure : packoffset(c35.w);
  float3 CubeSunColor : packoffset(c36);
  float padding1 : packoffset(c36.w);
  float2 WindDirection : packoffset(c37);
  float2 CubeFadeValues : packoffset(c37.z);
}

SamplerState PointClampSampler_s : register(s0);
Texture2D<float> SourceBuffer : register(t0);


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


void main(
  float4 v0 : SV_POSITION0,
  out float o0 : SV_TARGET0)
{
  const float4 icb[] = { { 0.0133037297, 0, 0, 0},
                              { 0.110981643, 0, 0, 0},
                              { 0.225083515, 0, 0, 0},
                              { 0.110981643, 0, 0, 0},
                              { 0.0133037297, 0, 0, 0} };
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v0.xy / ViewportWidthHeight.xy;
  r1.xyzw = SourceBuffer.SampleLevel(PointClampSampler_s, r0.xy, 0).xyzw;
  r0.z = cmp(r1.x >= 0.100000001);
  if (r0.z != 0) {
    r2.xyzw = float4(1,1,1,1) / ViewportWidthHeight.xyxy;
    r0.z = 0.225083515 * r1.x;
    r0.xy = -r2.zw * float2(2,0) + r0.xy;
    r1.yz = r0.xy;
    r3.x = 0.225083515;
    r3.y = r0.z;
    r0.w = -2;
    while (true) {
      r1.w = cmp(2 < (int)r0.w);
      if (r1.w != 0) break;
      if (r0.w != 0) {
        r4.xyzw = SourceBuffer.SampleLevel(PointClampSampler_s, r1.yz, 0).xyzw;
        r1.w = r4.x + -r1.x;
        r1.w = 4 * r1.w;
        r1.w = -r1.w * r1.w;
        r1.w = 1.44269502 * r1.w;
        r1.w = exp2(r1.w);
        r1.w = saturate(-0.100000001 + r1.w);
        r2.z = max((int)r0.w, (int)-r0.w);
        r2.w = icb[r2.z+0].x * r1.w;
        r3.y = r4.x * r2.w + r3.y;
        r3.x = icb[r2.z+0].x * r1.w + r3.x;
      }
      r1.yz = r2.xy * float2(1,0) + r1.yz;
      r0.w = (int)r0.w + 1;
    }
    o0.x = r3.y / r3.x;
  } else {
    o0.x = r1.x;
  }
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.11 on Sun Jun 24 20:04:40 2018
//
//
// Buffer Definitions:
//
// cbuffer SceneWideParameterConstantBuffer
// {
//
//   float4x4 ViewProjection;           // Offset:    0 Size:    64 [unused]
//   float4x4 ViewProjectionPrev;       // Offset:   64 Size:    64 [unused]
//   float4x4 View;                     // Offset:  128 Size:    64 [unused]
//   float4x4 Projection;               // Offset:  192 Size:    64 [unused]
//   float4x4 ViewInverse;              // Offset:  256 Size:    64 [unused]
//   float4x4 ProjInverse;              // Offset:  320 Size:    64 [unused]
//   float3 EyePosition;                // Offset:  384 Size:    12 [unused]
//   float cameraNearTimesFar;          // Offset:  396 Size:     4 [unused]
//   float cameraFarMinusNear;          // Offset:  400 Size:     4 [unused]
//   float time;                        // Offset:  404 Size:     4 [unused]
//   float2 cameraNearFar;              // Offset:  408 Size:     8 [unused]
//   float2 ViewportWidthHeight;        // Offset:  416 Size:     8
//   float2 screenWidthHeightInv;       // Offset:  424 Size:     8 [unused]
//   float2 screenWidthHeight;          // Offset:  432 Size:     8 [unused]
//   float2 ProjectionJitter;           // Offset:  440 Size:     8 [unused]
//   float2 ProjectionJitterPrev;       // Offset:  448 Size:     8 [unused]
//   uint checkerBoardID;               // Offset:  456 Size:     4 [unused]
//   float m_pad;                       // Offset:  460 Size:     4 [unused]
//   uint PointLightCount;              // Offset:  464 Size:     4 [unused]
//   uint SpotLightCount;               // Offset:  468 Size:     4 [unused]
//   uint FoliageSpheresCount;          // Offset:  472 Size:     4 [unused]
//   uint m_padExtra;                   // Offset:  476 Size:     4 [unused]
//   float4 FogParameters0;             // Offset:  480 Size:    16 [unused]
//   float4 FogParameters1;             // Offset:  496 Size:    16 [unused]
//   float4 FogParameters2;             // Offset:  512 Size:    16 [unused]
//   float4 FogParameters3;             // Offset:  528 Size:    16 [unused]
//   float4 FogPlanes;                  // Offset:  544 Size:    16 [unused]
//   float3 CubeSunDir;                 // Offset:  560 Size:    12 [unused]
//   float CamExposure;                 // Offset:  572 Size:     4 [unused]
//   float3 CubeSunColor;               // Offset:  576 Size:    12 [unused]
//   float padding1;                    // Offset:  588 Size:     4 [unused]
//   float2 WindDirection;              // Offset:  592 Size:     8 [unused]
//   float2 CubeFadeValues;             // Offset:  600 Size:     8 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// PointClampSampler                 sampler      NA          NA    0        1
// SourceBuffer                      texture   float          2d    0        1
// SceneWideParameterConstantBuffer    cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   x           0   TARGET   float   x
//
ps_4_0
dcl_immediateConstantBuffer { { 0.0133037297, 0, 0, 0},
                              { 0.110981643, 0, 0, 0},
                              { 0.225083515, 0, 0, 0},
                              { 0.110981643, 0, 0, 0},
                              { 0.0133037297, 0, 0, 0} }
dcl_constantbuffer cb0[27], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.x
dcl_temps 5
div r0.xy, v0.xyxx, cb0[26].xyxx
sample_l r1.xyzw, r0.xyxx, t0.xyzw, s0, l(0.000000)
ge r0.z, r1.x, l(0.100000)
if_nz r0.z
  div r2.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000), cb0[26].xyxy
  mul r0.z, r1.x, l(0.225083515)
  mad r0.xy, -r2.zwzz, l(2.000000, 0.000000, 0.000000, 0.000000), r0.xyxx
  mov r1.yz, r0.xxyx
  mov r3.x, l(0.225083515)
  mov r3.y, r0.z
  mov r0.w, l(-2)
  loop
    ilt r1.w, l(2), r0.w
    breakc_nz r1.w
    if_nz r0.w
      sample_l r4.xyzw, r1.yzyy, t0.xyzw, s0, l(0.000000)
      add r1.w, -r1.x, r4.x
      mul r1.w, r1.w, l(4.000000)
      mul r1.w, r1.w, -r1.w
      mul r1.w, r1.w, l(1.442695)
      exp r1.w, r1.w
      add_sat r1.w, r1.w, l(-0.100000)
      imax r2.z, -r0.w, r0.w
      mul r2.w, r1.w, icb[r2.z + 0].x
      mad r3.y, r4.x, r2.w, r3.y
      mad r3.x, icb[r2.z + 0].x, r1.w, r3.x
    endif
    mad r1.yz, r2.xxyx, l(0.000000, 1.000000, 0.000000, 0.000000), r1.yyzy
    iadd r0.w, r0.w, l(1)
  endloop
  div o0.x, r3.y, r3.x
else
  mov o0.x, r1.x
endif
ret
// Approximately 35 instruction slots used

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