//Radial blur (distortion). Standalone.
// ---- Created with 3Dmigoto v1.3.16 on Sat Oct  2 10:11:51 2021

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

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,r10;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  r0.xy = v0.xy * renderpositiontoviewtexture.zw + renderpositiontoviewtexture.xy;
  
  r0.z = lensparm.x * renderpositiontoviewtexture.z;
  r0.zw = float2(5,750) * r0.zz;
  r1.x = lensparm2.y * r0.w;
  r0.w = dot(lensparm2.xx, r0.ww);
  r0.w = 1 + r0.w;
  r0.w = r1.x * 4 + r0.w;
  r0.w = r0.w * 0.5 + 0.5;
  r1.x = cmp(0 < lensparm2.x);
  r1.y = 1 + -r0.w;
  r1.zw = -r1.yy + r0.xy;
  r0.w = -r1.y + r0.w;
  r1.yz = saturate(r1.zw / r0.ww);
  r0.xy = r1.xx ? r1.yz : r0.xy;
  
  r10.xy = r0.xy;
  
  r10.x-=stereo.x*0.5;
  
  r0.w = dot(r0.xy, float2(12.9898005,78.2330017));
  r0.w = sin(r0.w);
  r0.w = 43758.5469 * r0.w;
  r0.w = frac(r0.w);
  r0.xy = r0.xy * float2(2,2) + float2(-1,-1);
  
  r10.xy = r10.xy * float2(2,2) + float2(-1,-1);
  
  
  
  r1.x = dot(r10.xy, r10.xy);
  r1.y = r1.x * r1.x;
  r2.xyz = float3(0,0,0);
  r3.xyz = float3(0,0,0);
  r1.z = 0;
  while (true) {
    r1.w = cmp((int)r1.z >= 16);
    if (r1.w != 0) break;
    r1.w = (int)r1.z;
    r1.w = r1.w + r0.w;
    r2.w = r1.w * r0.z;
    r4.zw = r1.ww * float2(0.200000018,0.200000018) + float2(-1.5,-0.5);
    r4.y = 1 + -abs(r4.z);
    r4.x = 1 + -r4.w;
    r4.xyz = saturate(r4.xyz);
    r4.xyz = float3(-1,-1,-1) + r4.xyz;
    r4.xyz = lensparm.yyy * r4.xyz + float3(1,1,1);
    r3.xyz = r4.xyz + r3.xyz;
    r1.w = r2.w * 0.0666666701 + r0.z;
    r1.w = 75 * r1.w;
    r5.xy = lensparm2.xy * r1.ww;
    r1.w = r5.x * r1.x + 1;
    r1.w = r1.y * r5.y + r1.w;
    r5.xy = r1.ww * r0.xy;
    r5.xy = r5.xy * float2(0.5,0.5) + float2(0.5,0.5);
    r5.xyz = viewcolormap_samp.SampleLevel(viewcolormap_samp_state_s, r5.xy, 0).xyz;
    r2.xyz = r4.xyz * r5.xyz + r2.xyz;
    r1.z = (int)r1.z + 1;
  }
  o0.xyz = r2.xyz / r3.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:11:51 2021
//
//
// Buffer Definitions:
//
// cbuffer fblock
// {
//
//   float4 renderpositiontoviewtexture;// Offset:    0 Size:    16
//   float4 lensparm;                   // Offset:   16 Size:    16
//   float4 lensparm2;                  // Offset:   32 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[3], 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 6
mad r0.xy, v0.xyxx, cb0[0].zwzz, cb0[0].xyxx
mul r0.z, cb0[0].z, cb0[1].x
mul r0.zw, r0.zzzz, l(0.000000, 0.000000, 5.000000, 750.000000)
mul r1.x, r0.w, cb0[2].y
dp2 r0.w, cb0[2].xxxx, r0.wwww
add r0.w, r0.w, l(1.000000)
mad r0.w, r1.x, l(4.000000), r0.w
mad r0.w, r0.w, l(0.500000), l(0.500000)
lt r1.x, l(0.000000), cb0[2].x
add r1.y, -r0.w, l(1.000000)
add r1.zw, r0.xxxy, -r1.yyyy
add r0.w, r0.w, -r1.y
div_sat r1.yz, r1.zzwz, r0.wwww
movc r0.xy, r1.xxxx, r1.yzyy, r0.xyxx
dp2 r0.w, r0.xyxx, l(12.989800, 78.233002, 0.000000, 0.000000)
sincos r0.w, null, r0.w
mul r0.w, r0.w, l(43758.546875)
frc r0.w, r0.w
mad r0.xy, r0.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
dp2 r1.x, r0.xyxx, r0.xyxx
mul r1.y, r1.x, r1.x
mov r2.xyz, l(0,0,0,0)
mov r3.xyz, l(0,0,0,0)
mov r1.z, l(0)
loop
  ige r1.w, r1.z, l(16)
  breakc_nz r1.w
  itof r1.w, r1.z
  add r1.w, r0.w, r1.w
  mul r2.w, r0.z, r1.w
  mad r4.zw, r1.wwww, l(0.000000, 0.000000, 0.200000018, 0.200000018), l(0.000000, 0.000000, -1.500000, -0.500000)
  add r4.y, -|r4.z|, l(1.000000)
  add r4.x, -r4.w, l(1.000000)
  mov_sat r4.xyz, r4.xyzx
  add r4.xyz, r4.xyzx, l(-1.000000, -1.000000, -1.000000, 0.000000)
  mad r4.xyz, cb0[1].yyyy, r4.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
  add r3.xyz, r3.xyzx, r4.xyzx
  mad r1.w, r2.w, l(0.0666666701), r0.z
  mul r1.w, r1.w, l(75.000000)
  mul r5.xy, r1.wwww, cb0[2].xyxx
  mad r1.w, r5.x, r1.x, l(1.000000)
  mad r1.w, r1.y, r5.y, r1.w
  mul r5.xy, r0.xyxx, r1.wwww
  mad r5.xy, r5.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r5.xyz, r5.xyxx, t0.xyzw, s0, l(0.000000)
  mad r2.xyz, r4.xyzx, r5.xyzx, r2.xyzx
  iadd r1.z, r1.z, l(1)
endloop
div o0.xyz, r2.xyzx, r3.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 51 instruction slots used

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