// Lights

//NEW
cbuffer g_CameraVS_CB : register(b13)
{

  struct
  {
    row_major float4x4 vs_viewProj;
    row_major float4x4 vs_view;
    float4 vs_worldCamPos;
    float4 vs_projection_params;
    float4 vs_inverse_projection_xy;
    float4 vs_frustum_params;
    float4 vs_inverse_projection2;
    float4 vs_cameraOrigin;
  } g_CameraVS : packoffset(c0);

}

cbuffer g_Light_CB : register(b0)
{

  struct
  {
    float4 posDirRadius;
    float4 color;
    float4 params1;
    float4 params2;
    float4 params3;
    float4 projectedTexCoordUAxis;
    float4 projectedTexCoordVAxis;
    float4 fadeColor;
    row_major float4x4 spotViewProj;
  } g_Light : packoffset(c0);

}

SamplerState g_SceneDepthTex_ss_s : register(s0);
SamplerState g_AlbedoTex_ss_s : register(s6);
SamplerState g_AttenuationTex_ss_s : register(s9);
Texture2D<float4> g_SceneDepthTex : register(t0);
Texture2D<float4> g_AlbedoTex : register(t6);
Texture2D<float4> g_AttenuationTex : register(t9);


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


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

  r0.x = v2.w;
  r0.y = 0;
  r1.xyzw = v1.xyzw / v2.zzzz;
  r0.z = g_SceneDepthTex.SampleLevel(g_SceneDepthTex_ss_s, r1.xy, 0).x;
  r0.z = -r0.z * v2.y + 1;
  r2.z = v2.x / r0.z;
  r2.xy = r1.zw * r2.zz + r0.xy;
  
  float4 stereo = StereoParams.Load(0);
  r2.x -= stereo.x * (r2.z - stereo.y) * g_CameraVS.vs_inverse_projection_xy.x;
  
  r0.xyz = g_AlbedoTex.Sample(g_AlbedoTex_ss_s, r1.xy).xyz;
  r0.xyz = r0.xyz * r0.xyz;
  r1.xyz = g_Light.posDirRadius.xyz + -r2.xyz;
  r0.w = -g_Light.params2.x + r2.z;
  r0.w = saturate(g_Light.params2.y * r0.w);
  r0.w = 1 + -r0.w;
  r1.x = dot(r1.xyz, r1.xyz);
  r1.x = sqrt(r1.x);
  r1.x = g_Light.params1.z * r1.x;
  r1.y = g_Light.params3.w;
  r1.xyz = g_AttenuationTex.Sample(g_AttenuationTex_ss_s, r1.xy).xyz;
  r1.xyz = g_Light.posDirRadius.www * r1.xyz;
  r1.xyz = r1.xyz * r0.www;
  r1.xyz = max(float3(0,0,0), r1.xyz);
  r1.xyz = g_Light.color.xyz * r1.xyz;
  r1.xyz = r1.xyz * r1.xyz;
  o0.xyz = r1.xyz * r0.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.3.11 on Tue May 22 20:01:42 2018
//
//
// Buffer Definitions:
//
// cbuffer g_Light_CB
// {
//
//   struct Light
//   {
//
//       float4 posDirRadius;           // Offset:    0
//       float4 color;                  // Offset:   16
//       float4 params1;                // Offset:   32
//       float4 params2;                // Offset:   48
//       float4 params3;                // Offset:   64
//       float4 projectedTexCoordUAxis; // Offset:   80
//       float4 projectedTexCoordVAxis; // Offset:   96
//       float4 fadeColor;              // Offset:  112
//       row_major float4x4 spotViewProj;// Offset:  128
//
//   } g_Light;                         // Offset:    0 Size:   192
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_SceneDepthTex_ss                sampler      NA          NA    0        1
// g_AlbedoTex_ss                    sampler      NA          NA    6        1
// g_AttenuationTex_ss               sampler      NA          NA    9        1
// g_SceneDepthTex                   texture  float4          2d    0        1
// g_AlbedoTex                       texture  float4          2d    6        1
// g_AttenuationTex                  texture  float4          2d    9        1
// g_Light_CB                        cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 1   xyzw        2     NONE   float   xyzw
// TEXCOORD                 2   xyzw        3     NONE   float
//
//
// 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 cb0[5], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s6, mode_default
dcl_sampler s9, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t6
dcl_resource_texture2d (float,float,float,float) t9
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xyzw
dcl_output o0.xyzw
dcl_temps 3
mov r0.x, v2.w
mov r0.y, l(0)
div r1.xyzw, v1.xyzw, v2.zzzz
sample_l_indexable(texture2d)(float,float,float,float) r0.z, r1.xyxx, t0.yzxw, s0, l(0.000000)
mad r0.z, -r0.z, v2.y, l(1.000000)
div r2.z, v2.x, r0.z
mad r2.xy, r1.zwzz, r2.zzzz, r0.xyxx
sample_indexable(texture2d)(float,float,float,float) r0.xyz, r1.xyxx, t6.xyzw, s6
mul r0.xyz, r0.xyzx, r0.xyzx
add r1.xyz, -r2.xyzx, cb0[0].xyzx
add r0.w, r2.z, -cb0[3].x
mul_sat r0.w, r0.w, cb0[3].y
add r0.w, -r0.w, l(1.000000)
dp3 r1.x, r1.xyzx, r1.xyzx
sqrt r1.x, r1.x
mul r1.x, r1.x, cb0[2].z
mov r1.y, cb0[4].w
sample_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyxx, t9.xyzw, s9
mul r1.xyz, r1.xyzx, cb0[0].wwww
mul r1.xyz, r0.wwww, r1.xyzx
max r1.xyz, r1.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
mul r1.xyz, r1.xyzx, cb0[1].xyzx
mul r1.xyz, r1.xyzx, r1.xyzx
mul o0.xyz, r0.xyzx, r1.xyzx
mov o0.w, l(0)
ret
// Approximately 26 instruction slots used

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