//Nioh 2 distant fog PS.
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Sat Feb 06 11:20:13 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 gVfogInfo;                  // Index:   66.xyzw           Components:     4
//   float4 gCalcVolumeFactor;          // Index:   67.xyzw           Components:     4
//   float4 vP2V;                       // Index:   68.xyzw           Components:     4
//   row_major float4x4 mV2W;           // Index:   69 70 71 72       Components:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// __smpsVolumetricFogMap            sampler      NA          NA    0        1
// sVolumetricFogMap                 texture  float4          3d    0        1
// sSceneDepth                       texture  float4          2d    1        1
// sSceneColor                       texture  float4          2d    2        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[73], dynamicIndexed
dcl_sampler s0, mode_default
dcl_resource_texture3d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
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.zw, r0.xxxy, cb0[68].zzzw
ftoi r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.x, r1.xyzw, t1.xyzw
add r1.y, r1.x, cb0[68].x
div r1.y, cb0[68].y, r1.y
mul r0.zw, r0.zzzw, -r1.yyyy

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

mul r2.xyz, r0.wwww, cb0[70].xyzx
mad r2.xyz, r0.zzzz, cb0[69].xyzx, r2.xyzx
mad r2.xyz, r1.yyyy, cb0[71].xyzx, r2.xyzx
add r2.xyz, r2.xyzx, cb0[72].xyzx
ftou r3.xy, v0.xyxx
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyz, r3.xyzw, t2.xyzw
mov r0.zw, l(0,0,0,0)
loop
  ige r1.z, r0.w, l(20)
  breakc_nz r1.z
  mad r1.z, r2.x, cb0[r0.w + 7].x, cb0[r0.w + 8].x
  mul r1.z, r1.z, l(6.283185)
  mad r1.w, r2.z, cb0[r0.w + 9].x, cb0[r0.w + 10].x
  mul r1.w, r1.w, l(6.283185)
  sincos null, r1.zw, r1.zzzw
  add r1.z, r1.w, r1.z
  mad r0.z, r1.z, cb0[r0.w + 6].x, r0.z
  iadd r0.w, r0.w, l(5)
endloop
add r0.z, r0.z, r2.y
mad_sat r0.z, r0.z, cb0[3].x, cb0[3].y
mov_sat r0.w, cb0[0].w
mul r0.z, r0.w, r0.z
mad_sat r0.w, -r1.y, cb0[3].z, cb0[3].w
mul r0.z, r0.w, r0.z
add r4.xyz, -r3.xyzx, cb0[0].xyzx
mad r3.xyz, r0.zzzz, r4.xyzx, r3.xyzx
mov r0.zw, l(0,0,0,0)
loop
  ige r1.z, r0.w, l(20)
  breakc_nz r1.z
  mad r1.z, r2.x, cb0[r0.w + 27].x, cb0[r0.w + 28].x
  mul r1.z, r1.z, l(6.283185)
  mad r1.w, r2.z, cb0[r0.w + 29].x, cb0[r0.w + 30].x
  mul r1.w, r1.w, l(6.283185)
  sincos null, r1.zw, r1.zzzw
  add r1.z, r1.w, r1.z
  mad r0.z, r1.z, cb0[r0.w + 26].x, r0.z
  iadd r0.w, r0.w, l(5)
endloop
add r0.z, r0.z, r2.y
mad_sat r0.z, r0.z, cb0[4].x, cb0[4].y
mov_sat r0.w, cb0[1].w
mul r0.z, r0.w, r0.z
mad_sat r0.w, -r1.y, cb0[4].z, cb0[4].w
mul r0.z, r0.w, r0.z
add r4.xyz, -r3.xyzx, cb0[1].xyzx
mad r3.xyz, r0.zzzz, r4.xyzx, r3.xyzx
mov r0.zw, l(0,0,0,0)
loop
  ige r1.z, r0.w, l(20)
  breakc_nz r1.z
  mad r1.z, r2.x, cb0[r0.w + 47].x, cb0[r0.w + 48].x
  mul r1.z, r1.z, l(6.283185)
  mad r1.w, r2.z, cb0[r0.w + 49].x, cb0[r0.w + 50].x
  mul r1.w, r1.w, l(6.283185)
  sincos null, r1.zw, r1.zzzw
  add r1.z, r1.w, r1.z
  mad r0.z, r1.z, cb0[r0.w + 46].x, r0.z
  iadd r0.w, r0.w, l(5)
endloop
add r0.z, r0.z, r2.y
mad_sat r0.z, r0.z, cb0[5].x, cb0[5].y
mov_sat r0.w, cb0[2].w
mul r0.z, r0.w, r0.z
mad_sat r0.w, -r1.y, cb0[5].z, cb0[5].w
mul r0.z, r0.w, r0.z
add r1.yzw, -r3.xxyz, cb0[2].xxyz
mad r1.yzw, r0.zzzz, r1.yyzw, r3.xxyz
mad r0.xy, r0.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000), l(0.500000, -0.500000, 0.000000, 0.000000)
add r1.x, r1.x, cb0[67].y
log r1.x, |r1.x|
mad r0.z, r1.x, cb0[67].z, cb0[67].x
mov r0.w, -r0.y
sample_indexable(texture3d)(float,float,float,float) r0.xyzw, r0.xwzx, t0.xyzw, s0
mad r0.xyz, r1.yzwy, r0.wwww, r0.xyzx
add r0.xyz, -r1.yzwy, r0.xyzx
mad o0.xyz, cb0[66].wwww, r0.xyzx, r1.yzwy
mov o0.w, l(1.000000)
ret
// Approximately 90 instruction slots used

///////////////////////////////// HLSL Code /////////////////////////////////
// // ---- Created with 3Dmigoto v1.3.16 on Sat Feb 06 11:20:13 2021
//
// cbuffer _Globals : register(b0)
// {
//   float4 cHFog[3] : packoffset(c0);
//   float4 hFogParam[3] : packoffset(c3);
//   float hFogFlucPrms[60] : packoffset(c6);
//   float4 gVfogInfo : packoffset(c66);
//   float4 gCalcVolumeFactor : packoffset(c67);
//   float4 vP2V : packoffset(c68);
//   row_major float4x4 mV2W : packoffset(c69);
// }
//
// SamplerState __smpsVolumetricFogMap_s : register(s0);
// Texture3D<float4> sVolumetricFogMap : register(t0);
// Texture2D<float4> sSceneDepth : register(t1);
// Texture2D<float4> sSceneColor : register(t2);
//
//
// // 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,r3,r4;
//   uint4 bitmask, uiDest;
//   float4 fDest;
//
//   r0.x = 1 / v1.w;
//   r0.xy = v1.xy * r0.xx;
//   r0.zw = vP2V.zw * r0.xy;
//   r1.xy = (int2)v0.xy;
//   r1.zw = float2(0,0);
//   r1.x = sSceneDepth.Load(r1.xyz).x;
//   r1.y = vP2V.x + r1.x;
//   r1.y = vP2V.y / r1.y;
//   r0.zw = -r1.yy * r0.zw;
//   r2.xyz = mV2W._m10_m11_m12 * r0.www;
//   r2.xyz = r0.zzz * mV2W._m00_m01_m02 + r2.xyz;
//   r2.xyz = r1.yyy * mV2W._m20_m21_m22 + r2.xyz;
//   r2.xyz = mV2W._m30_m31_m32 + r2.xyz;
//   r3.xy = (uint2)v0.xy;
//   r3.zw = float2(0,0);
//   r3.xyz = sSceneColor.Load(r3.xyz).xyz;
//   r0.zw = float2(0,0);
//   while (true) {
//     r1.z = cmp((int)r0.w >= 20);
//     if (r1.z != 0) break;
//     r1.z = r2.x * hFogFlucPrms[r0.w+7] + hFogFlucPrms[r0.w+8];
//     r1.z = 6.28318501 * r1.z;
//     r1.w = r2.z * hFogFlucPrms[r0.w+9] + hFogFlucPrms[r0.w+10];
//     r1.w = 6.28318501 * r1.w;
//     r1.zw = cos(r1.zw);
//     r1.z = r1.z + r1.w;
//     r0.z = r1.z * hFogFlucPrms[r0.w] + r0.z;
//     r0.w = (int)r0.w + 5;
//   }
//   r0.z = r2.y + r0.z;
//   r0.z = saturate(r0.z * hFogParam[0].x + hFogParam[0].y);
//   r0.w = saturate(cHFog[0].w);
//   r0.z = r0.z * r0.w;
//   r0.w = saturate(-r1.y * hFogParam[0].z + hFogParam[0].w);
//   r0.z = r0.z * r0.w;
//   r4.xyz = cHFog[0].xyz + -r3.xyz;
//   r3.xyz = r0.zzz * r4.xyz + r3.xyz;
//   r0.zw = float2(0,0);
//   while (true) {
//     r1.z = cmp((int)r0.w >= 20);
//     if (r1.z != 0) break;
//     r1.z = r2.x * hFogFlucPrms[r0.w+27] + hFogFlucPrms[r0.w+28];
//     r1.z = 6.28318501 * r1.z;
//     r1.w = r2.z * hFogFlucPrms[r0.w+29] + hFogFlucPrms[r0.w+30];
//     r1.w = 6.28318501 * r1.w;
//     r1.zw = cos(r1.zw);
//     r1.z = r1.z + r1.w;
//     r0.z = r1.z * hFogFlucPrms[r0.w+26] + r0.z;
//     r0.w = (int)r0.w + 5;
//   }
//   r0.z = r2.y + r0.z;
//   r0.z = saturate(r0.z * hFogParam[1].x + hFogParam[1].y);
//   r0.w = saturate(cHFog[1].w);
//   r0.z = r0.z * r0.w;
//   r0.w = saturate(-r1.y * hFogParam[1].z + hFogParam[1].w);
//   r0.z = r0.z * r0.w;
//   r4.xyz = cHFog[1].xyz + -r3.xyz;
//   r3.xyz = r0.zzz * r4.xyz + r3.xyz;
//   r0.zw = float2(0,0);
//   while (true) {
//     r1.z = cmp((int)r0.w >= 20);
//     if (r1.z != 0) break;
//     r1.z = r2.x * hFogFlucPrms[r0.w+47] + hFogFlucPrms[r0.w+48];
//     r1.z = 6.28318501 * r1.z;
//     r1.w = r2.z * hFogFlucPrms[r0.w+49] + hFogFlucPrms[r0.w+50];
//     r1.w = 6.28318501 * r1.w;
//     r1.zw = cos(r1.zw);
//     r1.z = r1.z + r1.w;
//     r0.z = r1.z * hFogFlucPrms[r0.w+46] + r0.z;
//     r0.w = (int)r0.w + 5;
//   }
//   r0.z = r2.y + r0.z;
//   r0.z = saturate(r0.z * hFogParam[2].x + hFogParam[2].y);
//   r0.w = saturate(cHFog[2].w);
//   r0.z = r0.z * r0.w;
//   r0.w = saturate(-r1.y * hFogParam[2].z + hFogParam[2].w);
//   r0.z = r0.z * r0.w;
//   r1.yzw = cHFog[2].xyz + -r3.xyz;
//   r1.yzw = r0.zzz * r1.yzw + r3.xyz;
//   r0.xy = r0.xy * float2(0.5,0.5) + float2(0.5,-0.5);
//   r1.x = gCalcVolumeFactor.y + r1.x;
//   r1.x = log2(abs(r1.x));
//   r0.z = r1.x * gCalcVolumeFactor.z + gCalcVolumeFactor.x;
//   r0.w = -r0.y;
//   r0.xyzw = sVolumetricFogMap.Sample(__smpsVolumetricFogMap_s, r0.xwz).xyzw;
//   r0.xyz = r1.yzw * r0.www + r0.xyz;
//   r0.xyz = r0.xyz + -r1.yzw;
//   o0.xyz = gVfogInfo.www * r0.xyz + r1.yzw;
//   o0.w = 1;
//   return;
// }
//////////////////////////////// HLSL Errors ////////////////////////////////
// F:\SteamLibrary\steamapps\common\Nioh2\ShaderFixes\a2c286a197af648e-ps_replace.txt(99,43-63): error X3504: literal loop terminated early due to out of bounds array access
// F:\SteamLibrary\steamapps\common\Nioh2\ShaderFixes\a2c286a197af648e-ps_replace.txt(94,10-13): error X3696: infinite loop detected - loop never exits
/////////////////////////////////////////////////////////////////////////////
