//Chromatic aberration. Disabled alongside vignette.
// ---- Created with 3Dmigoto v1.3.16 on Sat Oct  2 10:59:33 2021

cbuffer fblock : register(b0)
{
  float4 renderpositiontoviewtexture : packoffset(c0);
  float4 lensparm : packoffset(c1);
}

SamplerState viewcolormap_samp_state_s : register(s0);
Texture2D<float4> viewcolormap_samp : register(t0);


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


void main(
  float4 v0 : SV_Position0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r10;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  float4 iniparams1 = IniParams.Load(int2(1,0));
  
  r0.xy = v0.xy * renderpositiontoviewtexture.zw + renderpositiontoviewtexture.xy;
  
  r10.xy = r0.xy;
  r10.x+=stereo.x*0.5;
  
  r0.zw = float2(-0.5,-0.5) + r0.xy;
  r0.z = dot(r0.zw, r0.zw);
  r0.w = 4 * r0.z;
  r1.x = saturate(lensparm.x * -0.100000001 + 0.479999989);
  r1.yzw = viewcolormap_samp.SampleLevel(viewcolormap_samp_state_s, r0.xy, 0).xyz;
  r1.x = cmp(r0.w < r1.x);
  if (r1.x != 0) {
    o0.xyz = r1.yzw;
    o0.w = 1;
    return;
  }
  r1.x = lensparm.x * -0.100000001 + 0.5;
  r2.x = saturate(r0.z * 4 + -lensparm.z);
  r2.y = 10 * lensparm.x * iniparams1.x;
  r2.yz = renderpositiontoviewtexture.zw * r2.yy;
  r3.xy = float2(0.5,0.5) * r2.yz;
  r2.yz = r2.yz * float2(2,2) + float2(1,1);
  
  //r2.y+=stereo.x;
  
  r3.zw = float2(1,1) + -r2.yz;
  r4.xy = -r3.zw + r0.xy;
  r2.yz = -r3.zw + r2.yz;
  r2.yz = saturate(r4.xy / r2.yz);
  r3.zw = float2(-0.5,-0.5) + r2.yz;
  
  
  
  r3.zw = r3.zw + r3.zw;
  r4.xyz = float3(0,0,0);
  r5.xyz = float3(0,0,0);
  r2.w = 0;
  while (true) {
    r4.w = cmp((int)r2.w >= 3);
    if (r4.w != 0) break;
    r4.w = (int)r2.w;
    r5.w = 0.5 * r4.w;
    r6.zw = r4.ww * float2(1.5,1.5) + float2(-1.5,-0.5);
    r6.y = 1 + -abs(r6.z);
    r6.x = 1 + -r6.w;
    r6.xyz = saturate(r6.xyz);
    r6.xyz = float3(-1,-1,-1) + r6.xyz;
    r6.xyz = lensparm.yyy * r6.xyz + float3(1,1,1);
    r5.xyz = r6.xyz + r5.xyz;
    r7.xy = r5.ww * r3.xy + r3.xy;
    r7.xy = r7.xy * r3.zw;
    r7.xy = r7.xy * float2(2,2) + r2.yz;
    r7.xy = r7.xy + -r0.xy;
    r7.xy = r2.xx * r7.xy + r0.xy;
    r7.xyz = viewcolormap_samp.SampleLevel(viewcolormap_samp_state_s, r7.xy, 0).xyz;
    r4.xyz = r6.xyz * r7.xyz + r4.xyz;
    r2.w = (int)r2.w + 1;
  }
  r2.xyz = r4.xyz / r5.xyz;
  r0.x = cmp(r0.w < r1.x);
  if (r0.x != 0) {
    r0.x = -r0.z * 4 + r1.x;
    r0.x = 50 * r0.x;
    r0.yzw = -r2.xyz + r1.yzw;
    r2.xyz = r0.xxx * r0.yzw + r2.xyz;
  }
  o0.xyz = r2.xyz;
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.16 on Sat Oct  2 10:59:33 2021
//
//
// Buffer Definitions:
//
// cbuffer fblock
// {
//
//   float4 renderpositiontoviewtexture;// Offset:    0 Size:    16
//   float4 lensparm;                   // Offset:   16 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// viewcolormap_samp_state           sampler      NA          NA    0        1
// viewcolormap_samp                 texture  float4          2d    0        1
// fblock                            cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   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[2], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 8
mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
add r0.zw, r0.xxxy, l(0.000000, 0.000000, -0.500000, -0.500000)
dp2 r0.z, r0.zwzz, r0.zwzz
mul r0.w, r0.z, l(4.000000)
mad_sat r1.x, cb0[1].x, l(-0.100000), l(0.480000)
sample_l_indexable(texture2d)(float,float,float,float) r1.yzw, r0.xyxx, t0.wxyz, s0, l(0.000000)
lt r1.x, r0.w, r1.x
if_nz r1.x
  mov o0.xyz, r1.yzwy
  mov o0.w, l(1.000000)
  ret
endif
mad r1.x, cb0[1].x, l(-0.100000), l(0.500000)
mad_sat r2.x, r0.z, l(4.000000), -cb0[1].z
mul r2.y, cb0[1].x, l(10.000000)
mul r2.yz, r2.yyyy, cb0[0].zzwz
mul r3.xy, r2.yzyy, l(0.500000, 0.500000, 0.000000, 0.000000)
mad r2.yz, r2.yyzy, l(0.000000, 2.000000, 2.000000, 0.000000), l(0.000000, 1.000000, 1.000000, 0.000000)
add r3.zw, -r2.yyyz, l(0.000000, 0.000000, 1.000000, 1.000000)
add r4.xy, r0.xyxx, -r3.zwzz
add r2.yz, r2.yyzy, -r3.zzwz
div_sat r2.yz, r4.xxyx, r2.yyzy
add r3.zw, r2.yyyz, l(0.000000, 0.000000, -0.500000, -0.500000)
add r3.zw, r3.zzzw, r3.zzzw
mov r4.xyz, l(0,0,0,0)
mov r5.xyz, l(0,0,0,0)
mov r2.w, l(0)
loop
  ige r4.w, r2.w, l(3)
  breakc_nz r4.w
  itof r4.w, r2.w
  mul r5.w, r4.w, l(0.500000)
  mad r6.zw, r4.wwww, l(0.000000, 0.000000, 1.500000, 1.500000), l(0.000000, 0.000000, -1.500000, -0.500000)
  add r6.y, -|r6.z|, l(1.000000)
  add r6.x, -r6.w, l(1.000000)
  mov_sat r6.xyz, r6.xyzx
  add r6.xyz, r6.xyzx, l(-1.000000, -1.000000, -1.000000, 0.000000)
  mad r6.xyz, cb0[1].yyyy, r6.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
  add r5.xyz, r5.xyzx, r6.xyzx
  mad r7.xy, r5.wwww, r3.xyxx, r3.xyxx
  mul r7.xy, r3.zwzz, r7.xyxx
  mad r7.xy, r7.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), r2.yzyy
  add r7.xy, -r0.xyxx, r7.xyxx
  mad r7.xy, r2.xxxx, r7.xyxx, r0.xyxx
  sample_l_indexable(texture2d)(float,float,float,float) r7.xyz, r7.xyxx, t0.xyzw, s0, l(0.000000)
  mad r4.xyz, r6.xyzx, r7.xyzx, r4.xyzx
  iadd r2.w, r2.w, l(1)
endloop
div r2.xyz, r4.xyzx, r5.xyzx
lt r0.x, r0.w, r1.x
if_nz r0.x
  mad r0.x, -r0.z, l(4.000000), r1.x
  mul r0.x, r0.x, l(50.000000)
  add r0.yzw, r1.yyzw, -r2.xxyz
  mad r2.xyz, r0.xxxx, r0.yzwy, r2.xyzx
endif
mov o0.xyz, r2.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 59 instruction slots used

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