//waterfall-- vpos
// ---- Created with 3Dmigoto v1.2.39 on Mon Jun 20 11:07:16 2016

cbuffer VSOffsetConstants : register(b1)
{
  float4x4 ViewProjectionMatrix : packoffset(c0);
  float4 CameraPositionVS : packoffset(c4);
  float4 PreViewTranslation : packoffset(c5);
}

cbuffer PSOffsetConstants : register(b2)
{
  float4 ScreenPositionScaleBias : packoffset(c0);
  float4 MinZ_MaxZRatio : packoffset(c1);
  float NvStereoEnabled : packoffset(c2);
  float4 DiffuseOverrideParameter : packoffset(c3);
  float4 SpecularOverrideParameter : packoffset(c4);
  float4 CameraPositionPS : packoffset(c5);
  float4 ScreenAndTexelSize : packoffset(c6);
}

SamplerState SceneDepthTextureSampler_s : register(s0);
SamplerState PixelTexture2D_1Sampler_s : register(s1);
Texture2D<float4> SceneDepthTexture : register(t0);
Texture2D<float4> PixelTexture2D_1 : register(t1);


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


void main( 
  float4 v0 : TEXCOORD10,
  float4 v1 : TEXCOORD11,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD1,
  float4 v4 : TEXCOORD5,
  float4 v5 : TEXCOORD6,
  float4 v9 : SV_POSITION0,
  //uint v6 : SV_IsFrontFace0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r20;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = float2(0.5,1) * v2.xy;
  r0.x = PixelTexture2D_1.SampleBias(PixelTexture2D_1Sampler_s, r0.xy, 0).x;
  r0.x = r0.x * 2 + -1;
  r0.x = 5 * r0.x;
  r0.x = v3.z * -r0.x + r0.x;
  r0.y = dot(r0.xx, r0.xx);
  r0.y = -0.100000001 + r0.y;
  r0.y = cmp(r0.y < 0);
  if (r0.y != 0) discard;
  r0.yzw = ViewProjectionMatrix._m01_m11_m31 * v4.yyy;
  r0.yzw = ViewProjectionMatrix._m00_m10_m30 * v4.xxx + r0.yzw;
  r0.yzw = ViewProjectionMatrix._m02_m12_m32 * v4.zzz + r0.yzw;
  r0.yzw = ViewProjectionMatrix._m03_m13_m33 * v4.www + r0.yzw;

//float4 stereo = StereoParams.Load(0);
//r0.y += stereo.x*(r0.w - stereo.y);

  r0.yz = r0.yz / r0.ww;
  r0.yz = r0.yz * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
  r0.yz = r0.xx * float2(0.00392156886,-0.00392156886) + r0.yz;
  r0.x = 4 * r0.x;
  r0.x = max(-255, r0.x);
  r0.x = min(255, r0.x);
  r0.x = 0.00392156886 * r0.x;

float4 res = IniParams.Load(int2(1, 0));
r20.xy = ((1 / res.xy) * v1.xy) + (0.5 / res.xy);

  r0.y = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r20.xy, 0).x;
  r0.y = min(0.999000013, r0.y);
  r0.y = r0.y * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r0.y = 1 / r0.y;
  r0.y = cmp(r0.w >= r0.y);
  r0.x = r0.y ? 0 : r0.x;
  o0.xy = max(float2(0,0), r0.xx);
  r0.x = min(0, r0.x);
  o0.zw = -r0.xx;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Mon Jun 20 11:07:16 2016
//
//
// Buffer Definitions: 
//
// cbuffer VSOffsetConstants
// {
//
//   float4x4 ViewProjectionMatrix;     // Offset:    0 Size:    64
//   float4 CameraPositionVS;           // Offset:   64 Size:    16 [unused]
//   float4 PreViewTranslation;         // Offset:   80 Size:    16 [unused]
//
// }
//
// cbuffer PSOffsetConstants
// {
//
//   float4 ScreenPositionScaleBias;    // Offset:    0 Size:    16
//   float4 MinZ_MaxZRatio;             // Offset:   16 Size:    16
//   float NvStereoEnabled;             // Offset:   32 Size:     4 [unused]
//   float4 DiffuseOverrideParameter;   // Offset:   48 Size:    16 [unused]
//   float4 SpecularOverrideParameter;  // Offset:   64 Size:    16 [unused]
//   float4 CameraPositionPS;           // Offset:   80 Size:    16 [unused]
//   float4 ScreenAndTexelSize;         // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SceneDepthTextureSampler          sampler      NA          NA    0        1
// PixelTexture2D_1Sampler           sampler      NA          NA    1        1
// SceneDepthTexture                 texture  float4          2d    0        1
// PixelTexture2D_1                  texture  float4          2d    1        1
// VSOffsetConstants                 cbuffer      NA          NA    1        1
// PSOffsetConstants                 cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                10   xyzw        0     NONE   float       
// TEXCOORD                11   xyzw        1     NONE   float       
// TEXCOORD                 0   xy          2     NONE   float   xy  
// TEXCOORD                 1   xyzw        3     NONE   float     z 
// TEXCOORD                 5   xyzw        4     NONE   float   xyzw
// TEXCOORD                 6   xyzw        5     NONE   float       
// SV_IsFrontFace           0   x           6    FFACE    uint       
//
//
// 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 cb1[4], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v2.xy
dcl_input_ps linear v3.z
dcl_input_ps linear v4.xyzw
dcl_output o0.xyzw
dcl_temps 1
mul r0.xy, v2.xyxx, l(0.500000, 1.000000, 0.000000, 0.000000)
sample_b_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t1.xyzw, s1, l(0.000000)
mad r0.x, r0.x, l(2.000000), l(-1.000000)
mul r0.x, r0.x, l(5.000000)
mad r0.x, v3.z, -r0.x, r0.x
dp2 r0.y, r0.xxxx, r0.xxxx
add r0.y, r0.y, l(-0.100000)
lt r0.y, r0.y, l(0.000000)
discard_nz r0.y
mul r0.yzw, v4.yyyy, cb1[1].xxyw
mad r0.yzw, cb1[0].xxyw, v4.xxxx, r0.yyzw
mad r0.yzw, cb1[2].xxyw, v4.zzzz, r0.yyzw
mad r0.yzw, cb1[3].xxyw, v4.wwww, r0.yyzw
div r0.yz, r0.yyzy, r0.wwww
mad r0.yz, r0.yyzy, cb2[0].xxyx, cb2[0].wwzw
mad r0.yz, r0.xxxx, l(0.000000, 0.00392156886, -0.00392156886, 0.000000), r0.yyzy
mul r0.x, r0.x, l(4.000000)
max r0.x, r0.x, l(-255.000000)
min r0.x, r0.x, l(255.000000)
mul r0.x, r0.x, l(0.00392156886)
sample_l_indexable(texture2d)(float,float,float,float) r0.y, r0.yzyy, t0.yxzw, s0, l(0.000000)
min r0.y, r0.y, l(0.999000)
mad r0.y, r0.y, cb2[1].z, -cb2[1].w
div r0.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.y
ge r0.y, r0.w, r0.y
movc r0.x, r0.y, l(0), r0.x
max o0.xy, r0.xxxx, l(0.000000, 0.000000, 0.000000, 0.000000)
min r0.x, r0.x, l(0.000000)
mov o0.zw, -r0.xxxx
ret 
// Approximately 30 instruction slots used

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