// Sun flares
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.3.15 on Mon Mar 11 09:54:02 2019
//
//
// Buffer Definitions:
//
// cbuffer cbComposite
// {
//
//   float4 g_vSceneTexSize;            // Offset:    0 Size:    16
//   float4 g_vCompositeInfo;           // Offset:   16 Size:    16
//   float4 g_vSun2dInfo;               // Offset:   32 Size:    16
//   float4 g_vEtcEffect;               // Offset:   48 Size:    16
//   float4 g_vBloomInfo;               // Offset:   64 Size:    16 [unused]
//   float4 g_vLimbDarkenningInfo;      // Offset:   80 Size:    16
//   float4 g_vFxaaParams;              // Offset:   96 Size:    16 [unused]
//   float4 g_vGammaCorrection;         // Offset:  112 Size:    16
//   float4 g_vRadialBlurCenter;        // Offset:  128 Size:    16
//   float4 g_vRadialBlurInfo;          // Offset:  144 Size:    16 [unused]
//   float4 g_vFxaaQualityParams;       // Offset:  160 Size:    16 [unused]
//   float4 g_vCompositeLastViewport;   // Offset:  176 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sampleLinear                      sampler      NA          NA    7        1
// g_tSceneMap                       texture  float4          2d    0        1
// g_tLensFlareMap                   texture  float4          2d    1        1
// g_tExposureScaleInfo              texture  float4          2d    2        1
// g_tHdrLut                         texture  float4          3d    3        1
// g_tLdrLut                         texture  float4          3d    4        1
// cbComposite                       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   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_immediateConstantBuffer { { 0, 0, 1.000000, 0},
                              { 0, 1.000000, 0, 0},
                              { 1.000000, 0, 0, 0},
                              { 1.000000, 0, 0, 0},
                              { 0, 1.000000, 0, 0},
                              { 0, 0, 1.000000, 0},
                              { 0, 1.000000, 0, 0},
                              { 1.000000, 0, 0, 0},
                              { 1.000000, 0, 1.000000, 0},
                              { 1.000000, 0, 1.000000, 0},
                              { 1.000000, 0, 0, 0},
                              { 0, 1.000000, 0, 0} }
dcl_constantbuffer cb2[12], immediateIndexed
dcl_sampler s7, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture3d (float,float,float,float) t3
dcl_resource_texture3d (float,float,float,float) t4
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 15

dcl_resource_texture2d (float,float,float,float) t121
ld_indexable(texture2d)(float,float,float,float) r12.xyzw, l(0, 0, 0, 0), t121.xyzw

// Correct g_vSun2dInfo, which is used to sample the sun buffer to check if the
// sun is obscured or not to determine whether to draw the flares. If the
// ShaderRegex to do this is applied the main shaft type flares get half
// adjusted from another shader
mov r13.xyzw, cb2[2].xyzw
mad r13.x, r12.x, l(0.5), r13.x

// Create a copy of the texcoord only used with the flares to move them to
// infinity.
mov r14.xy, v1.xyxx
mad r14.x, r12.x, l(-0.5), r14.x
mad r14.xz, r14.xxyx, cb2[11].zzwz, cb2[11].xxyx

lt r0.x, l(0.000000), r13.z
lt r0.y, l(0.000000), cb2[5].w
lt r0.z, cb2[1].z, l(0.000000)
ld_indexable(texture2d)(float,float,float,float) r0.w, l(0, 0, 0, 0), t2.yzwx
lt r1.xy, l(0.000000, 0.000000, 0.000000, 0.000000), cb2[1].zyzz
movc r1.x, r1.x, cb2[1].z, l(1.000000)
movc r0.z, r0.z, r0.w, r1.x
mad r1.xz, v1.xxyx, cb2[11].zzwz, cb2[11].xxyx
sample_l_indexable(texture2d)(float,float,float,float) r2.xyz, r1.xzxx, t0.xyzw, s7, l(0.000000)
min r2.xyz, r2.xyzx, l(65024.000000, 65024.000000, 65024.000000, 0.000000)
lt r0.w, l(0.000000), cb2[3].x
if_nz r0.w
  ftou r0.w, cb2[3].y
  mad r3.xy, r1.xzxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
  dp2 r1.w, r3.xyxx, r3.xyxx
  mul r3.xy, r1.wwww, r3.xyxx
  mul r3.xy, r3.xyxx, cb2[3].xxxx
  mul r3.zw, -r3.xxxy, cb2[0].xxxy
  mul r3.zw, r3.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000)
  dp2 r1.w, r3.zwzz, r3.zwzz
  sqrt r1.w, r1.w
  ftoi r1.w, r1.w
  imax r1.w, r1.w, l(3)
  imin r1.w, r1.w, l(16)
  itof r2.w, r1.w
  div r3.xy, -r3.xyxx, r2.wwww
  mul r4.xyz, r2.xyzx, icb[r0.w + 0].xyzx
  iadd r3.zw, r0.wwww, l(0, 0, 1, 2)
  add r5.xyz, -icb[r0.w + 0].xyzx, icb[r3.z + 0].xyzx
  add r6.xyz, -icb[r3.z + 0].xyzx, icb[r3.w + 0].xyzx
  mov r7.xyz, r4.xyzx
  mov r8.xyz, icb[r0.w + 0].xyzx
  mov r9.xy, r1.xzxx
  mov r3.w, l(1)
  loop
    ige r4.w, r3.w, r1.w
    breakc_nz r4.w
    add r9.xy, r3.xyxx, r9.xyxx
    sample_l_indexable(texture2d)(float,float,float,float) r10.xyz, r9.xyxx, t0.xyzw, s7, l(0.000000)
    min r10.xyz, r10.xyzx, l(65024.000000, 65024.000000, 65024.000000, 0.000000)
    itof r4.w, r3.w
    div r4.w, r4.w, r2.w
    lt r5.w, r4.w, l(0.500000)
    if_nz r5.w
      add r5.w, r4.w, r4.w
      mad r11.xyz, r5.wwww, r5.xyzx, icb[r0.w + 0].xyzx
    else
      mad r4.w, r4.w, l(2.000000), l(-1.000000)
      mad r11.xyz, r4.wwww, r6.xyzx, icb[r3.z + 0].xyzx
    endif
    mad r7.xyz, r10.xyzx, r11.xyzx, r7.xyzx
    add r8.xyz, r8.xyzx, r11.xyzx
    iadd r3.w, r3.w, l(1)
  endloop
  div r2.xyz, r7.xyzx, r8.xyzx
endif
mul r2.xyz, r0.zzzz, r2.xyzx
if_nz r0.x
  sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r13.xyxx, t0.xyzw, s7, l(0.000000)
  min r3.xyz, r3.xyzx, l(65024.000000, 65024.000000, 65024.000000, 0.000000)
  mul r0.xzw, r0.zzzz, r3.xxyz
// lens flare:
  //sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r1.xzxx, t1.xyzw, s7, l(0.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r14.xzxx, t1.xyzw, s7, l(0.000000)
  min r3.xyz, r3.xyzx, l(65024.000000, 65024.000000, 65024.000000, 0.000000)
  dp3 r1.w, r0.xzwx, l(0.222015, 0.706655, 0.071330, 0.000000)
  lt r1.w, cb2[3].w, r1.w
  and r1.w, r1.w, cb2[3].z
  mul r0.xzw, r0.xxzw, r3.xxyz
  mad r2.xyz, r0.xzwx, r1.wwww, r2.xyzx
endif
if_nz r0.y
  add r0.yz, r1.xxzx, l(0.000000, -0.500000, -0.500000, 0.000000)
  mul r0.x, r0.y, cb2[1].x
  dp2 r0.x, r0.xzxx, r0.xzxx
  sqrt r0.y, r0.x
  add r0.y, r0.y, -cb2[5].y
  lt r0.z, l(0.000000), r0.y
  mad_sat r0.y, -r0.y, cb2[5].z, l(1.000000)
  movc r0.y, r0.z, r0.y, l(1.000000)
  lt r0.z, l(0.000000), r0.y
  add r0.x, r0.x, cb2[5].x
  div r0.x, cb2[5].x, r0.x
  mul r0.x, r0.x, r0.x
  movc r0.x, r0.z, r0.x, l(1.000000)
  mul r0.x, r0.y, r0.x
  add r0.y, -cb2[5].w, l(1.000000)
  mad r0.x, r0.x, cb2[5].w, r0.y
  mul r2.xyz, r0.xxxx, r2.xyzx
endif
mad r0.xyz, r2.xyzx, l(5.555556, 5.555556, 5.555556, 0.000000), l(0.047996, 0.047996, 0.047996, 0.000000)
log r0.xyz, r0.xyzx
mad_sat r0.xyz, r0.xyzx, l(0.0734997839, 0.0734997839, 0.0734997839, 0.000000), l(0.386036, 0.386036, 0.386036, 0.000000)
sample_l_indexable(texture3d)(float,float,float,float) r0.xyz, r0.xyzx, t3.xyzw, s7, l(0.000000)
if_nz r1.y
  mov_sat r1.xyz, r0.xyzx
  sample_l_indexable(texture3d)(float,float,float,float) r1.xyz, r1.xyzx, t4.xyzw, s7, l(0.000000)
  add r1.xyz, -r0.xyzx, r1.xyzx
  mad r0.xyz, cb2[1].yyyy, r1.xyzx, r0.xyzx
endif
ne r0.w, cb2[7].x, l(1.000000)
log r1.xyz, |r0.xyzx|
mul r1.xyz, r1.xyzx, cb2[7].xxxx
exp r1.xyz, r1.xyzx
movc r0.xyz, r0.wwww, r1.xyzx, r0.xyzx
mul o0.xyz, r0.xyzx, cb2[8].zzzz
mov o0.w, l(1.000000)
ret
// Approximately 106 instruction slots used
