// sun halo

cbuffer _Globals : register(b0)
{
  float4x4 matView : packoffset(c0);
  float4x4 matProj : packoffset(c4);
  float3 sunDir : packoffset(c8);
  float3 cameraPos : packoffset(c9);
}

SamplerState gAnisotropicClampSampler_s : register(s14);
Texture2D<float4> sunTexture : register(t0);


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


void main( 
  float4 v0 : SV_POSITION0,
  float2 v1 : TEXCOORD0,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2;
  uint4 bitmask, uiDest;
  float4 fDest;
  float z1 = IniParams.Load(int2(1, 0)).z;
  float4 stereo = StereoParams.Load(0);

  r0.x = sunDir.y * 2 + matView._m00;
  r0.x = matView._m11 + r0.x;
  r0.x = matView._m22 + r0.x;
  sincos(r0.x, r0.x, r1.x);
  r2.z = r0.x;
  r2.y = r1.x;
  r2.x = -r0.x;
  r0.xy = float2(-0.5,-0.5) + v1.xy;
  r1.x = dot(r0.xy, r2.yz);
  r1.y = dot(r0.xy, r2.xy);
  r0.xy = float2(0.5,0.5) + r1.xy;
  r0.xyzw = sunTexture.Sample(gAnisotropicClampSampler_s, r0.xy).xyzw;
  r1.xyzw = sunTexture.Sample(gAnisotropicClampSampler_s, v1.xy-float2(z1*stereo.x,0.0)).xyzw;
  //r0.xyzw = r1.xyzw + r0.xyzw;
r0.xyzw = r1.xyzw *2;  
  r0.xyzw = saturate(float4(0.400000006,0.400000006,0.400000006,0.400000006) * r0.xyzw);
  r0.xyzw = log2(r0.xyzw);
  r0.xyzw = float4(1.75,1.75,1.75,1.75) * r0.xyzw;
  r0.xyzw = exp2(r0.xyzw);
  r1.x = -cameraPos.y * 0.5 + 1.5;
  r1.x = max(0.100000001, r1.x);
  r1.y = log2(sunDir.y);
  r1.x = r1.x * r1.y;
  r1.x = exp2(r1.x);
  o0.w = r1.x * r0.w;
  o0.xyz = r0.xyz;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.21 on Thu Jan 21 20:42:26 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4x4 matView;                  // Offset:    0 Size:    64
//   float4x4 matProj;                  // Offset:   64 Size:    64 [unused]
//   float3 sunDir;                     // Offset:  128 Size:    12
//   float3 cameraPos;                  // Offset:  144 Size:    12
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// gAnisotropicClampSampler          sampler      NA          NA   14        1
// sunTexture                        texture  float4          2d    0        1
// $Globals                          cbuffer      NA          NA    0        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_4_0
dcl_constantbuffer cb0[10], immediateIndexed
dcl_sampler s14, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
dcl_temps 3
mad r0.x, cb0[8].y, l(2.000000), cb0[0].x
add r0.x, r0.x, cb0[1].y
add r0.x, r0.x, cb0[2].z
sincos r0.x, r1.x, r0.x
mov r2.z, r0.x
mov r2.y, r1.x
mov r2.x, -r0.x
add r0.xy, v1.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
dp2 r1.x, r0.xyxx, r2.yzyy
dp2 r1.y, r0.xyxx, r2.xyxx
add r0.xy, r1.xyxx, l(0.500000, 0.500000, 0.000000, 0.000000)
sample r0.xyzw, r0.xyxx, t0.xyzw, s14
sample r1.xyzw, v1.xyxx, t0.xyzw, s14
add r0.xyzw, r0.xyzw, r1.xyzw
mul_sat r0.xyzw, r0.xyzw, l(0.400000, 0.400000, 0.400000, 0.400000)
log r0.xyzw, r0.xyzw
mul r0.xyzw, r0.xyzw, l(1.750000, 1.750000, 1.750000, 1.750000)
exp r0.xyzw, r0.xyzw
mad r1.x, -cb0[9].y, l(0.500000), l(1.500000)
max r1.x, r1.x, l(0.100000)
log r1.y, cb0[8].y
mul r1.x, r1.y, r1.x
exp r1.x, r1.x
mul o0.w, r0.w, r1.x
mov o0.xyz, r0.xyzx
ret 
// Approximately 26 instruction slots used

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