// Lensflares VS - DSS correction

cbuffer cVSObject : register(b5)
{

  struct
  {
    float4x4 m_viewWorld;
    float4x4 m_world;
    float4 m_useWeightCount;
    float4 m_localParam[4];
  } g_vsObject : packoffset(c0);

}

cbuffer cVSLight : register(b3)
{

  struct
  {
    float4 m_lightDir0;
    float4 m_lightColor0;
    float4 m_lightColor1;
    float4 m_lightSourcePos;
    float4 m_lightSourceColor;
    float4 m_lightSourceDir;
    float4 m_lightSourceParam1;
    float4 m_lightSourceParam2;
    float4 m_lightSourceParam3;
    float4 m_lightPos0;
    float4 m_lightParam2;
  } g_vsLight : packoffset(c0);

}

cbuffer cVSWork : register(b7)
{

  struct
  {
    float4x4 m_viewInverse;
    float4x4 m_matrix[8];
  } g_vsWork : packoffset(c0);

}



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


void main( 
  float3 v0 : POSITION0,
  float4 v1 : COLOR0,
  float2 v2 : TEXCOORD0,
  out float4 o0 : COLOR1,
  out float2 o1 : TEXCOORD0,
  out float p1 : TEXCOORD2,
  out float4 o2 : TEXCOORD1,
  out float3 o3 : TEXCOORD3,
  out float4 o4 : SV_Position0)
{
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

  o0.xyzw = g_vsLight.m_lightColor1.xyzw;
  r0.xy = floor(v2.xy);
  o1.x = 0.0158730168 * r0.y;
  r0.xy = v2.xy + -r0.xy;
  o1.y = 1.01587307 * r0.y;
  o2.z = 1.06666672 * r0.x;
  r0.x = 0.0625 * v2.x;
  r0.x = floor(r0.x);
  r0.y = -r0.x * 16 + v2.x;
  r0.x = 0.0666666701 * r0.x;
  o2.x = r0.x;
  r0.x = floor(r0.y);
  o2.y = 0.0666666701 * r0.x;
  o2.w = v1.w;
  p1.x = v0.z;
  o3.xyz = v1.xyz;
  r0.xy = v0.xy;
  r0.z = 1;
  
  
  
  r1.x = dot(r0.xyz, g_vsObject.m_world._m00_m10_m30);
  r1.y = dot(r0.xyz, g_vsObject.m_world._m01_m11_m31);
  r1.z = dot(r0.xyz, g_vsObject.m_world._m02_m12_m32);
  r1.w = dot(r0.xyz, g_vsObject.m_world._m03_m13_m33);
  
  
  float4 stereo = StereoParams.Load(0);
  float4 iniParams = IniParams.Load(0);
  
  // Corrects placement & opacity -DSS:
  float adj = stereo.x * (v0.z - stereo.y) / v0.z / 2;
  r1.x += adj; // Placement
  o3.x += adj; // Opacity
   
  
  r0.x = dot(r1.xyzw, g_vsWork.m_matrix[0]._m00_m10_m20_m30);
  r0.y = dot(r1.xyzw, g_vsWork.m_matrix[0]._m01_m11_m21_m31);
  r0.z = dot(r1.xyzw, g_vsWork.m_matrix[0]._m02_m12_m22_m32);
  o4.w = dot(r1.xyzw, g_vsWork.m_matrix[0]._m03_m13_m23_m33);
  o4.xyz = r0.xyz * g_vsObject.m_localParam[0].xyz + g_vsObject.m_localParam[1].xyz;
  
  if (iniParams.z == 0)
  {
  o4 = 0;
  }
  
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.24 on Mon Jan 18 12:31:13 2016
//
//
// Buffer Definitions: 
//
// cbuffer cVSObject
// {
//
//   struct VSObject
//   {
//       
//       float4x4 m_viewWorld;          // Offset:    0
//       float4x4 m_world;              // Offset:   64
//       float4 m_useWeightCount;       // Offset:  128
//       float4 m_localParam[4];        // Offset:  144
//
//   } g_vsObject;                      // Offset:    0 Size:   208
//
// }
//
// cbuffer cVSLight
// {
//
//   struct VSLight
//   {
//       
//       float4 m_lightDir0;            // Offset:    0
//       float4 m_lightColor0;          // Offset:   16
//       float4 m_lightColor1;          // Offset:   32
//       float4 m_lightSourcePos;       // Offset:   48
//       float4 m_lightSourceColor;     // Offset:   64
//       float4 m_lightSourceDir;       // Offset:   80
//       float4 m_lightSourceParam1;    // Offset:   96
//       float4 m_lightSourceParam2;    // Offset:  112
//       float4 m_lightSourceParam3;    // Offset:  128
//       float4 m_lightPos0;            // Offset:  144
//       float4 m_lightParam2;          // Offset:  160
//
//   } g_vsLight;                       // Offset:    0 Size:   176
//
// }
//
// cbuffer cVSWork
// {
//
//   struct VSWork
//   {
//       
//       float4x4 m_viewInverse;        // Offset:    0
//       float4x4 m_matrix[8];          // Offset:   64
//
//   } g_vsWork;                        // Offset:    0 Size:   576
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// cVSLight                          cbuffer      NA          NA    3        1
// cVSObject                         cbuffer      NA          NA    5        1
// cVSWork                           cbuffer      NA          NA    7        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyz         0     NONE   float   xyz 
// COLOR                    0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 0   xy          2     NONE   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// COLOR                    1   xyzw        0     NONE   float   xyzw
// TEXCOORD                 0   xy          1     NONE   float   xy  
// TEXCOORD                 2     z         1     NONE   float     z 
// TEXCOORD                 1   xyzw        2     NONE   float   xyzw
// TEXCOORD                 3   xyz         3     NONE   float   xyz 
// SV_Position              0   xyzw        4      POS   float   xyzw
//
vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb5[11], immediateIndexed
dcl_constantbuffer cb3[3], immediateIndexed
dcl_constantbuffer cb7[8], immediateIndexed
dcl_input v0.xyz
dcl_input v1.xyzw
dcl_input v2.xy
dcl_output o0.xyzw
dcl_output o1.xy
dcl_output o1.z
dcl_output o2.xyzw
dcl_output o3.xyz
dcl_output_siv o4.xyzw, position
dcl_temps 2
mov o0.xyzw, cb3[2].xyzw
round_ni r0.xy, v2.xyxx
mul o1.x, r0.y, l(0.0158730168)
add r0.xy, -r0.xyxx, v2.xyxx
mul o1.y, r0.y, l(1.01587307)
mul o2.z, r0.x, l(1.06666672)
mul r0.x, v2.x, l(0.062500)
round_ni r0.x, r0.x
mad r0.y, -r0.x, l(16.000000), v2.x
mul r0.x, r0.x, l(0.0666666701)
mov o2.x, r0.x
round_ni r0.x, r0.y
mul o2.y, r0.x, l(0.0666666701)
mov o2.w, v1.w
mov o1.z, v0.z
mov o3.xyz, v1.xyzx
mov r0.xy, v0.xyxx
mov r0.z, l(1.000000)
dp3 r1.x, r0.xyzx, cb5[4].xywx
dp3 r1.y, r0.xyzx, cb5[5].xywx
dp3 r1.z, r0.xyzx, cb5[6].xywx
dp3 r1.w, r0.xyzx, cb5[7].xywx
dp4 r0.x, r1.xyzw, cb7[4].xyzw
dp4 r0.y, r1.xyzw, cb7[5].xyzw
dp4 r0.z, r1.xyzw, cb7[6].xyzw
dp4 o4.w, r1.xyzw, cb7[7].xyzw
mad o4.xyz, r0.xyzx, cb5[9].xyzx, cb5[10].xyzx
ret 
// Approximately 28 instruction slots used

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