//Nioh 2 distant fog PS 2.
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Mon Feb 08 21:10:30 2021
//
//
// Buffer Definitions:
//
// cbuffer $Globals
// {
//
//   float4 cHFog[3];                   // Index:    0 1 2            Components:    12
//   float4 hFogParam[3];               // Index:    3 4 5            Components:    12
//   float hFogFlucPrms[60];            // Index:    6-65.x           Components:   237
//   float4 vP2V;                       // Index:   66.xyzw           Components:     4
//   row_major float4x4 mV2W;           // Index:   67 68 69 70       Components:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sSceneDepth                       texture  float4          2d    0        1
// sSceneColor                       texture  float4          2d    1        1
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xy
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
//
//
// 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[71], dynamicIndexed
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v1.xyw
dcl_output o0.xyzw
dcl_temps 35
dcl_resource_texture2d (float,float,float,float) t125
ld_indexable(texture2d)(float,float,float,float) r25.xyzw, l(0, 0, 0, 0), t125.xyzw
div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), v1.w
mul r0.xy, r0.xxxx, v1.xyxx
mul r0.xy, r0.xyxx, cb0[66].zwzz
ftoi r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r0.z, r1.xyzw, t0.yzxw
add r0.z, r0.z, cb0[66].x
div r0.z, cb0[66].y, r0.z
mul r0.xy, -r0.zzzz, r0.xyxx

add r25.w, r0.z, -r25.y
mul r25.w, r25.w, cb0[66].z
mad r0.x, r25.x, r25.w, r0.x

mul r1.xyz, r0.yyyy, cb0[68].xyzx
mad r0.xyw, r0.xxxx, cb0[67].xyxz, r1.xyxz
mad r0.xyw, r0.zzzz, cb0[69].xyxz, r0.xyxw
add r0.xyw, r0.xyxw, cb0[70].xyxz
ftou r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyzw, t1.xyzw
mov r1.w, l(0)
mov r2.x, l(0)
loop
  ige r2.y, r2.x, l(20)
  breakc_nz r2.y
  mad r2.y, r0.x, cb0[r2.x + 7].x, cb0[r2.x + 8].x
  mul r2.y, r2.y, l(6.283185)
  mad r2.z, r0.w, cb0[r2.x + 9].x, cb0[r2.x + 10].x
  mul r2.z, r2.z, l(6.283185)
  sincos null, r2.yz, r2.yyzy
  add r2.y, r2.z, r2.y
  mad r1.w, r2.y, cb0[r2.x + 6].x, r1.w
  iadd r2.x, r2.x, l(5)
endloop
add r1.w, r0.y, r1.w
mad_sat r1.w, r1.w, cb0[3].x, cb0[3].y
mov_sat r2.x, cb0[0].w
mul r1.w, r1.w, r2.x
mad_sat r2.x, -r0.z, cb0[3].z, cb0[3].w
mul r1.w, r1.w, r2.x
add r2.xyz, -r1.xyzx, cb0[0].xyzx
mad r1.xyz, r1.wwww, r2.xyzx, r1.xyzx
mov r1.w, l(0)
mov r2.x, l(0)
loop
  ige r2.y, r2.x, l(20)
  breakc_nz r2.y
  mad r2.y, r0.x, cb0[r2.x + 27].x, cb0[r2.x + 28].x
  mul r2.y, r2.y, l(6.283185)
  mad r2.z, r0.w, cb0[r2.x + 29].x, cb0[r2.x + 30].x
  mul r2.z, r2.z, l(6.283185)
  sincos null, r2.yz, r2.yyzy
  add r2.y, r2.z, r2.y
  mad r1.w, r2.y, cb0[r2.x + 26].x, r1.w
  iadd r2.x, r2.x, l(5)
endloop
add r1.w, r0.y, r1.w
mad_sat r1.w, r1.w, cb0[4].x, cb0[4].y
mov_sat r2.x, cb0[1].w
mul r1.w, r1.w, r2.x
mad_sat r2.x, -r0.z, cb0[4].z, cb0[4].w
mul r1.w, r1.w, r2.x
add r2.xyz, -r1.xyzx, cb0[1].xyzx
mad r1.xyz, r1.wwww, r2.xyzx, r1.xyzx
mov r1.w, l(0)
mov r2.x, l(0)
loop
  ige r2.y, r2.x, l(20)
  breakc_nz r2.y
  mad r2.y, r0.x, cb0[r2.x + 47].x, cb0[r2.x + 48].x
  mul r2.y, r2.y, l(6.283185)
  mad r2.z, r0.w, cb0[r2.x + 49].x, cb0[r2.x + 50].x
  mul r2.z, r2.z, l(6.283185)
  sincos null, r2.yz, r2.yyzy
  add r2.y, r2.z, r2.y
  mad r1.w, r2.y, cb0[r2.x + 46].x, r1.w
  iadd r2.x, r2.x, l(5)
endloop
add r0.x, r0.y, r1.w
mad_sat r0.x, r0.x, cb0[5].x, cb0[5].y
mov_sat r0.y, cb0[2].w
mul r0.x, r0.y, r0.x
mad_sat r0.y, -r0.z, cb0[5].z, cb0[5].w
mul r0.x, r0.y, r0.x
add r0.yzw, -r1.xxyz, cb0[2].xxyz
mad o0.xyz, r0.xxxx, r0.yzwy, r1.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 84 instruction slots used

///////////////////////////////// HLSL Code /////////////////////////////////
// // ---- Created with 3Dmigoto v1.3.16 on Mon Feb 08 21:10:30 2021
//
// cbuffer _Globals : register(b0)
// {
//   float4 cHFog[3] : packoffset(c0);
//   float4 hFogParam[3] : packoffset(c3);
//   float hFogFlucPrms[60] : packoffset(c6);
//   float4 vP2V : packoffset(c66);
//   row_major float4x4 mV2W : packoffset(c67);
// }
//
// Texture2D<float4> sSceneDepth : register(t0);
// Texture2D<float4> sSceneColor : register(t1);
//
//
// // 3Dmigoto declarations
// #define cmp -
// Texture1D<float4> IniParams : register(t120);
// Texture2D<float4> StereoParams : register(t125);
//
//
// void main(
//   float4 v0 : SV_Position0,
//   float4 v1 : TEXCOORD0,
//   out float4 o0 : SV_Target0)
// {
//   float4 r0,r1,r2;
//   uint4 bitmask, uiDest;
//   float4 fDest;
//
//   r0.x = 1 / v1.w;
//   r0.xy = v1.xy * r0.xx;
//   r0.xy = vP2V.zw * r0.xy;
//   r1.xy = (int2)v0.xy;
//   r1.zw = float2(0,0);
//   r0.z = sSceneDepth.Load(r1.xyz).x;
//   r0.z = vP2V.x + r0.z;
//   r0.z = vP2V.y / r0.z;
//   r0.xy = r0.xy * -r0.zz;
//   r1.xyz = mV2W._m10_m11_m12 * r0.yyy;
//   r0.xyw = r0.xxx * mV2W._m00_m01_m02 + r1.xyz;
//   r0.xyw = r0.zzz * mV2W._m20_m21_m22 + r0.xyw;
//   r0.xyw = mV2W._m30_m31_m32 + r0.xyw;
//   r1.xy = (uint2)v0.xy;
//   r1.zw = float2(0,0);
//   r1.xyz = sSceneColor.Load(r1.xyz).xyz;
//   r1.w = 0;
//   r2.x = 0;
//   while (true) {
//     r2.y = cmp((int)r2.x >= 20);
//     if (r2.y != 0) break;
//     r2.y = r0.x * hFogFlucPrms[r2.x+7] + hFogFlucPrms[r2.x+8];
//     r2.y = 6.28318501 * r2.y;
//     r2.z = r0.w * hFogFlucPrms[r2.x+9] + hFogFlucPrms[r2.x+10];
//     r2.z = 6.28318501 * r2.z;
//     r2.yz = cos(r2.yz);
//     r2.y = r2.y + r2.z;
//     r1.w = r2.y * hFogFlucPrms[r2.x] + r1.w;
//     r2.x = (int)r2.x + 5;
//   }
//   r1.w = r1.w + r0.y;
//   r1.w = saturate(r1.w * hFogParam[0].x + hFogParam[0].y);
//   r2.x = saturate(cHFog[0].w);
//   r1.w = r2.x * r1.w;
//   r2.x = saturate(-r0.z * hFogParam[0].z + hFogParam[0].w);
//   r1.w = r2.x * r1.w;
//   r2.xyz = cHFog[0].xyz + -r1.xyz;
//   r1.xyz = r1.www * r2.xyz + r1.xyz;
//   r1.w = 0;
//   r2.x = 0;
//   while (true) {
//     r2.y = cmp((int)r2.x >= 20);
//     if (r2.y != 0) break;
//     r2.y = r0.x * hFogFlucPrms[r2.x+27] + hFogFlucPrms[r2.x+28];
//     r2.y = 6.28318501 * r2.y;
//     r2.z = r0.w * hFogFlucPrms[r2.x+29] + hFogFlucPrms[r2.x+30];
//     r2.z = 6.28318501 * r2.z;
//     r2.yz = cos(r2.yz);
//     r2.y = r2.y + r2.z;
//     r1.w = r2.y * hFogFlucPrms[r2.x+26] + r1.w;
//     r2.x = (int)r2.x + 5;
//   }
//   r1.w = r1.w + r0.y;
//   r1.w = saturate(r1.w * hFogParam[1].x + hFogParam[1].y);
//   r2.x = saturate(cHFog[1].w);
//   r1.w = r2.x * r1.w;
//   r2.x = saturate(-r0.z * hFogParam[1].z + hFogParam[1].w);
//   r1.w = r2.x * r1.w;
//   r2.xyz = cHFog[1].xyz + -r1.xyz;
//   r1.xyz = r1.www * r2.xyz + r1.xyz;
//   r1.w = 0;
//   r2.x = 0;
//   while (true) {
//     r2.y = cmp((int)r2.x >= 20);
//     if (r2.y != 0) break;
//     r2.y = r0.x * hFogFlucPrms[r2.x+47] + hFogFlucPrms[r2.x+48];
//     r2.y = 6.28318501 * r2.y;
//     r2.z = r0.w * hFogFlucPrms[r2.x+49] + hFogFlucPrms[r2.x+50];
//     r2.z = 6.28318501 * r2.z;
//     r2.yz = cos(r2.yz);
//     r2.y = r2.y + r2.z;
//     r1.w = r2.y * hFogFlucPrms[r2.x+46] + r1.w;
//     r2.x = (int)r2.x + 5;
//   }
//   r0.x = r1.w + r0.y;
//   r0.x = saturate(r0.x * hFogParam[2].x + hFogParam[2].y);
//   r0.y = saturate(cHFog[2].w);
//   r0.x = r0.x * r0.y;
//   r0.y = saturate(-r0.z * hFogParam[2].z + hFogParam[2].w);
//   r0.x = r0.x * r0.y;
//   r0.yzw = cHFog[2].xyz + -r1.xyz;
//   o0.xyz = r0.xxx * r0.yzw + r1.xyz;
//   o0.w = 1;
//   return;
// }
//////////////////////////////// HLSL Errors ////////////////////////////////
// F:\SteamLibrary\steamapps\common\Nioh2\ShaderFixes\f05e598c9ef78a10-ps_replace.txt(98,43-63): error X3504: literal loop terminated early due to out of bounds array access
// F:\SteamLibrary\steamapps\common\Nioh2\ShaderFixes\f05e598c9ef78a10-ps_replace.txt(93,10-13): error X3696: infinite loop detected - loop never exits
/////////////////////////////////////////////////////////////////////////////
