//Sun and lens flares PS. P5S too.
// ---- Created with 3Dmigoto v1.3.16 on Sat Feb 06 00:52:56 2021

cbuffer cbFlare : register(b2)
{
  float4 g_vLensFlareInfo : packoffset(c0);
  float4 g_vSun2dInfo : packoffset(c1);
  float4 g_vScreenInfo : packoffset(c2);
  float4 g_vLensHaloInfo0 : packoffset(c3);
  float4 g_vLensHaloInfo1 : packoffset(c4);
  float4 g_vAnamorphicCoat : packoffset(c5);
}

SamplerState sampleStarBurst_s : register(s1);
Texture2D<float4> g_tStarBurstBaseMap : register(t1);


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


void main(
  float4 v0 : SV_Position0,
  float2 v1 : TEXCOORD0,
  float2 w1 : TEXCOORD1,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r10;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  r10.xyzw=g_vSun2dInfo.xyzw;
  //r10.x+=stereo.x;
  
  r0.x = 0.5 * g_vSun2dInfo.w;
  r0.yz = r10.xy * float2(0.5,-0.5) + float2(0.5,0.5);
  r1.x = g_vScreenInfo.x;
  r1.y = 1;
  r1.zw = g_vLensFlareInfo.xx * r1.xy;
  
  //r0.y+=stereo.x*0.5;
  
  r2.xy = w1.xy + -r0.yz;
  r1.zw = r2.xy * r1.zw + float2(0.5,0.5);
  r2.xyz = g_tStarBurstBaseMap.Sample(sampleStarBurst_s, r1.zw).xyz;
  r1.zw = r0.yz * float2(2,2) + float2(-0.5,-0.5);
  
  
  
  r1.zw = -w1.xy + r1.zw;
  r1.xy = r1.zw * r1.xy;
  r0.w = dot(r1.xy, r1.xy);
  r0.w = rsqrt(r0.w);
  r1.xy = r1.xy * r0.ww;
  r0.w = 0.5 * g_vLensHaloInfo0.w;
  r1.xy = r1.xy * abs(r0.ww);
  r1.x = g_vScreenInfo.y * r1.x;
  r0.w = g_vLensHaloInfo1.x + -g_vLensHaloInfo1.y;
  r1.zw = r1.xy * r0.ww;
  
  
  
  r1.xy = w1.xy + r1.xy;
  r3.xy = r1.xy * g_vLensHaloInfo1.yy + r1.zw;
  r3.zw = -r1.yx * g_vLensHaloInfo1.yy + r0.zy;
  
  r3.xy = -r3.xy + r0.yz;
  r0.w = dot(r1.zw, r1.zw);
  r2.w = rsqrt(r0.w);
  r4.xy = r2.ww * r1.zw;
  
  r2.w = dot(r4.yx, r3.zw);
  r4.z = cmp(r2.w < 0);
  r4.w = dot(r3.zw, r3.zw);
  r4.w = sqrt(r4.w);
  r0.w = sqrt(r0.w);
  r0.w = cmp(r0.w < r2.w);
  r2.w = dot(r3.xy, r3.xy);
  r2.w = sqrt(r2.w);
  r3.x = r4.y * r3.w;
  r3.x = r4.x * r3.z + -r3.x;
  r0.w = r0.w ? r2.w : abs(r3.x);
  r0.w = r4.z ? r4.w : r0.w;
  r0.x = cmp(r0.w < r0.x);
  if (r0.x != 0) {
    r0.xw = float2(0.333333343,0.333333343) * r1.zw;
	
    r3.xy = r1.xy * g_vLensHaloInfo1.yy + -r0.yz;
    r2.w = dot(r3.xy, r3.xy);
    r2.w = sqrt(r2.w);
    r3.x = -g_vLensFlareInfo.w * 2 + r2.w;
    r2.w = -r3.x + r2.w;
    r3.x = g_vSun2dInfo.w * 0.5 + -r3.x;
    r2.w = 1 / r2.w;
    r2.w = saturate(r3.x * r2.w);
    r3.x = r2.w * -2 + 3;
    r2.w = r2.w * r2.w;
    r2.w = r3.x * r2.w;
    r0.xw = r1.xy * g_vLensHaloInfo1.yy + r0.xw;
	
    r1.xy = r0.xw + -r0.yz;
    r1.x = dot(r1.xy, r1.xy);
    r1.x = sqrt(r1.x);
    r1.y = -g_vLensFlareInfo.w * 2 + r1.x;
    r1.x = r1.x + -r1.y;
    r1.y = g_vSun2dInfo.w * 0.5 + -r1.y;
    r1.x = 1 / r1.x;
    r1.x = saturate(r1.y * r1.x);
    r1.y = r1.x * -2 + 3;
    r1.x = r1.x * r1.x;
    r1.x = r1.y * r1.x;
    r3.xyz = float3(0,1,0) * r1.xxx;
    r3.xyz = r2.www * float3(0,0,1) + r3.xyz;
    r0.xw = r1.zw * float2(0.333333343,0.333333343) + r0.xw;
    r0.xy = r0.xw + -r0.yz;
    r0.x = dot(r0.xy, r0.xy);
    r0.x = sqrt(r0.x);
    r0.y = -g_vLensFlareInfo.w * 2 + r0.x;
    r0.x = r0.x + -r0.y;
    r0.y = g_vSun2dInfo.w * 0.5 + -r0.y;
    r0.x = 1 / r0.x;
    r0.x = saturate(r0.y * r0.x);
    r0.y = r0.x * -2 + 3;
    r0.x = r0.x * r0.x;
    r0.x = r0.y * r0.x;
    r0.xyz = r0.xxx * float3(1,0,0) + r3.xyz;
    r0.xyz = g_vLensHaloInfo0.xyz * r0.xyz;
    r0.xyz = float3(16,16,16) * r0.xyz;
  } else {
    r0.xyz = float3(0,0,0);
  }
  o0.xyz = r2.xyz + r0.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.3.16 on Sat Feb 06 00:52:56 2021
//
//
// Buffer Definitions:
//
// cbuffer cbFlare
// {
//
//   float4 g_vLensFlareInfo;           // Offset:    0 Size:    16
//   float4 g_vSun2dInfo;               // Offset:   16 Size:    16
//   float4 g_vScreenInfo;              // Offset:   32 Size:    16
//   float4 g_vLensHaloInfo0;           // Offset:   48 Size:    16
//   float4 g_vLensHaloInfo1;           // Offset:   64 Size:    16
//   float4 g_vAnamorphicCoat;          // Offset:   80 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sampleStarBurst                   sampler      NA          NA    1        1
// g_tStarBurstBaseMap               texture  float4          2d    1        1
// cbFlare                           cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xy          1     NONE   float
// TEXCOORD                 1     zw        1     NONE   float     zw
//
//
// 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 cb2[5], immediateIndexed
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v1.zw
dcl_output o0.xyzw
dcl_temps 5
mul r0.x, cb2[1].w, l(0.500000)
mad r0.yz, cb2[1].xxyx, l(0.000000, 0.500000, -0.500000, 0.000000), l(0.000000, 0.500000, 0.500000, 0.000000)
mov r1.x, cb2[2].x
mov r1.y, l(1.000000)
mul r1.zw, r1.xxxy, cb2[0].xxxx
add r2.xy, -r0.yzyy, v1.zwzz
mad r1.zw, r2.xxxy, r1.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000)
sample_indexable(texture2d)(float,float,float,float) r2.xyz, r1.zwzz, t1.xyzw, s1
mad r1.zw, r0.yyyz, l(0.000000, 0.000000, 2.000000, 2.000000), l(0.000000, 0.000000, -0.500000, -0.500000)
add r1.zw, r1.zzzw, -v1.zzzw
mul r1.xy, r1.xyxx, r1.zwzz
dp2 r0.w, r1.xyxx, r1.xyxx
rsq r0.w, r0.w
mul r1.xy, r0.wwww, r1.xyxx
mul r0.w, cb2[3].w, l(0.500000)
mul r1.xy, |r0.wwww|, r1.xyxx
mul r1.x, r1.x, cb2[2].y
add r0.w, -cb2[4].y, cb2[4].x
mul r1.zw, r0.wwww, r1.xxxy
add r1.xy, r1.xyxx, v1.zwzz
mad r3.xy, r1.xyxx, cb2[4].yyyy, r1.zwzz
mad r3.zw, -r1.yyyx, cb2[4].yyyy, r0.zzzy
add r3.xy, r0.yzyy, -r3.xyxx
dp2 r0.w, r1.zwzz, r1.zwzz
rsq r2.w, r0.w
mul r4.xy, r1.zwzz, r2.wwww
dp2 r2.w, r4.yxyy, r3.zwzz
lt r4.z, r2.w, l(0.000000)
dp2 r4.w, r3.zwzz, r3.zwzz
sqrt r4.w, r4.w
sqrt r0.w, r0.w
lt r0.w, r0.w, r2.w
dp2 r2.w, r3.xyxx, r3.xyxx
sqrt r2.w, r2.w
mul r3.x, r3.w, r4.y
mad r3.x, r4.x, r3.z, -r3.x
movc r0.w, r0.w, r2.w, |r3.x|
movc r0.w, r4.z, r4.w, r0.w
lt r0.x, r0.w, r0.x
if_nz r0.x
  mul r0.xw, r1.zzzw, l(0.333333343, 0.000000, 0.000000, 0.333333343)
  mad r3.xy, r1.xyxx, cb2[4].yyyy, -r0.yzyy
  dp2 r2.w, r3.xyxx, r3.xyxx
  sqrt r2.w, r2.w
  mad r3.x, -cb2[0].w, l(2.000000), r2.w
  add r2.w, r2.w, -r3.x
  mad r3.x, cb2[1].w, l(0.500000), -r3.x
  div r2.w, l(1.000000, 1.000000, 1.000000, 1.000000), r2.w
  mul_sat r2.w, r2.w, r3.x
  mad r3.x, r2.w, l(-2.000000), l(3.000000)
  mul r2.w, r2.w, r2.w
  mul r2.w, r2.w, r3.x
  mad r0.xw, r1.xxxy, cb2[4].yyyy, r0.xxxw
  add r1.xy, -r0.yzyy, r0.xwxx
  dp2 r1.x, r1.xyxx, r1.xyxx
  sqrt r1.x, r1.x
  mad r1.y, -cb2[0].w, l(2.000000), r1.x
  add r1.x, -r1.y, r1.x
  mad r1.y, cb2[1].w, l(0.500000), -r1.y
  div r1.x, l(1.000000, 1.000000, 1.000000, 1.000000), r1.x
  mul_sat r1.x, r1.x, r1.y
  mad r1.y, r1.x, l(-2.000000), l(3.000000)
  mul r1.x, r1.x, r1.x
  mul r1.x, r1.x, r1.y
  mul r3.xyz, r1.xxxx, l(0.000000, 1.000000, 0.000000, 0.000000)
  mad r3.xyz, r2.wwww, l(0.000000, 0.000000, 1.000000, 0.000000), r3.xyzx
  mad r0.xw, r1.zzzw, l(0.333333343, 0.000000, 0.000000, 0.333333343), r0.xxxw
  add r0.xy, -r0.yzyy, r0.xwxx
  dp2 r0.x, r0.xyxx, r0.xyxx
  sqrt r0.x, r0.x
  mad r0.y, -cb2[0].w, l(2.000000), r0.x
  add r0.x, -r0.y, r0.x
  mad r0.y, cb2[1].w, l(0.500000), -r0.y
  div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
  mul_sat r0.x, r0.x, r0.y
  mad r0.y, r0.x, l(-2.000000), l(3.000000)
  mul r0.x, r0.x, r0.x
  mul r0.x, r0.x, r0.y
  mad r0.xyz, r0.xxxx, l(1.000000, 0.000000, 0.000000, 0.000000), r3.xyzx
  mul r0.xyz, r0.xyzx, cb2[3].xyzx
  mul r0.xyz, r0.xyzx, l(16.000000, 16.000000, 16.000000, 0.000000)
else
  mov r0.xyz, l(0,0,0,0)
endif
add o0.xyz, r0.xyzx, r2.xyzx
mov o0.w, l(0)
ret
// Approximately 87 instruction slots used

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