// ---- Created with 3Dmigoto v1.2.35 on Tue Apr 26 22:30:27 2016

cbuffer cbPerScene : register(b0)
{
  float4x4 g_InvProjMatrix : packoffset(c0);
  float4x4 g_ProjMatrix : packoffset(c4);
  float4x4 g_ViewMatrix : packoffset(c8);
  float4x4 g_ReprojMatrix : packoffset(c12);
  float4 g_fadeParam : packoffset(c16);
  float4 g_vDepthComputeParam : packoffset(c17);
  float2 g_vScreenSize : packoffset(c18);
  float4 g_rayTraceParam : packoffset(c19);
}

SamplerState SS_WrapPoint_s : register(s6);
SamplerState SS_ClampPoint_s : register(s7);
SamplerState SS_ClampLinear_s : register(s9);
Texture2D<float4> g_LightPrepassAttrTexture : register(t0);
Texture2D<float4> g_DepthTexture : register(t1);
Texture2D<float4> g_GBuffer1Texture : register(t3);
Texture2D<float4> g_GBuffer3Texture : register(t5);
Texture2D<float4> g_PrevFrameTexture : register(t11);


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


void main( 
  float4 v0 : SV_POSITION0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD1,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.w = g_DepthTexture.Sample(SS_ClampPoint_s, v1.xy).x;
  r1.x = cmp(r0.w >= 1);
  r1.yz = v2.xy * float2(0.5,-0.5) + float2(0.5,0.5);
  r2.xy = ddx_coarse(r1.yz);
  r2.zw = ddy_coarse(r1.yz);
  if (r1.x != 0) {
    o0.xyzw = float4(0,0,0,0);
    return;
  }
  r0.xy = v2.xy;
  r0.z = 1;
  r3.x = dot(r0.xywz, g_InvProjMatrix._m00_m10_m20_m30);
  r3.y = dot(r0.xywz, g_InvProjMatrix._m01_m11_m21_m31);
  r3.z = dot(r0.xywz, g_InvProjMatrix._m02_m12_m22_m32);
  r1.x = dot(r0.xywz, g_InvProjMatrix._m03_m13_m23_m33);
  r3.xyz = r3.xyz / r1.xxx;
  r1.x = dot(r3.xyz, r3.xyz);
  r1.x = rsqrt(r1.x);
  r4.xyz = r3.xyz * r1.xxx;
  r5.xyz = g_LightPrepassAttrTexture.Sample(SS_WrapPoint_s, v1.xy).xyz;
  r5.xyz = r5.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r1.x = dot(r5.xyz, r5.xyz);
  r1.x = rsqrt(r1.x);
  r5.xyz = r5.xyz * r1.xxx;
  r6.x = dot(r5.xyz, g_ViewMatrix._m00_m10_m20);
  r6.y = dot(r5.xyz, g_ViewMatrix._m01_m11_m21);
  r6.z = dot(r5.xyz, g_ViewMatrix._m02_m12_m22);
  r1.x = dot(r4.xyz, r6.xyz);
  r1.x = r1.x + r1.x;
  r6.xyz = r6.xyz * -r1.xxx + r4.xyz;
  r1.x = dot(r6.xyz, r6.xyz);
  r1.x = rsqrt(r1.x);
  r1.w = r6.z * r1.x;
  r1.w = cmp(r1.w < g_fadeParam.x);
  if (r1.w != 0) {
    o0.xyzw = float4(0,0,0,0);
    return;
  }
  r7.x = dot(-r4.xyz, g_ViewMatrix._m00_m10_m20);
  r7.y = dot(-r4.xyz, g_ViewMatrix._m01_m11_m21);
  r7.z = dot(-r4.xyz, g_ViewMatrix._m02_m12_m22);
  r4.xyz = g_GBuffer3Texture.Sample(SS_ClampPoint_s, v1.xy).xyz;
  r8.xyz = r4.xyz * r4.xyz;
  r1.w = g_GBuffer1Texture.Sample(SS_ClampPoint_s, v1.xy).x;
  r3.w = saturate(dot(r7.xyz, r5.xyz));
  r3.w = 1 + -r3.w;
  r4.w = r3.w * r3.w;
  r4.w = r4.w * r4.w;
  r3.w = r4.w * r3.w;
  r4.xyz = -r4.xyz * r4.xyz + float3(1,1,1);
  r4.xyz = r4.xyz * r3.www;
  r1.w = r1.w * r1.w;
  r4.xyz = r4.xyz * r1.www + r8.xyz;
  r1.w = saturate(r6.z * r1.x + -g_fadeParam.x);
  r1.w = r1.w * r1.w;
  r3.xyz = r6.xyz * r1.xxx + r3.xyz;
  r1.x = cmp(0 < r3.z);
  r3.w = 1;
  r5.y = dot(r3.xyzw, g_ProjMatrix._m00_m10_m20_m30);
  r5.z = dot(r3.xyzw, g_ProjMatrix._m01_m11_m21_m31);
  r5.w = dot(r3.xyzw, g_ProjMatrix._m02_m12_m22_m32);
  r3.xyz = r5.yzw / r3.zzz;
  r3.xyz = r1.xxx ? r3.xyz : r0.xyw;
  r3.xyz = r3.xyz + -r0.xyw;
  r0.x = dot(r3.xyz, r3.xyz);
  r0.x = rsqrt(r0.x);
  r3.xyz = r3.xyz * r0.xxx;
  r3.xyz = float3(0.5,-0.5,1) * r3.xyz;
  r0.x = dot(r3.xyz, r3.xyz);
  r0.x = rsqrt(r0.x);
  r3.xyz = r3.xyz * r0.xxx;
  r0.x = dot(r3.xy, r3.xy);
  r0.x = sqrt(r0.x);
  r0.x = g_vScreenSize.x * r0.x;
  r1.x = cmp(0 < r0.x);
  r5.xyz = r3.xyz / r0.xxx;
  r3.xyz = r1.xxx ? r5.xyz : r3.xyz;
  r3.xyz = r3.xyz * g_rayTraceParam.www + r3.xyz;
  r5.x = (int)g_vScreenSize.x;
  r0.yz = v2.xy * float2(0.5,-0.5) + float2(0.5,0.5);
  r6.xyz = r0.yzw + r3.xyz;
  r0.x = g_rayTraceParam.y * r3.z;
  r0.x = max(g_rayTraceParam.x, r0.x);
  r1.x = cmp(9.99999975e-006 < abs(r3.z));
  r1.yz = float2(0.5,0.5) + -r1.yz;
  r1.y = dot(r1.yz, r1.yz);
  r1.y = sqrt(r1.y);
  r1.y = r1.y + r1.y;
  r1.y = min(1, r1.y);
  r1.y = -r1.y * r1.y + 1;
  r1.y = min(r1.w, r1.y);
  r7.w = 1;
  r5.yzw = float3(0.99000001,0.99000001,0.99000001);
  r8.xyz = float3(0,0,0);
  r1.w = 0;
  r9.z = 0;
  r9.xyw = r6.xyz;
  while (true) {
    r1.z = cmp((int)r9.z >= (int)r5.x);
    if (r1.z != 0) break;
    r7.z = g_DepthTexture.SampleGrad(SS_ClampPoint_s, r9.xy, r2.x, r2.z).x;
    r1.z = r9.w + -r7.z;
    r3.w = cmp(r1.z >= 0);
    r4.w = cmp(r1.z < r0.x);
    r3.w = r3.w ? r4.w : 0;
    if (r3.w != 0) {
      r1.z = r1.z / r3.z;
      r10.xy = r1.zz * r3.xy + r9.xy;
      r9.xy = r1.xx ? r10.xy : r9.xy;
      r7.xy = r9.xy * float2(2,-2) + float2(-1,1);
      r10.x = dot(r7.xyzw, g_ReprojMatrix._m00_m10_m20_m30);
      r10.y = dot(r7.xyzw, g_ReprojMatrix._m01_m11_m21_m31);
      r1.z = dot(r7.xyzw, g_ReprojMatrix._m03_m13_m23_m33);
      r7.xy = r10.xy / r1.zz;
      r7.xy = r7.xy * float2(0.5,-0.5) + float2(0.5,0.5);
      r8.xyz = g_PrevFrameTexture.SampleGrad(SS_ClampLinear_s, r7.xy, r2.xyx, r2.zwz).xyz;
      r1.w = r1.y;
      r9.z = r5.x;
    } else {
      r1.z = (int)r9.z + 1;
      r3.w = (int)r1.z;
      r10.yzw = r3.xyz * r3.www + r0.yzw;
      r3.w = cmp(r10.w >= 1);
      r4.w = g_vDepthComputeParam.x + -r10.w;
      r4.w = -g_vDepthComputeParam.y / r4.w;
      r4.w = cmp(g_rayTraceParam.z < r4.w);
      r7.xy = cmp(r10.yz < float2(0,0));
      r11.xy = cmp(float2(1,1) < r10.yz);
      r6.w = (int)r7.x | (int)r11.x;
      r6.w = (int)r7.y | (int)r6.w;
      r6.w = (int)r11.y | (int)r6.w;
      r4.w = (int)r4.w | (int)r6.w;
      r10.x = r4.w ? r5.x : r1.z;
      r9.xyzw = r3.wwww ? r5.yzxw : r10.yzxw;
    }
  }
  r0.xyz = r8.xyz * r4.xyz;
  o0.xyz = r0.xyz * r1.www;
  o0.w = r1.w;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//
// Buffer Definitions: 
//
// cbuffer cbPerScene
// {
//
//   float4x4 g_InvProjMatrix;          // Offset:    0 Size:    64
//   float4x4 g_ProjMatrix;             // Offset:   64 Size:    64
//   float4x4 g_ViewMatrix;             // Offset:  128 Size:    64
//   float4x4 g_ReprojMatrix;           // Offset:  192 Size:    64
//   float4 g_fadeParam;                // Offset:  256 Size:    16
//   float4 g_vDepthComputeParam;       // Offset:  272 Size:    16
//   float2 g_vScreenSize;              // Offset:  288 Size:     8
//   float4 g_rayTraceParam;            // Offset:  304 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SS_WrapPoint                      sampler      NA          NA    6        1
// SS_ClampPoint                     sampler      NA          NA    7        1
// SS_ClampLinear                    sampler      NA          NA    9        1
// g_LightPrepassAttrTexture         texture  float4          2d    0        1
// g_DepthTexture                    texture  float4          2d    1        1
// g_GBuffer1Texture                 texture  float4          2d    3        1
// g_GBuffer3Texture                 texture  float4          2d    5        1
// g_PrevFrameTexture                texture  float4          2d   11        1
// cbPerScene                        cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xy          1     NONE   float   xy  
// TEXCOORD                 1   xyzw        2     NONE   float   xy  
//
//
// 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 cb0[20], immediateIndexed
dcl_sampler s6, mode_default
dcl_sampler s7, mode_default
dcl_sampler s9, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t5
dcl_resource_texture2d (float,float,float,float) t11
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 12
sample_indexable(texture2d)(float,float,float,float) r0.w, v1.xyxx, t1.yzwx, s7
ge r1.x, r0.w, l(1.000000)
mad r1.yz, v2.xxyx, l(0.000000, 0.500000, -0.500000, 0.000000), l(0.000000, 0.500000, 0.500000, 0.000000)
deriv_rtx_coarse r2.xy, r1.yzyy
deriv_rty_coarse r2.zw, r1.yyyz
if_nz r1.x
  mov o0.xyzw, l(0,0,0,0)
  ret 
endif 
mov r0.xy, v2.xyxx
mov r0.z, l(1.000000)
dp4 r3.x, r0.xywz, cb0[0].xyzw
dp4 r3.y, r0.xywz, cb0[1].xyzw
dp4 r3.z, r0.xywz, cb0[2].xyzw
dp4 r1.x, r0.xywz, cb0[3].xyzw
div r3.xyz, r3.xyzx, r1.xxxx
dp3 r1.x, r3.xyzx, r3.xyzx
rsq r1.x, r1.x
mul r4.xyz, r1.xxxx, r3.xyzx
sample_indexable(texture2d)(float,float,float,float) r5.xyz, v1.xyxx, t0.xyzw, s6
mad r5.xyz, r5.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r1.x, r5.xyzx, r5.xyzx
rsq r1.x, r1.x
mul r5.xyz, r1.xxxx, r5.xyzx
dp3 r6.x, r5.xyzx, cb0[8].xyzx
dp3 r6.y, r5.xyzx, cb0[9].xyzx
dp3 r6.z, r5.xyzx, cb0[10].xyzx
dp3 r1.x, r4.xyzx, r6.xyzx
add r1.x, r1.x, r1.x
mad r6.xyz, r6.xyzx, -r1.xxxx, r4.xyzx
dp3 r1.x, r6.xyzx, r6.xyzx
rsq r1.x, r1.x
mul r1.w, r1.x, r6.z
lt r1.w, r1.w, cb0[16].x
if_nz r1.w
  mov o0.xyzw, l(0,0,0,0)
  ret 
endif 
dp3 r7.x, -r4.xyzx, cb0[8].xyzx
dp3 r7.y, -r4.xyzx, cb0[9].xyzx
dp3 r7.z, -r4.xyzx, cb0[10].xyzx
sample_indexable(texture2d)(float,float,float,float) r4.xyz, v1.xyxx, t5.xyzw, s7
mul r8.xyz, r4.xyzx, r4.xyzx
sample_indexable(texture2d)(float,float,float,float) r1.w, v1.xyxx, t3.yzwx, s7
dp3_sat r3.w, r7.xyzx, r5.xyzx
add r3.w, -r3.w, l(1.000000)
mul r4.w, r3.w, r3.w
mul r4.w, r4.w, r4.w
mul r3.w, r3.w, r4.w
mad r4.xyz, -r4.xyzx, r4.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
mul r4.xyz, r3.wwww, r4.xyzx
mul r1.w, r1.w, r1.w
mad r4.xyz, r4.xyzx, r1.wwww, r8.xyzx
mad_sat r1.w, r6.z, r1.x, -cb0[16].x
mul r1.w, r1.w, r1.w
mad r3.xyz, r6.xyzx, r1.xxxx, r3.xyzx
lt r1.x, l(0.000000), r3.z
mov r3.w, l(1.000000)
dp4 r5.y, r3.xyzw, cb0[4].xyzw
dp4 r5.z, r3.xyzw, cb0[5].xyzw
dp4 r5.w, r3.xyzw, cb0[6].xyzw
div r3.xyz, r5.yzwy, r3.zzzz
movc r3.xyz, r1.xxxx, r3.xyzx, r0.xywx
add r3.xyz, -r0.xywx, r3.xyzx
dp3 r0.x, r3.xyzx, r3.xyzx
rsq r0.x, r0.x
mul r3.xyz, r0.xxxx, r3.xyzx
mul r3.xyz, r3.xyzx, l(0.500000, -0.500000, 1.000000, 0.000000)
dp3 r0.x, r3.xyzx, r3.xyzx
rsq r0.x, r0.x
mul r3.xyz, r0.xxxx, r3.xyzx
dp2 r0.x, r3.xyxx, r3.xyxx
sqrt r0.x, r0.x
mul r0.x, r0.x, cb0[18].x
lt r1.x, l(0.000000), r0.x
div r5.xyz, r3.xyzx, r0.xxxx
movc r3.xyz, r1.xxxx, r5.xyzx, r3.xyzx
mad r3.xyz, r3.xyzx, cb0[19].wwww, r3.xyzx
ftoi r5.x, cb0[18].x
mad r0.yz, v2.xxyx, l(0.000000, 0.500000, -0.500000, 0.000000), l(0.000000, 0.500000, 0.500000, 0.000000)
add r6.xyz, r3.xyzx, r0.yzwy
mul r0.x, r3.z, cb0[19].y
max r0.x, r0.x, cb0[19].x
lt r1.x, l(0.000010), |r3.z|
add r1.yz, -r1.yyzy, l(0.000000, 0.500000, 0.500000, 0.000000)
dp2 r1.y, r1.yzyy, r1.yzyy
sqrt r1.y, r1.y
add r1.y, r1.y, r1.y
min r1.y, r1.y, l(1.000000)
mad r1.y, -r1.y, r1.y, l(1.000000)
min r1.y, r1.y, r1.w
mov r7.w, l(1.000000)
mov r5.yzw, l(0,0.990000,0.990000,0.990000)
mov r8.xyz, l(0,0,0,0)
mov r1.w, l(0)
mov r9.z, l(0)
mov r9.xyw, r6.xyxz
loop 
  ige r1.z, r9.z, r5.x
  breakc_nz r1.z
  sample_d_indexable(texture2d)(float,float,float,float) r7.z, r9.xyxx, t1.yzxw, s7, r2.xyxx, r2.zwzz
  add r1.z, -r7.z, r9.w
  ge r3.w, r1.z, l(0.000000)
  lt r4.w, r1.z, r0.x
  and r3.w, r3.w, r4.w
  if_nz r3.w
    div r1.z, r1.z, r3.z
    mad r10.xy, r1.zzzz, r3.xyxx, r9.xyxx
    movc r9.xy, r1.xxxx, r10.xyxx, r9.xyxx
    mad r7.xy, r9.xyxx, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
    dp4 r10.x, r7.xyzw, cb0[12].xyzw
    dp4 r10.y, r7.xyzw, cb0[13].xyzw
    dp4 r1.z, r7.xyzw, cb0[15].xyzw
    div r7.xy, r10.xyxx, r1.zzzz
    mad r7.xy, r7.xyxx, l(0.500000, -0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
    sample_d_indexable(texture2d)(float,float,float,float) r8.xyz, r7.xyxx, t11.xyzw, s9, r2.xyxx, r2.zwzz
    mov r1.w, r1.y
    mov r9.z, r5.x
  else 
    iadd r1.z, r9.z, l(1)
    itof r3.w, r1.z
    mad r10.yzw, r3.xxyz, r3.wwww, r0.yyzw
    ge r3.w, r10.w, l(1.000000)
    add r4.w, -r10.w, cb0[17].x
    div r4.w, -cb0[17].y, r4.w
    lt r4.w, cb0[19].z, r4.w
    lt r7.xy, r10.yzyy, l(0.000000, 0.000000, 0.000000, 0.000000)
    lt r11.xy, l(1.000000, 1.000000, 0.000000, 0.000000), r10.yzyy
    or r6.w, r7.x, r11.x
    or r6.w, r7.y, r6.w
    or r6.w, r11.y, r6.w
    or r4.w, r4.w, r6.w
    movc r10.x, r4.w, r5.x, r1.z
    movc r9.xyzw, r3.wwww, r5.yzxw, r10.yzxw
  endif 
endloop 
mul r0.xyz, r4.xyzx, r8.xyzx
mul o0.xyz, r1.wwww, r0.xyzx
mov o0.w, r1.w
ret 
// Approximately 140 instruction slots used

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