// MOON HALOS

cbuffer cbLightShaft : register(b3)
{
  float4 g_SkyMaskParam : packoffset(c0);
  float4 g_SkyMaskBlurParam : packoffset(c1);
  float4 g_SkyMaskCenterVec : packoffset(c2);
  float4 g_SkyMultiplyColor : packoffset(c3);
  float4 g_SkyAddColor : packoffset(c4);
  float2 g_CameraFovTangent : packoffset(c5);
  float g_SceneColorSaturate : packoffset(c5.z);
  float g_SceneColorThreshold : packoffset(c5.w);
  float4 g_SkyMaskBlurParallelDir : packoffset(c6);
}

SamplerState SS_BlackBorderLinear_s : register(s3);
Texture2D<float4> g_SourceTexture : register(t0);


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


void main(
  float4 v0 : SV_Position0,
  float3 v1 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = -g_SkyMaskBlurParam.xy + v1.xy;
  float4 stereo = StereoParams.Load(0);
//r2.x += stereo.x * 0.5;
  
  r1.xyz = float3(0,0,0);
  r0.zw = float2(0,0);
  while (true) {
    r1.w = cmp((int)r0.w >= 8);
    if (r1.w != 0) break;
    r1.w = (int)r0.w;
    r1.w = 0.125 * r1.w;
    r2.x = g_SkyMaskBlurParam.z * -r1.w;
    r2.x = exp2(r2.x);
    r2.xy = r0.xy * r2.xx + g_SkyMaskBlurParam.xy;
	
    r1.w = g_SkyMaskBlurParam.w * r1.w;
    r1.w = exp2(r1.w);
    r2.xyz = g_SourceTexture.SampleLevel(SS_BlackBorderLinear_s, r2.xy, 0).xyz;
    r1.xyz = r2.xyz * r1.www + r1.xyz;
    r0.z = r1.w + r0.z;
    r0.w = (int)r0.w + 1;
  }
  o0.xyz = r1.xyz / r0.zzz;
  o0.w = 1;
  
  o0 = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//   using 3Dmigoto v1.3.14 on Fri Mar 22 23:10:31 2019
//
//
// Buffer Definitions:
//
// cbuffer cbLightShaft
// {
//
//   float4 g_SkyMaskParam;             // Offset:    0 Size:    16 [unused]
//   float4 g_SkyMaskBlurParam;         // Offset:   16 Size:    16
//   float4 g_SkyMaskCenterVec;         // Offset:   32 Size:    16 [unused]
//   float4 g_SkyMultiplyColor;         // Offset:   48 Size:    16 [unused]
//   float4 g_SkyAddColor;              // Offset:   64 Size:    16 [unused]
//   float2 g_CameraFovTangent;         // Offset:   80 Size:     8 [unused]
//   float g_SceneColorSaturate;        // Offset:   88 Size:     4 [unused]
//   float g_SceneColorThreshold;       // Offset:   92 Size:     4 [unused]
//   float4 g_SkyMaskBlurParallelDir;   // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SS_BlackBorderLinear              sampler      NA          NA    3        1
// g_SourceTexture                   texture  float4          2d    0        1
// cbLightShaft                      cbuffer      NA          NA    3        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xyz         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_constantbuffer cb3[2], immediateIndexed
dcl_sampler s3, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 3
add r0.xy, v1.xyxx, -cb3[1].xyxx
mov r1.xyz, l(0,0,0,0)
mov r0.zw, l(0,0,0,0)
loop
  ige r1.w, r0.w, l(8)
  breakc_nz r1.w
  itof r1.w, r0.w
  mul r1.w, r1.w, l(0.125000)
  mul r2.x, -r1.w, cb3[1].z
  exp r2.x, r2.x
  mad r2.xy, r0.xyxx, r2.xxxx, cb3[1].xyxx
  mul r1.w, r1.w, cb3[1].w
  exp r1.w, r1.w
  sample_l_indexable(texture2d)(float,float,float,float) r2.xyz, r2.xyxx, t0.xyzw, s3, l(0.000000)
  mad r1.xyz, r2.xyzx, r1.wwww, r1.xyzx
  add r0.z, r0.z, r1.w
  iadd r0.w, r0.w, l(1)
endloop
div o0.xyz, r1.xyzx, r0.zzzz
mov o0.w, l(1.000000)
ret
// Approximately 21 instruction slots used

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