// Water REflections
Texture2D<float4> t1 : register(t1);

Texture2D<float4> t0 : register(t0);

SamplerState s1_s : register(s1);

SamplerState s0_s : register(s0);

cbuffer cb3 : register(b3)
{
  float4 cb3[11];
}

cbuffer cb2 : register(b2)
{
  float4 cb2[10];
}

cbuffer cb1 : register(b1)
{
  float4 cb1[40];
}

cbuffer cb0 : register(b0)
{
  float4 cb0[61];
}




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

void main( 
  float4 v0 : TEXCOORD10,
  float4 v1 : TEXCOORD11,
  float4 v2 : TEXCOORD0,
  float4 v3 : TEXCOORD1,
  float4 v4 : VELOCITY_PREV_POS0,
  float4 v5 : SV_Position0,
  uint v6 : SV_IsFrontFace0,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1,
  out float4 o2 : SV_Target2,
  out float4 o3 : SV_Target3,
  out float4 o4 : SV_Target4,
  out float4 o5 : SV_Target5)
{
  float4 r0,r1,r2,r3;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = -cb1[1].xy + v5.xy;
  r0.xy = r0.xy * cb1[2].zw + float2(-0.5,-0.5);
  r0.xy = v5.ww * r0.xy;
  
  float4 stereo = StereoParams.Load(0);
  r0.x += stereo.x * (-v5.w + stereo.y) / 2;
  
  r0.z = v5.w;
  r0.xyz = float3(2,-2,1) * r0.xyz;
  r0.xy = r0.xy / r0.zz;
  
  
  
  r0.zw = r0.xy * cb0[53].xy + cb0[53].wz;
  r1.xy = cb1[3].zw * cb1[2].xy;
  r0.zw = r0.zw / r1.xy;
  r1.y = cb1[2].y / cb1[2].x;
  r1.xz = float2(-1,0);
  r2.x = 1 + -r1.y;
  r1.w = 0.5 * r2.x;
  r0.zw = r0.zw * r1.xy + r1.zw;
  r1.xyz = t0.Sample(s0_s, r0.zw).xyz;
  r0.z = t1.Sample(s1_s, v3.xy).y;
  r0.z = max(9.99999997e-007, abs(r0.z));
  r0.z = r0.z * r0.z;
  r0.z = 0.600000024 * r0.z;
  r0.z = max(9.99999997e-007, r0.z);
  r0.z = log2(r0.z);
  r0.z = cb3[9].w * r0.z;
  r0.z = exp2(r0.z);
  r0.zw = cmp(r0.zz < float2(0.449999988,0.5));
  r2.xyz = cb3[10].xxx * cb3[5].xyz;
  r2.xyz = r0.zzz ? float3(0,0,0) : r2.xyz;
  r2.xyz = r0.www ? r2.xyz : 0;
  r1.xyz = r2.xyz + r1.xyz;
  r1.xyz = cb3[6].xyz + r1.xyz;
  if (r0.z != 0) discard;
  r0.xy = -cb0[27].xy + r0.xy;
  r0.zw = v4.xy / v4.ww;
  r0.zw = -cb0[60].xy + r0.zw;
  r0.xy = r0.xy + -r0.zw;
  r0.xy = r0.xy * float2(0.249500006,0.249500006) + float2(0.499992371,0.499992371);
  o4.xy = v4.zz * r0.xy;
  o4.zw = float2(0,0);
  r0.xyz = max(float3(0,0,0), r1.xyz);
  r0.w = cmp(0 < cb1[9].x);
  if (r0.w != 0) {
    r1.xyzw = cb0[38].xyzw * v5.yyyy;
    r1.xyzw = v5.xxxx * cb0[37].xyzw + r1.xyzw;
    r1.xyzw = v5.zzzz * cb0[39].xyzw + r1.xyzw;
    r1.xyzw = cb0[40].xyzw + r1.xyzw;
    r1.xyz = r1.xyz / r1.www;
	
// Common SVPositionToTranslatedWorld fix:
//matrix TranslatedWorldToClip = MATRIX(cb0, 1);
//matrix ClipToTranslatedWorld = MATRIX(cb0, 33);
//float4 tmp = mul(r1.xyz, TranslatedWorldToClip);
//tmp.x -= stereo.x * (tmp.w - stereo.y);
//r1.xyz = mul(tmp, ClipToTranslatedWorld);
	
    r1.xyz = -cb0[57].xyz + r1.xyz;
    r2.xyz = -cb2[8].xyz + r1.xyz;
    r3.xyz = float3(1,1,1) + cb2[9].xyz;
    r2.xyz = cmp(r3.xyz < abs(r2.xyz));
    r0.w = (int)r2.y | (int)r2.x;
    r0.w = (int)r2.z | (int)r0.w;
    r1.x = dot(r1.xyz, float3(0.577000022,0.577000022,0.577000022));
    r1.x = 0.00200000009 * r1.x;
    r1.x = frac(r1.x);
    r1.x = cmp(0.5 < r1.x);
    r1.xyz = r1.xxx ? float3(0,1,1) : float3(1,1,0);
    r0.xyz = r0.www ? r1.xyz : r0.xyz;
  }
  o0.xyz = r0.xyz;
  o0.w = 0;
  o1.xyzw = float4(0,0,0,0);
  o2.xyzw = float4(0,0,0,0);
  o3.xyzw = float4(0,0,0,0);
  o5.xyzw = float4(0,0,0,0);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.2.57 on Sat Jun 17 11:54:19 2017
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                10   xyzw        0     NONE   float       
// TEXCOORD                11   xyzw        1     NONE   float       
// TEXCOORD                 0   xyzw        2     NONE   float       
// TEXCOORD                 1   xyzw        3     NONE   float   xy  
// VELOCITY_PREV_POS        0   xyzw        4     NONE   float   xyzw
// SV_Position              0   xyzw        5      POS   float   xyzw
// SV_IsFrontFace           0   x           6    FFACE    uint       
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
// SV_Target                1   xyzw        1   TARGET   float   xyzw
// SV_Target                2   xyzw        2   TARGET   float   xyzw
// SV_Target                3   xyzw        3   TARGET   float   xyzw
// SV_Target                4   xyzw        4   TARGET   float   xyzw
// SV_Target                5   xyzw        5   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[61], immediateIndexed
dcl_constantbuffer cb1[10], immediateIndexed
dcl_constantbuffer cb2[10], immediateIndexed
dcl_constantbuffer cb3[11], 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 v3.xy
dcl_input_ps linear v4.xyzw
dcl_input_ps_siv linear noperspective v5.xyzw, position
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_output o2.xyzw
dcl_output o3.xyzw
dcl_output o4.xyzw
dcl_output o5.xyzw
dcl_temps 4
add r0.xy, v5.xyxx, -cb1[1].xyxx
mad r0.xy, r0.xyxx, cb1[2].zwzz, l(-0.500000, -0.500000, 0.000000, 0.000000)
mul r0.xy, r0.xyxx, v5.wwww
mov r0.z, v5.w
mul r0.xyz, r0.xyzx, l(2.000000, -2.000000, 1.000000, 0.000000)
div r0.xy, r0.xyxx, r0.zzzz
mad r0.zw, r0.xxxy, cb0[53].xxxy, cb0[53].wwwz
mul r1.xy, cb1[2].xyxx, cb1[3].zwzz
div r0.zw, r0.zzzw, r1.xxxy
div r1.y, cb1[2].y, cb1[2].x
mov r1.xz, l(-1.000000,0,0,0)
add r2.x, -r1.y, l(1.000000)
mul r1.w, r2.x, l(0.500000)
mad r0.zw, r0.zzzw, r1.xxxy, r1.zzzw
sample_indexable(texture2d)(float,float,float,float) r1.xyz, r0.zwzz, t0.xyzw, s0
sample_indexable(texture2d)(float,float,float,float) r0.z, v3.xyxx, t1.xzyw, s1
max r0.z, |r0.z|, l(0.000001)
mul r0.z, r0.z, r0.z
mul r0.z, r0.z, l(0.600000)
max r0.z, r0.z, l(0.000001)
log r0.z, r0.z
mul r0.z, r0.z, cb3[9].w
exp r0.z, r0.z
lt r0.zw, r0.zzzz, l(0.000000, 0.000000, 0.450000, 0.500000)
mul r2.xyz, cb3[5].xyzx, cb3[10].xxxx
movc r2.xyz, r0.zzzz, l(0,0,0,0), r2.xyzx
and r2.xyz, r0.wwww, r2.xyzx
add r1.xyz, r1.xyzx, r2.xyzx
add r1.xyz, r1.xyzx, cb3[6].xyzx
discard_nz r0.z
add r0.xy, r0.xyxx, -cb0[27].xyxx
div r0.zw, v4.xxxy, v4.wwww
add r0.zw, r0.zzzw, -cb0[60].xxxy
add r0.xy, -r0.zwzz, r0.xyxx
mad r0.xy, r0.xyxx, l(0.249500, 0.249500, 0.000000, 0.000000), l(0.499992371, 0.499992371, 0.000000, 0.000000)
mul o4.xy, r0.xyxx, v4.zzzz
mov o4.zw, l(0,0,0,0)
max r0.xyz, r1.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
lt r0.w, l(0.000000), cb1[9].x
if_nz r0.w
  mul r1.xyzw, v5.yyyy, cb0[38].xyzw
  mad r1.xyzw, v5.xxxx, cb0[37].xyzw, r1.xyzw
  mad r1.xyzw, v5.zzzz, cb0[39].xyzw, r1.xyzw
  add r1.xyzw, r1.xyzw, cb0[40].xyzw
  div r1.xyz, r1.xyzx, r1.wwww
  add r1.xyz, r1.xyzx, -cb0[57].xyzx
  add r2.xyz, r1.xyzx, -cb2[8].xyzx
  add r3.xyz, cb2[9].xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
  lt r2.xyz, r3.xyzx, |r2.xyzx|
  or r0.w, r2.y, r2.x
  or r0.w, r2.z, r0.w
  dp3 r1.x, r1.xyzx, l(0.577000, 0.577000, 0.577000, 0.000000)
  mul r1.x, r1.x, l(0.002000)
  frc r1.x, r1.x
  lt r1.x, l(0.500000), r1.x
  movc r1.xyz, r1.xxxx, l(0,1.000000,1.000000,0), l(1.000000,1.000000,0,0)
  movc r0.xyz, r0.wwww, r1.xyzx, r0.xyzx
endif 
mov o0.xyz, r0.xyzx
mov o0.w, l(0)
mov o1.xyzw, l(0,0,0,0)
mov o2.xyzw, l(0,0,0,0)
mov o3.xyzw, l(0,0,0,0)
mov o5.xyzw, l(0,0,0,0)
ret 
// Approximately 0 instruction slots used

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