//Nioh 2 screen space reflections. nMaxRaySmpl controls the amount of content in reflections.
// ---- Created with 3Dmigoto v1.3.16 on Fri Feb 05 20:39:32 2021
//
//cbuffer _Globals : register(b0)
//{
//  float fRayRadiusScale : packoffset(c0);
//  row_major float4x4 mP2V : packoffset(c1);
//  row_major float4x4 mV2P : packoffset(c5);
//  int nMaxRaySmpl : packoffset(c9);
//  float4 vReflParam : packoffset(c10);
//  float4 vDepthParam : packoffset(c11);
//  float4 vDepthFadeParam : packoffset(c12);
//  float4 vSampleEdgeFadeParam : packoffset(c13);
//}
//
//SamplerState __smpsDepth_s : register(s0);
//SamplerState __smpsScene_s : register(s1);
//SamplerState __smpsSceneNormal_s : register(s2);
//SamplerState __smpsMask_s : register(s3);
//Texture2D<float4> sDepth : register(t0);
//Texture2D<float4> sScene : register(t1);
//Texture2D<float4> sSceneNormal : register(t2);
//Texture2D<float4> sMask : register(t3);
//
//
//// 3Dmigoto declarations
//#define cmp -
//Texture1D<float4> IniParams : register(t120);
//Texture2D<float4> StereoParams : register(t125);
//
//
//void main(
//  float4 v0 : SV_Position0,
//  float4 v1 : TEXCOORD0,
//  float2 v2 : TEXCOORD1,
//  out float4 o0 : SV_Target0)
//{
//  float4 r0,r1,r2,r3,r4,r5,r6,r7,r20,r21,r22;
//  uint4 bitmask, uiDest;
//  float4 fDest;
//  
//  float4 stereo = StereoParams.Load(0);
//  float4 iniparams = IniParams.Load(0);
//  float4 iniparams2 = IniParams.Load(int2(2,0));
//  r20=v1;
//  
//  r0.x = sMask.SampleLevel(__smpsMask_s, v2.xy, 0).w;
//  r0.x = cmp(r0.x >= vDepthFadeParam.w);
//  if (r0.x != 0) {
//    r0.x = sDepth.SampleLevel(__smpsDepth_s, v2.xy, 0).x;
//    r0.y = cmp(0 < r0.x);
//    if (r0.y != 0) {
//	  
//	  r21.xyzw = mP2V._m10_m11_m12_m13 * v1.yyyy;
//      r21.xyzw = v1.xxxx * mP2V._m00_m01_m02_m03 + r21.xyzw;
//      r21.xyzw = r0.xxxx * mP2V._m20_m21_m22_m23 + r21.xyzw;
//      r21.xyzw = mP2V._m30_m31_m32_m33 + r21.xyzw;
//	  
//	  r20.x-=stereo.x;
//	  
//      r1.xyzw = mP2V._m10_m11_m12_m13 * v1.yyyy;
//      r1.xyzw = r20.xxxx * mP2V._m00_m01_m02_m03 + r1.xyzw;
//      r1.xyzw = r0.xxxx * mP2V._m20_m21_m22_m23 + r1.xyzw;
//      r1.xyzw = mP2V._m30_m31_m32_m33 + r1.xyzw;
//      r0.yzw = r1.xyz / r1.www;
//      r1.xyz = sSceneNormal.Sample(__smpsSceneNormal_s, v2.xy).xyz;
//      r1.xyz = float3(255,0.996336997,0.996336997) * r1.zxy;
//      r1.x = (uint)r1.x;
//      r1.w = (int)r1.x & 15;
//      r1.w = (uint)r1.w;
//      r2.x = r1.w * 0.000244200259 + r1.y;
//      r1.x = (uint)r1.x >> 4;
//      r1.x = (uint)r1.x;
//      r2.y = r1.x * 0.000244200259 + r1.z;
//      r1.xy = r2.xy * float2(2,2) + float2(-1,-1);
//      r2.xyz = float3(1,1,1) + -abs(r1.xyx);
//      r3.z = r2.x + -abs(r1.y);
//      r1.z = cmp(r3.z >= 0);
//      r2.xw = cmp(r1.xy >= float2(0,0));
//      r2.xw = r2.xw ? float2(1,1) : float2(-1,-1);
//      r2.xy = r2.yz * r2.xw;
//      r3.xy = r1.zz ? r1.xy : r2.xy;
//      r1.x = dot(r3.xyz, r3.xyz);
//      r1.x = rsqrt(r1.x);
//      r1.xyz = r3.xyz * r1.xxx;
//      r1.w = dot(r0.yzw, r1.xyz);
//      r1.w = r1.w + r1.w;
//      r1.xyz = r1.xyz * -r1.www + r0.yzw;
//      r1.w = dot(r1.xyz, r1.xyz);
//      r1.w = rsqrt(r1.w);
//      r1.w = r1.z * r1.w;
//      r1.w = r1.w * vReflParam.z + vReflParam.w;
//      r2.x = cmp(r1.w < 1);
//      if (r2.x != 0) {
//        r0.yzw = r1.xyz + r0.yzw;
//        r2.xyzw = mV2P._m10_m11_m12_m13 * r0.zzzz;
//        r2.xyzw = r0.yyyy * mV2P._m00_m01_m02_m03 + r2.xyzw;
//        r2.xyzw = r0.wwww * mV2P._m20_m21_m22_m23 + r2.xyzw;
//        r2.xyzw = mV2P._m30_m31_m32_m33 + r2.xyzw;
//		
//		r2.x+=stereo.x*r2.w;
//		
//        r0.yzw = r2.xyz / r2.www;
//        r1.xy = v1.xy;
//        r1.z = r0.x;
//        r0.yzw = -r1.xyz + r0.yzw;
//        r2.x = vReflParam.y * r0.y;
//        r2.x = max(abs(r2.x), abs(r0.z));
//        r2.x = vReflParam.x / r2.x;
//		
//		r0.y+=stereo.x*r2.x*vDepthParam.z;
//		
//        r0.yzw = r2.xxx * r0.yzw;
//        r1.xy = v2.xy;
//        r1.xyz = r0.yzw * float3(1,-1,2) + r1.xyz;
//        r2.x = fRayRadiusScale * r0.w;
//        r1.w = saturate(r1.w);
//        r3.z = 0;
//        r4.xyzw = float4(0,0,0,0);
//        r5.xyz = r1.xyz;
//        r2.y = r0.x;
//        r2.z = 0;
//        while (true) {
//          r2.w = cmp((int)r2.z >= nMaxRaySmpl*iniparams2.x);
//          if (r2.w != 0) break;
//          r2.w = sDepth.SampleLevel(__smpsDepth_s, r5.xy, 0).x;
//          r3.w = cmp(r2.w >= r5.z);
//          r6.x = r5.z + abs(r2.x);
//          r6.y = cmp(r6.x >= r2.w);
//          r3.w = r3.w ? r6.y : 0;
//          if (r3.w != 0) {
//            r3.w = saturate(r5.z);
//            r3.w = r3.w * vDepthParam.x + vDepthParam.y;
//            r3.w = 1 / r3.w;
//            r6.y = r2.w * vDepthParam.x + vDepthParam.y;
//            r6.y = 1 / r6.y;
//            r5.w = -r6.y + r3.w;
//            r6.yzw = -r0.wyz * float3(1,0.5,-0.5) + r5.zxy;
//            r3.w = cmp(r2.y >= r6.y);
//            r7.x = r6.y + abs(r2.x);
//            r7.x = cmp(r7.x >= r2.y);
//            r3.w = r3.w ? r7.x : 0;
//            r3.w = ~(int)r3.w;
//            r7.x = cmp(r2.y >= r5.z);
//            r6.x = cmp(r6.x >= r2.y);
//            r6.x = r6.x ? r7.x : 0;
//            r3.w = r3.w ? r6.x : 0;
//            r6.y = saturate(r6.y);
//            r6.x = r6.y * vDepthParam.x + vDepthParam.y;
//            r6.x = 1 / r6.x;
//            r6.y = r2.y * vDepthParam.x + vDepthParam.y;
//			
//			r22.w=r6.y;
//			
//            r6.y = 1 / r6.y;
//            r6.x = r6.y + -r6.x;
//            r6.y = r6.x + r5.w;
//            r6.x = r6.x / r6.y;
//            r7.xy = -r6.zw + r5.xy;
//            r3.xy = r6.xx * r7.xy + r6.zw;
//            r3.xyw = r3.www ? r3.xyz : r5.xyw;
//            r5.w = cmp(r3.w < vDepthFadeParam.x);
//            if (r5.w != 0) {
//              r3.w = saturate(r3.w * vDepthFadeParam.y + vDepthFadeParam.z);
//              r4.xyz = sScene.SampleLevel(__smpsScene_s, r3.xy, 0).xyz;
//              r6.xy = float2(-0.5,-0.5) + r3.xy;
//			  
//			  r6.x-=stereo.x*(0.5-stereo.y*r22.w*0.5);
//			  
//              r5.w = max(abs(r6.x), abs(r6.y));
//              r5.w = saturate(r5.w * vSampleEdgeFadeParam.z + vSampleEdgeFadeParam.w);
//              r6.x = (int)r2.z;
//              r6.x = saturate(r6.x * vSampleEdgeFadeParam.x + vSampleEdgeFadeParam.y);
//              r5.w = max(r5.w, r1.w);
//              r3.w = max(r6.x, r3.w)*0;
//              r3.w = max(r5.w, r3.w)*0;
//              r4.w = 1 + -r3.w;
//              break;
//            }
//            r5.xy = r3.xy;
//          }
//          r5.xyz = r0.yzw * float3(0.5,-0.5,1) + r5.xyz;
//          r3.xy = float2(-0.5,-0.5) + r5.xy;
//          r3.x = max(abs(r3.x), abs(r3.y));
//          r3.y = cmp(0.5 < r3.x);
//          if (r3.y != 0) {
//            r4.xyzw = float4(0,0,0,0);
//            break;
//          }
//          r3.y = cmp(r5.z < 0);
//          if (r3.y != 0) {
//            r3.y = sDepth.SampleLevel(__smpsDepth_s, r5.xy, 0).x;
//            r3.y = cmp(0 >= r3.y);
//            if (r3.y != 0) {
//              r4.xyz = sScene.SampleLevel(__smpsScene_s, r5.xy, 0).xyz;
//              r3.x = saturate(r3.x * vSampleEdgeFadeParam.z + vSampleEdgeFadeParam.w);
//              r3.y = (int)r2.z;
//              r3.y = saturate(r3.y * vSampleEdgeFadeParam.x + vSampleEdgeFadeParam.y);
//              r3.x = max(r3.x, r1.w);
//              r3.x = max(r3.x, r3.y);
//              r4.w = 1 + -r3.x;
//            } else {
//              r4.xyzw = float4(0,0,0,0);
//            }
//            break;
//          }
//          r2.y = r2.w;
//          r2.z = (int)r2.z + 1;
//          r4.xyzw = float4(0,0,0,0);
//        }
//        o0.xyzw = r4.xyzw;
//      } else {
//        o0.xyzw = float4(0,0,0,0);
//      }
//    } else {
//      o0.xyzw = float4(0,0,0,0);
//    }
//  } else {
//    o0.xyzw = float4(0,0,0,0);
//  }
//  return;
//}
//
///*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Fri Feb 05 20:39:32 2021
//
//
// Buffer Definitions:
//
// cbuffer $Globals
// {
//
//   float fRayRadiusScale;             // Offset:    0 Size:     4
//   row_major float4x4 mP2V;           // Offset:   16 Size:    64
//   row_major float4x4 mV2P;           // Offset:   80 Size:    64
//   int nMaxRaySmpl;                   // Offset:  144 Size:     4
//   float4 vReflParam;                 // Offset:  160 Size:    16
//   float4 vDepthParam;                // Offset:  176 Size:    16
//   float4 vDepthFadeParam;            // Offset:  192 Size:    16
//   float4 vSampleEdgeFadeParam;       // Offset:  208 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// __smpsDepth                       sampler      NA          NA    0        1
// __smpsScene                       sampler      NA          NA    1        1
// __smpsSceneNormal                 sampler      NA          NA    2        1
// __smpsMask                        sampler      NA          NA    3        1
// sDepth                            texture  float4          2d    0        1
// sScene                            texture  float4          2d    1        1
// sSceneNormal                      texture  float4          2d    2        1
// sMask                             texture  float4          2d    3        1
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy
// TEXCOORD                 1   xy          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[14], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, 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) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 32
dcl_resource_texture2d (float,float,float,float) t125
dcl_resource_texture1d (float,float,float,float) t120
ld_indexable(texture2d)(float,float,float,float) r25.xyzw, l(0, 0, 0, 0), t125.xyzw
ld_indexable(texture1d)(float,float,float,float) r26.xyzw, l(2, 0, 0, 0), t120.xyzw

mov r20.xy, v1.xy

ige r27.x, r26.x, l(1.01)

sample_l_indexable(texture2d)(float,float,float,float) r0.x, v2.xyxx, t3.wxyz, s3, l(0.000000)
ge r0.x, r0.x, cb0[12].w
if_nz r0.x
  sample_l_indexable(texture2d)(float,float,float,float) r0.x, v2.xyxx, t0.xyzw, s0, l(0.000000)
  lt r0.y, l(0.000000), r0.x
  if_nz r0.y
    
	add r20.x, -r25.x, r20.x 
	
    mul r1.xyzw, v1.yyyy, cb0[2].xyzw
    mad r1.xyzw, r20.xxxx, cb0[1].xyzw, r1.xyzw
    mad r1.xyzw, r0.xxxx, cb0[3].xyzw, r1.xyzw
    add r1.xyzw, r1.xyzw, cb0[4].xyzw
    div r0.yzw, r1.xxyz, r1.wwww
    sample_indexable(texture2d)(float,float,float,float) r1.xyz, v2.xyxx, t2.xyzw, s2
    mul r1.xyz, r1.zxyz, l(255.000000, 0.996337, 0.996337, 0.000000)
    ftou r1.x, r1.x
    and r1.w, r1.x, l(15)
    utof r1.w, r1.w
    mad r2.x, r1.w, l(0.000244200259), r1.y
    ushr r1.x, r1.x, l(4)
    utof r1.x, r1.x
    mad r2.y, r1.x, l(0.000244200259), r1.z
    mad r1.xy, r2.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
    add r2.xyz, -|r1.xyxx|, l(1.000000, 1.000000, 1.000000, 0.000000)
    add r3.z, -|r1.y|, r2.x
    ge r1.z, r3.z, l(0.000000)
    ge r2.xw, r1.xxxy, l(0.000000, 0.000000, 0.000000, 0.000000)
    movc r2.xw, r2.xxxw, l(1.000000,0,0,1.000000), l(-1.000000,0,0,-1.000000)
    mul r2.xy, r2.xwxx, r2.yzyy
    movc r3.xy, r1.zzzz, r1.xyxx, r2.xyxx
    dp3 r1.x, r3.xyzx, r3.xyzx
    rsq r1.x, r1.x
    mul r1.xyz, r1.xxxx, r3.xyzx
    dp3 r1.w, r0.yzwy, r1.xyzx
    add r1.w, r1.w, r1.w
    mad r1.xyz, r1.xyzx, -r1.wwww, r0.yzwy
    dp3 r1.w, r1.xyzx, r1.xyzx
    rsq r1.w, r1.w
    mul r1.w, r1.w, r1.z
    mad r1.w, r1.w, cb0[10].z, cb0[10].w
    lt r2.x, r1.w, l(1.000000)
    if_nz r2.x
      add r0.yzw, r0.yyzw, r1.xxyz
      mul r2.xyzw, r0.zzzz, cb0[6].xyzw
      mad r2.xyzw, r0.yyyy, cb0[5].xyzw, r2.xyzw
      mad r2.xyzw, r0.wwww, cb0[7].xyzw, r2.xyzw
      add r2.xyzw, r2.xyzw, cb0[8].xyzw
	  
	  mad r2.x, r25.x, r2.w, r2.x
	  
      div r0.yzw, r2.xxyz, r2.wwww
      mov r1.xy, v1.xyxx
      mov r1.z, r0.x
      add r0.yzw, r0.yyzw, -r1.xxyz
      mul r2.x, r0.y, cb0[10].y
      max r2.x, |r0.z|, |r2.x|
      div r2.x, cb0[10].x, r2.x
	  
	  mul r25.w, r2.x, cb0[11].z
	  mad r0.y, r25.x, r25.w, r0.y
	  
      mul r0.yzw, r0.yyzw, r2.xxxx
      mov r1.xy, v2.xyxx
      mad r1.xyz, r0.yzwy, l(1.000000, -1.000000, 2.000000, 0.000000), r1.xyzx
      mul r2.x, r0.w, cb0[0].x
      mov_sat r1.w, r1.w
      mov r3.z, l(0)
      mov r4.xyzw, l(0,0,0,0)
      mov r5.xyz, r1.xyzx
      mov r2.y, r0.x
      mov r2.z, l(0)
	  
	  //mul r27.x, r26.x, cb0[9].x
	  //iadd r27.x, r27.x, l(460)
	  
      loop
        ige r2.w, r2.z, cb0[9].x
		//ige r2.w, r2.z, r27.x
		
        breakc_nz r2.w
        sample_l_indexable(texture2d)(float,float,float,float) r2.w, r5.xyxx, t0.yzwx, s0, l(0.000000)
        ge r3.w, r2.w, r5.z
        add r6.x, |r2.x|, r5.z
        ge r6.y, r6.x, r2.w
        and r3.w, r3.w, r6.y
        if_nz r3.w
          mov_sat r3.w, r5.z
          mad r3.w, r3.w, cb0[11].x, cb0[11].y
          div r3.w, l(1.000000, 1.000000, 1.000000, 1.000000), r3.w
          mad r6.y, r2.w, cb0[11].x, cb0[11].y
          div r6.y, l(1.000000, 1.000000, 1.000000, 1.000000), r6.y
          add r5.w, r3.w, -r6.y
          mad r6.yzw, -r0.wwyz, l(0.000000, 1.000000, 0.500000, -0.500000), r5.zzxy
          ge r3.w, r2.y, r6.y
          add r7.x, |r2.x|, r6.y
          ge r7.x, r7.x, r2.y
          and r3.w, r3.w, r7.x
          not r3.w, r3.w
          ge r7.x, r2.y, r5.z
          ge r6.x, r6.x, r2.y
          and r6.x, r6.x, r7.x
          and r3.w, r3.w, r6.x
          mov_sat r6.y, r6.y
          mad r6.x, r6.y, cb0[11].x, cb0[11].y
          div r6.x, l(1.000000, 1.000000, 1.000000, 1.000000), r6.x
          mad r6.y, r2.y, cb0[11].x, cb0[11].y
		  
		  mov r22.x, r6.y
		  
          div r6.y, l(1.000000, 1.000000, 1.000000, 1.000000), r6.y
          add r6.x, -r6.x, r6.y
          add r6.y, r5.w, r6.x
          div r6.x, r6.x, r6.y
          add r7.xy, r5.xyxx, -r6.zwzz
          mad r3.xy, r6.xxxx, r7.xyxx, r6.zwzz
          movc r3.xyw, r3.wwww, r3.xyxz, r5.xyxw
          lt r5.w, r3.w, cb0[12].x
          if_nz r5.w
            mad_sat r3.w, r3.w, cb0[12].y, cb0[12].z
            sample_l_indexable(texture2d)(float,float,float,float) r4.xyz, r3.xyxx, t1.xyzw, s1, l(0.000000)
            add r6.xy, r3.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
			
			mad r25.w, -r25.y, r22.x, l(1.0)
			mul r25.w, r25.w, l(0.5)
			mad r6.x, -r25.x, r25.w, r6.x
			
            max r5.w, |r6.y|, |r6.x|
            mad_sat r5.w, r5.w, cb0[13].z, cb0[13].w
            itof r6.x, r2.z
            mad_sat r6.x, r6.x, cb0[13].x, cb0[13].y
            max r5.w, r1.w, r5.w
            max r3.w, r3.w, r6.x
            max r3.w, r3.w, r5.w
            add r4.w, -r3.w, l(1.000000)
            break
          endif
          mov r5.xy, r3.xyxx
        endif
        mad r5.xyz, r0.yzwy, l(0.500000, -0.500000, 1.000000, 0.000000), r5.xyzx
        add r3.xy, r5.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
        max r3.x, |r3.y|, |r3.x|
        lt r3.y, l(0.500000), r3.x
        if_nz r3.y
          mov r4.xyzw, l(0,0,0,0)
          break
        endif
        lt r3.y, r5.z, l(0.000000)
        if_nz r3.y
          sample_l_indexable(texture2d)(float,float,float,float) r3.y, r5.xyxx, t0.yxzw, s0, l(0.000000)
          ge r3.y, l(0.000000), r3.y
          if_nz r3.y
            sample_l_indexable(texture2d)(float,float,float,float) r4.xyz, r5.xyxx, t1.xyzw, s1, l(0.000000)
            mad_sat r3.x, r3.x, cb0[13].z, cb0[13].w
            itof r3.y, r2.z
            mad_sat r3.y, r3.y, cb0[13].x, cb0[13].y
            max r3.x, r1.w, r3.x
            max r3.x, r3.y, r3.x
            add r4.w, -r3.x, l(1.000000)
          else
            mov r4.xyzw, l(0,0,0,0)
          endif
          break
        endif
        mov r2.y, r2.w
		
		if_z r27.x
		iadd r2.z, r2.z, l(1)
		endif
        
        mov r4.xyzw, l(0,0,0,0)
      endloop
      mov o0.xyzw, r4.xyzw
    else
      mov o0.xyzw, l(0,0,0,0)
    endif
  else
    mov o0.xyzw, l(0,0,0,0)
  endif
else
  mov o0.xyzw, l(0,0,0,0)
endif
ret
// Approximately 155 instruction slots used
