//P5S cel shading PS 1.
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Tue Mar 08 23:18:12 2022
//
//
// Buffer Definitions:
//
// cbuffer $Globals
// {
//
//   float4 ambLit;                     // Index:    0.xyzw           Components:     4
//   float4 vDithAlp;                   // Index:    1.xyzw           Components:     4
//   int hFogType[3];                   // Index:    2-4.x            Components:     9
//   float4 cHFog[3];                   // Index:    5 6 7            Components:    12
//   float4 hFogParam[3];               // Index:    8 9 10           Components:    12
//   float hFogFlucPrms[60];            // Index:   11-70.x           Components:   237
//   float fOLLtEfFade;                 // Index:   70.y              Components:     1
//      = 0x00000000
//   float3 vOLAmbEfScaler;             // Index:   71.xyz            Components:     3
//      = 0x3f800000 0x3f800000 0x3f800000
//   float3 vOLColorScaler;             // Index:   72.xyz            Components:     3
//      = 0x3f800000 0x3f800000 0x3f800000
//   float fOLCSatFade;                 // Index:   72.w              Components:     1
//      = 0x00000000
//   float fOLPtnFade;                  // Index:   73.x              Components:     1
//      = 0x00000000
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// __smpsLit                         sampler      NA          NA    3        1
// __smpsOutlineColor                sampler      NA          NA    4        1
// sLit                              texture  float4          2d    3        1
// sOutlineColor                     texture  float4          2d    4        1
// sOutlineAutoHDRScaleExposure      texture  float4          2d    6        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      w
// TEXCOORD                 1   xyzw        2     NONE   float   xyz
// TEXCOORD                 2   xy          3     NONE   float   xy
// TEXCOORD                 3   x           4     NONE     int   x
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_immediateConstantBuffer { { 0.031250, 0, 0, 0},
                              { 0.531250, 0, 0, 0},
                              { 0.156250, 0, 0, 0},
                              { 0.656250, 0, 0, 0},
                              { 0.781250, 0, 0, 0},
                              { 0.281250, 0, 0, 0},
                              { 0.906250, 0, 0, 0},
                              { 0.406250, 0, 0, 0},
                              { 0.218750, 0, 0, 0},
                              { 0.718750, 0, 0, 0},
                              { 0.093750, 0, 0, 0},
                              { 0.593750, 0, 0, 0},
                              { 0.968750, 0, 0, 0},
                              { 0.468750, 0, 0, 0},
                              { 0.843750, 0, 0, 0},
                              { 0.343750, 0, 0, 0} }
dcl_constantbuffer cb0[74], dynamicIndexed
dcl_sampler s3, mode_default
dcl_sampler s4, mode_default
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t4
dcl_resource_texture2d (float,float,float,float) t6
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v1.w
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xy
dcl_input_ps constant v4.x
dcl_output o0.xyzw
dcl_temps 24
dcl_resource_texture1d (float,float,float,float) t120
ld_indexable(texture1d)(float,float,float,float) r20.xyzw, l(6, 0, 0, 0), t120.xyzw

discard_nz r20.x

round_ni r0.xy, v0.xyxx
itof r0.z, v4.x
add r0.z, r0.z, l(0.500000)
mul r1.x, r0.z, l(0.00390625000)
mov r1.y, l(0.500000)
sample_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyxx, t4.xyzw, s4
sample_indexable(texture2d)(float,float,float,float) r0.z, v3.xyxx, t3.yzxw, s3
mul r1.xyz, r1.xyzx, cb0[72].xyzx
mov_sat r0.w, cb0[70].y
mad r2.xyz, cb0[0].xyzx, cb0[71].xyzx, l(-1.000000, -1.000000, -1.000000, 0.000000)
mad r2.xyz, r0.wwww, r2.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
mul r1.xyz, r1.xyzx, r2.xyzx
mov_sat r0.w, cb0[73].x
add r0.z, r0.z, l(-1.000000)
mad r0.z, r0.w, r0.z, l(1.000000)
mul r1.xyz, r0.zzzz, r1.xyzx
max r0.z, r1.z, r1.y
max r0.z, r0.z, r1.x
add_sat r0.z, r0.z, l(-0.001960)
ge r2.xyz, r1.xyzx, r0.zzzz
and r2.xyz, r2.xyzx, l(0x3f800000, 0x3f800000, 0x3f800000, 0)
mov_sat r0.z, cb0[72].w
mad r2.xyz, r1.xyzx, r2.xyzx, -r1.xyzx
mad r1.xyz, r0.zzzz, r2.xyzx, r1.xyzx
ld_indexable(texture2d)(float,float,float,float) r0.z, l(0, 0, 0, 0), t6.yzxw
div r0.z, l(1.000000, 1.000000, 1.000000, 1.000000), r0.z
min r0.z, r0.z, l(340282306073709650000000000000000000000.000000)
mul r2.xyz, r0.zzzz, r1.xyzx
mov r0.w, l(0)
mov r1.w, l(0)
loop
  ige r2.w, r1.w, l(20)
  breakc_nz r2.w
  mad r2.w, v2.x, cb0[r1.w + 12].x, cb0[r1.w + 13].x
  mul r2.w, r2.w, l(6.283185)
  sincos null, r2.w, r2.w
  mad r3.x, v2.z, cb0[r1.w + 14].x, cb0[r1.w + 15].x
  mul r3.x, r3.x, l(6.283185)
  sincos null, r3.x, r3.x
  add r2.w, r2.w, r3.x
  mad r0.w, r2.w, cb0[r1.w + 11].x, r0.w
  iadd r1.w, r1.w, l(5)
endloop
add r0.w, r0.w, v2.y
mad_sat r0.w, r0.w, cb0[8].x, cb0[8].y
mul r1.w, r0.w, l(-1.442695)
exp r1.w, r1.w
add r1.w, -r1.w, l(1.000000)
ieq r3.xy, cb0[2].xxxx, l(1, 2, 0, 0)
mul r2.w, r0.w, r0.w
mul r2.w, r2.w, l(-1.442695)
exp r2.w, r2.w
add r2.w, -r2.w, l(1.000000)
and r2.w, r2.w, r3.y
movc r1.w, r3.x, r1.w, r2.w
movc r0.w, cb0[2].x, r1.w, r0.w
mov_sat r1.w, cb0[5].w
mul r0.w, r0.w, r1.w
mad_sat r1.w, v1.w, cb0[8].z, cb0[8].w
mul r0.w, r0.w, r1.w
mad r1.xyz, -r1.xyzx, r0.zzzz, cb0[5].xyzx
mad r1.xyz, r0.wwww, r1.xyzx, r2.xyzx
mov r0.zw, l(0,0,0,0)
loop
  ige r1.w, r0.w, l(20)
  breakc_nz r1.w
  mad r1.w, v2.x, cb0[r0.w + 32].x, cb0[r0.w + 33].x
  mul r1.w, r1.w, l(6.283185)
  sincos null, r1.w, r1.w
  mad r2.x, v2.z, cb0[r0.w + 34].x, cb0[r0.w + 35].x
  mul r2.x, r2.x, l(6.283185)
  sincos null, r2.x, r2.x
  add r1.w, r1.w, r2.x
  mad r0.z, r1.w, cb0[r0.w + 31].x, r0.z
  iadd r0.w, r0.w, l(5)
endloop
add r0.z, r0.z, v2.y
mad_sat r0.z, r0.z, cb0[9].x, cb0[9].y
mul r0.w, r0.z, l(-1.442695)
exp r0.w, r0.w
add r0.w, -r0.w, l(1.000000)
ieq r2.xy, cb0[3].xxxx, l(1, 2, 0, 0)
mul r1.w, r0.z, r0.z
mul r1.w, r1.w, l(-1.442695)
exp r1.w, r1.w
add r1.w, -r1.w, l(1.000000)
and r1.w, r1.w, r2.y
movc r0.w, r2.x, r0.w, r1.w
movc r0.z, cb0[3].x, r0.w, r0.z
mov_sat r0.w, cb0[6].w
mul r0.z, r0.w, r0.z
mad_sat r0.w, v1.w, cb0[9].z, cb0[9].w
mul r0.z, r0.w, r0.z
add r2.xyz, -r1.xyzx, cb0[6].xyzx
mad r1.xyz, r0.zzzz, r2.xyzx, r1.xyzx
mov r0.zw, l(0,0,0,0)
loop
  ige r1.w, r0.w, l(20)
  breakc_nz r1.w
  mad r1.w, v2.x, cb0[r0.w + 52].x, cb0[r0.w + 53].x
  mul r1.w, r1.w, l(6.283185)
  sincos null, r1.w, r1.w
  mad r2.x, v2.z, cb0[r0.w + 54].x, cb0[r0.w + 55].x
  mul r2.x, r2.x, l(6.283185)
  sincos null, r2.x, r2.x
  add r1.w, r1.w, r2.x
  mad r0.z, r1.w, cb0[r0.w + 51].x, r0.z
  iadd r0.w, r0.w, l(5)
endloop
add r0.z, r0.z, v2.y
mad_sat r0.z, r0.z, cb0[10].x, cb0[10].y
mul r0.w, r0.z, l(-1.442695)
exp r0.w, r0.w
add r0.w, -r0.w, l(1.000000)
ieq r2.xy, cb0[4].xxxx, l(1, 2, 0, 0)
mul r1.w, r0.z, r0.z
mul r1.w, r1.w, l(-1.442695)
exp r1.w, r1.w
add r1.w, -r1.w, l(1.000000)
and r1.w, r1.w, r2.y
movc r0.w, r2.x, r0.w, r1.w
movc r0.z, cb0[4].x, r0.w, r0.z
mov_sat r0.w, cb0[7].w
mul r0.z, r0.w, r0.z
mad_sat r0.w, v1.w, cb0[10].z, cb0[10].w
mul r0.z, r0.w, r0.z
add r2.xyz, -r1.xyzx, cb0[7].xyzx
mad o0.xyz, r0.zzzz, r2.xyzx, r1.xyzx
ftou r0.xy, r0.xyxx
bfi r0.y, l(2), l(2), r0.y, l(0)
bfi r0.x, l(2), l(0), r0.x, r0.y
add r0.x, cb0[1].w, -icb[r0.x + 0].x
lt r0.x, r0.x, l(0.000000)
discard_nz r0.x
mov o0.w, l(1.000000)
ret
// Approximately 136 instruction slots used

///////////////////////////////// HLSL Code /////////////////////////////////
// // ---- Created with 3Dmigoto v1.3.16 on Tue Mar 08 23:18:12 2022
//
// cbuffer _Globals : register(b0)
// {
//   float4 ambLit : packoffset(c0);
//   float4 vDithAlp : packoffset(c1);
//   int hFogType[3] : packoffset(c2);
//   float4 cHFog[3] : packoffset(c5);
//   float4 hFogParam[3] : packoffset(c8);
//   float hFogFlucPrms[60] : packoffset(c11);
//   float fOLLtEfFade : packoffset(c70.y) = {0};
//   float3 vOLAmbEfScaler : packoffset(c71) = {1,1,1};
//   float3 vOLColorScaler : packoffset(c72) = {1,1,1};
//   float fOLCSatFade : packoffset(c72.w) = {0};
//   float fOLPtnFade : packoffset(c73) = {0};
// }
//
// SamplerState __smpsLit_s : register(s3);
// SamplerState __smpsOutlineColor_s : register(s4);
// Texture2D<float4> sLit : register(t3);
// Texture2D<float4> sOutlineColor : register(t4);
// Texture2D<float4> sOutlineAutoHDRScaleExposure : register(t6);
//
//
// // 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,
//   float4 v3 : TEXCOORD2,
//   nointerpolation int v4 : TEXCOORD3,
//   out float4 o0 : SV_Target0)
// {
//   const float4 icb[] = { { 0.031250, 0, 0, 0},
//                               { 0.531250, 0, 0, 0},
//                               { 0.156250, 0, 0, 0},
//                               { 0.656250, 0, 0, 0},
//                               { 0.781250, 0, 0, 0},
//                               { 0.281250, 0, 0, 0},
//                               { 0.906250, 0, 0, 0},
//                               { 0.406250, 0, 0, 0},
//                               { 0.218750, 0, 0, 0},
//                               { 0.718750, 0, 0, 0},
//                               { 0.093750, 0, 0, 0},
//                               { 0.593750, 0, 0, 0},
//                               { 0.968750, 0, 0, 0},
//                               { 0.468750, 0, 0, 0},
//                               { 0.843750, 0, 0, 0},
//                               { 0.343750, 0, 0, 0} };
//   float4 r0,r1,r2,r3;
//   uint4 bitmask, uiDest;
//   float4 fDest;
//
//   r0.xy = floor(v0.xy);
//   r0.z = (int)v4.x;
//   r0.z = 0.5 + r0.z;
//   r1.x = 0.00390625 * r0.z;
//   r1.y = 0.5;
//   r1.xyz = sOutlineColor.Sample(__smpsOutlineColor_s, r1.xy).xyz;
//   r0.z = sLit.Sample(__smpsLit_s, v3.xy).x;
//   r1.xyz = vOLColorScaler.xyz * r1.xyz;
//   r0.w = saturate(fOLLtEfFade);
//   r2.xyz = ambLit.xyz * vOLAmbEfScaler.xyz + float3(-1,-1,-1);
//   r2.xyz = r0.www * r2.xyz + float3(1,1,1);
//   r1.xyz = r2.xyz * r1.xyz;
//   r0.w = saturate(fOLPtnFade);
//   r0.z = -1 + r0.z;
//   r0.z = r0.w * r0.z + 1;
//   r1.xyz = r1.xyz * r0.zzz;
//   r0.z = max(r1.y, r1.z);
//   r0.z = max(r1.x, r0.z);
//   r0.z = saturate(-0.00196000002 + r0.z);
//   r2.xyz = cmp(r1.xyz >= r0.zzz);
//   r2.xyz = r2.xyz ? float3(1,1,1) : 0;
//   r0.z = saturate(fOLCSatFade);
//   r2.xyz = r1.xyz * r2.xyz + -r1.xyz;
//   r1.xyz = r0.zzz * r2.xyz + r1.xyz;
//   r0.z = sOutlineAutoHDRScaleExposure.Load(float4(0,0,0,0)).x;
//   r0.z = 1 / r0.z;
//   r0.z = min(3.40282306e+038, r0.z);
//   r2.xyz = r1.xyz * r0.zzz;
//   r0.w = 0;
//   r1.w = 0;
//   while (true) {
//     r2.w = cmp((int)r1.w >= 20);
//     if (r2.w != 0) break;
//     r2.w = v2.x * hFogFlucPrms[r1.w+12] + hFogFlucPrms[r1.w+13];
//     r2.w = 6.28318501 * r2.w;
//     r2.w = cos(r2.w);
//     r3.x = v2.z * hFogFlucPrms[r1.w+14] + hFogFlucPrms[r1.w+15];
//     r3.x = 6.28318501 * r3.x;
//     r3.x = cos(r3.x);
//     r2.w = r3.x + r2.w;
//     r0.w = r2.w * hFogFlucPrms[r1.w] + r0.w;
//     r1.w = (int)r1.w + 5;
//   }
//   r0.w = v2.y + r0.w;
//   r0.w = saturate(r0.w * hFogParam[0].x + hFogParam[0].y);
//   r1.w = -1.44269502 * r0.w;
//   r1.w = exp2(r1.w);
//   r1.w = 1 + -r1.w;
//   r3.xy = cmp(hFogType[0] == int2(1,2));
//   r2.w = r0.w * r0.w;
//   r2.w = -1.44269502 * r2.w;
//   r2.w = exp2(r2.w);
//   r2.w = 1 + -r2.w;
//   r2.w = r3.y ? r2.w : 0;
//   r1.w = r3.x ? r1.w : r2.w;
//   r0.w = hFogType[0] ? r1.w : r0.w;
//   r1.w = saturate(cHFog[0].w);
//   r0.w = r1.w * r0.w;
//   r1.w = saturate(v1.w * hFogParam[0].z + hFogParam[0].w);
//   r0.w = r1.w * r0.w;
//   r1.xyz = -r1.xyz * r0.zzz + cHFog[0].xyz;
//   r1.xyz = r0.www * r1.xyz + r2.xyz;
//   r0.zw = float2(0,0);
//   while (true) {
//     r1.w = cmp((int)r0.w >= 20);
//     if (r1.w != 0) break;
//     r1.w = v2.x * hFogFlucPrms[r0.w+32] + hFogFlucPrms[r0.w+33];
//     r1.w = 6.28318501 * r1.w;
//     r1.w = cos(r1.w);
//     r2.x = v2.z * hFogFlucPrms[r0.w+34] + hFogFlucPrms[r0.w+35];
//     r2.x = 6.28318501 * r2.x;
//     r2.x = cos(r2.x);
//     r1.w = r2.x + r1.w;
//     r0.z = r1.w * hFogFlucPrms[r0.w+31] + r0.z;
//     r0.w = (int)r0.w + 5;
//   }
//   r0.z = v2.y + r0.z;
//   r0.z = saturate(r0.z * hFogParam[1].x + hFogParam[1].y);
//   r0.w = -1.44269502 * r0.z;
//   r0.w = exp2(r0.w);
//   r0.w = 1 + -r0.w;
//   r2.xy = cmp(hFogType[1] == int2(1,2));
//   r1.w = r0.z * r0.z;
//   r1.w = -1.44269502 * r1.w;
//   r1.w = exp2(r1.w);
//   r1.w = 1 + -r1.w;
//   r1.w = r2.y ? r1.w : 0;
//   r0.w = r2.x ? r0.w : r1.w;
//   r0.z = hFogType[1] ? r0.w : r0.z;
//   r0.w = saturate(cHFog[1].w);
//   r0.z = r0.z * r0.w;
//   r0.w = saturate(v1.w * hFogParam[1].z + hFogParam[1].w);
//   r0.z = r0.z * r0.w;
//   r2.xyz = cHFog[1].xyz + -r1.xyz;
//   r1.xyz = r0.zzz * r2.xyz + r1.xyz;
//   r0.zw = float2(0,0);
//   while (true) {
//     r1.w = cmp((int)r0.w >= 20);
//     if (r1.w != 0) break;
//     r1.w = v2.x * hFogFlucPrms[r0.w+52] + hFogFlucPrms[r0.w+53];
//     r1.w = 6.28318501 * r1.w;
//     r1.w = cos(r1.w);
//     r2.x = v2.z * hFogFlucPrms[r0.w+54] + hFogFlucPrms[r0.w+55];
//     r2.x = 6.28318501 * r2.x;
//     r2.x = cos(r2.x);
//     r1.w = r2.x + r1.w;
//     r0.z = r1.w * hFogFlucPrms[r0.w+51] + r0.z;
//     r0.w = (int)r0.w + 5;
//   }
//   r0.z = v2.y + r0.z;
//   r0.z = saturate(r0.z * hFogParam[2].x + hFogParam[2].y);
//   r0.w = -1.44269502 * r0.z;
//   r0.w = exp2(r0.w);
//   r0.w = 1 + -r0.w;
//   r2.xy = cmp(hFogType[2] == int2(1,2));
//   r1.w = r0.z * r0.z;
//   r1.w = -1.44269502 * r1.w;
//   r1.w = exp2(r1.w);
//   r1.w = 1 + -r1.w;
//   r1.w = r2.y ? r1.w : 0;
//   r0.w = r2.x ? r0.w : r1.w;
//   r0.z = hFogType[2] ? r0.w : r0.z;
//   r0.w = saturate(cHFog[2].w);
//   r0.z = r0.z * r0.w;
//   r0.w = saturate(v1.w * hFogParam[2].z + hFogParam[2].w);
//   r0.z = r0.z * r0.w;
//   r2.xyz = cHFog[2].xyz + -r1.xyz;
//   o0.xyz = r0.zzz * r2.xyz + r1.xyz;
//   r0.xy = (uint2)r0.xy;
//   bitmask.y = ((~(-1 << 2)) << 2) & 0xffffffff;  r0.y = (((uint)r0.y << 2) & bitmask.y) | ((uint)0 & ~bitmask.y);
//   bitmask.x = ((~(-1 << 2)) << 0) & 0xffffffff;  r0.x = (((uint)r0.x << 0) & bitmask.x) | ((uint)r0.y & ~bitmask.x);
//   r0.x = -icb[r0.x+0].x + vDithAlp.w;
//   r0.x = cmp(r0.x < 0);
//   if (r0.x != 0) discard;
//   o0.w = 1;
//   return;
// }
//////////////////////////////// HLSL Errors ////////////////////////////////
// F:\SteamLibrary\steamapps\common\P5S\ShaderFixes\05d49f870fdf1f7a-ps_replace.txt(83,10-59): warning X3206: 'Load': implicit truncation of vector type
// F:\SteamLibrary\steamapps\common\P5S\ShaderFixes\05d49f870fdf1f7a-ps_replace.txt(161,43-63): error X3504: literal loop terminated early due to out of bounds array access
// F:\SteamLibrary\steamapps\common\P5S\ShaderFixes\05d49f870fdf1f7a-ps_replace.txt(155,3-14): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
/////////////////////////////////////////////////////////////////////////////
