// HDR

cbuffer _Globals : register(b0)
{
  float3 sunPosScreen : packoffset(c0);
}

cbuffer cPerFrame : register(b6)
{
  float4 gFrameParams : packoffset(c0);
  float4 gSunDiffuse : packoffset(c1);
  float4 gSunAmbient : packoffset(c2);
  float3 gSunDir : packoffset(c3);
  float gSunAttenuation : packoffset(c3.w);
  float4 gMoonDiffuse : packoffset(c4);
  float3 gMoonDir : packoffset(c5);
  float gSeaLevel : packoffset(c5.w);
  float4 gSreenParams : packoffset(c6);
  float4 gFogCoeffs : packoffset(c7);
  float3 gFogColor : packoffset(c8);
  float unused : packoffset(c8.w);
}

cbuffer cPerView : register(b7)
{
  float4x4 gView : packoffset(c0);
  float4x4 gViewInv : packoffset(c4);
  float4x4 gProj : packoffset(c8);
  float4x4 gProjInv : packoffset(c12);
  float4x4 gViewProj : packoffset(c16);
  float4x4 gViewProjInv : packoffset(c20);
  float4x4 gNormViewProj : packoffset(c24);
  float4x4 gCloudShadowsProj : packoffset(c28);
  float4x4 gClipCockpit : packoffset(c32);
  float4 gSunDirV : packoffset(c36);
  float3 gOrigin : packoffset(c37);
  float gCameraHeightAbs : packoffset(c37.w);
  float3 gCameraPos : packoffset(c38);
  float gFogCameraHeightNorm : packoffset(c38.w);
  float4 gNearFarFovZoom : packoffset(c39);
}
//this line is making error with 3Dmigoto
//StructuredBuffer<lensData> lensData : register(t0);


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


void main( 
  uint v0 : SV_VertexID0,
  out float4 o0 : SV_POSITION0,
  out float4 o1 : TEXCOORD0)
{
  const float4 icb[] = { { -1.000000, 1.000000, 0, 0},
                              { 1.000000, 1.000000, 0, 0},
                              { -1.000000, -1.000000, 0, 0},
                              { 1.000000, -1.000000, 0, 0} };
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;
  float z1 = IniParams.Load(int2(1, 0)).z;
  float w1 = IniParams.Load(int2(1, 0)).w;

  r0.x = max(0, gSunDirV.z);
  r0.x = log2(r0.x);
  r0.x = 30 * r0.x;
  r0.x = exp2(r0.x);
  r0.x = r0.x * 1.5 + 1;
  r0.y = v0.x;
  r0.zw = icb[r0.y+0].xy * float2(0.800000012,0.800000012);
  o1.xy = icb[r0.y+0].xy * float2(0.5,0.5) + float2(0.5,0.5);
float4 stereo = StereoParams.Load(0);
float4 iniParams = IniParams.Load(0);
o1.x-= stereo.x * (1 - stereo.y +z1/3);    
  r0.yz = r0.zw * r0.xx;
  r0.x = r0.y / sunPosScreen.z;
  o0.xy = sunPosScreen.xy + r0.xz; 
  o0.zw = float2(0,1);
  r0.x = -0.100000001 + gSunDirV.z;
  r0.x = max(0, r0.x);
  r0.x = 1.11099994 * r0.x;
  r0.y = r0.x * r0.x;
  r0.x = r0.x * r0.y;
// Known bad code for instruction (needs manual fix):
// ld_structured r1.x, l(0), l(0), t0.xxxx
//this line is making error with 3Dmigoto, so the value is replacing by w1
//r1.x = lensData[]..swiz;
r1.x=w1;
  r0.x = r1.x * r0.x;
  o1.z = 0.5 * r0.x;
  r0.x = gSunDiffuse.x + gSunDiffuse.y;
  r0.x = gSunDiffuse.z + r0.x;
  r0.x = r0.x * 0.333000004 + -0.400000006;
  o1.w = 1.66659999 * r0.x;
  // o0.xyzw=float4(0,0,0,0);
  // o1.xyzw=float4(0,0,0,0);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.21 on Sun Jan 17 17:43:20 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float3 sunPosScreen;               // Offset:    0 Size:    12
//
// }
//
// cbuffer cPerFrame
// {
//
//   float4 gFrameParams;               // Offset:    0 Size:    16 [unused]
//   float4 gSunDiffuse;                // Offset:   16 Size:    16
//   float4 gSunAmbient;                // Offset:   32 Size:    16 [unused]
//   float3 gSunDir;                    // Offset:   48 Size:    12 [unused]
//   float gSunAttenuation;             // Offset:   60 Size:     4 [unused]
//   float4 gMoonDiffuse;               // Offset:   64 Size:    16 [unused]
//   float3 gMoonDir;                   // Offset:   80 Size:    12 [unused]
//   float gSeaLevel;                   // Offset:   92 Size:     4 [unused]
//   float4 gSreenParams;               // Offset:   96 Size:    16 [unused]
//   float4 gFogCoeffs;                 // Offset:  112 Size:    16 [unused]
//   float3 gFogColor;                  // Offset:  128 Size:    12 [unused]
//   float unused;                      // Offset:  140 Size:     4 [unused]
//
// }
//
// cbuffer cPerView
// {
//
//   float4x4 gView;                    // Offset:    0 Size:    64 [unused]
//   float4x4 gViewInv;                 // Offset:   64 Size:    64 [unused]
//   float4x4 gProj;                    // Offset:  128 Size:    64 [unused]
//   float4x4 gProjInv;                 // Offset:  192 Size:    64 [unused]
//   float4x4 gViewProj;                // Offset:  256 Size:    64 [unused]
//   float4x4 gViewProjInv;             // Offset:  320 Size:    64 [unused]
//   float4x4 gNormViewProj;            // Offset:  384 Size:    64 [unused]
//   float4x4 gCloudShadowsProj;        // Offset:  448 Size:    64 [unused]
//   float4x4 gClipCockpit;             // Offset:  512 Size:    64 [unused]
//   float4 gSunDirV;                   // Offset:  576 Size:    16
//   float3 gOrigin;                    // Offset:  592 Size:    12 [unused]
//   float gCameraHeightAbs;            // Offset:  604 Size:     4 [unused]
//   float3 gCameraPos;                 // Offset:  608 Size:    12 [unused]
//   float gFogCameraHeightNorm;        // Offset:  620 Size:     4 [unused]
//   float4 gNearFarFovZoom;            // Offset:  624 Size:    16 [unused]
//
// }
//
// Resource bind info for lensData
// {
//
//   struct
//   {
//       
//       float2 params;                 // Offset:    0
//
//   } $Element;                        // Offset:    0 Size:     8
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// lensData                          texture  struct         r/o    0        1
// $Globals                          cbuffer      NA          NA    0        1
// cPerFrame                         cbuffer      NA          NA    6        1
// cPerView                          cbuffer      NA          NA    7        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_VertexID              0   x           0   VERTID    uint   x   
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xyzw
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
//
vs_4_0
dcl_globalFlags refactoringAllowed | enableRawAndStructuredBuffers
dcl_immediateConstantBuffer { { -1.000000, 1.000000, 0, 0},
                              { 1.000000, 1.000000, 0, 0},
                              { -1.000000, -1.000000, 0, 0},
                              { 1.000000, -1.000000, 0, 0} }
dcl_constantbuffer cb0[1], immediateIndexed
dcl_constantbuffer cb6[2], immediateIndexed
dcl_constantbuffer cb7[37], immediateIndexed
dcl_resource_structured t0, 8 
dcl_input_sgv v0.x, vertex_id
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
dcl_temps 2
max r0.x, cb7[36].z, l(0.000000)
log r0.x, r0.x
mul r0.x, r0.x, l(30.000000)
exp r0.x, r0.x
mad r0.x, r0.x, l(1.500000), l(1.000000)
mov r0.y, v0.x
mul r0.zw, l(0.000000, 0.000000, 0.800000, 0.800000), icb[r0.y + 0].xxxy
mad o1.xy, icb[r0.y + 0].xyxx, l(0.500000, 0.500000, 0.000000, 0.000000), l(0.500000, 0.500000, 0.000000, 0.000000)
mul r0.yz, r0.xxxx, r0.zzwz
div r0.x, r0.y, cb0[0].z
add o0.xy, r0.xzxx, cb0[0].xyxx
mov o0.zw, l(0,0,0,1.000000)
add r0.x, cb7[36].z, l(-0.100000)
max r0.x, r0.x, l(0.000000)
mul r0.x, r0.x, l(1.111000)
mul r0.y, r0.x, r0.x
mul r0.x, r0.y, r0.x
ld_structured r1.x, l(0), l(0), t0.xxxx
mul r0.x, r0.x, r1.x
mul o1.z, r0.x, l(0.500000)
add r0.x, cb6[1].y, cb6[1].x
add r0.x, r0.x, cb6[1].z
mad r0.x, r0.x, l(0.333000), l(-0.400000)
mul o1.w, r0.x, l(1.666600)
ret 
// Approximately 25 instruction slots used

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