// Lights MSAA 2x

cbuffer _Globals : register(b4)
{
  float2 gm_vTextureSizeInv : packoffset(c0);
  float4 g_vParams0 : packoffset(c1);
  float4 g_vParams1 : packoffset(c2);
  float4 g_vLPVDimension : packoffset(c3);
  row_major float4x4 g_mLightProjToView : packoffset(c4);
  row_major float4x4 g_mLightViewToLPV : packoffset(c8);
  row_major float4x4 g_mLightViewToWorld : packoffset(c12);
  row_major float4x4 g_mInverseProjection : packoffset(c16);
  row_major float4x4 g_mViewToLPV : packoffset(c20);
  float4 g_mBackBufferSize : packoffset(c24);
}

cbuffer _cbSharedPerViewData : register(b1)
{

  struct
  {
    row_major float4x4 mProjection;
    row_major float4x4 mViewToViewport;
    row_major float4x4 mViewToWorld;
    float4 vViewRemap;
    float4 vViewDepthRemap;
    float4 vEyeVectorUL;
    float4 vEyeVectorLR;
    float4 v4ShadowRange;
    float4 vViewSpaceUpVector;
    float4 vGlobalLitFactor;
    float4 vViewportSize;
    float4 vEngineTime;
    float4 vShaderColor0;
    float4 vShaderColor1;
    float4 vShaderColor2;
    float4 vShaderColor3;
    float4 vShaderColor4;
    float4 vClipPlane;
  } cbSharedPerViewData : packoffset(c0);

}

SamplerState samplerLPV_RedTrilinear_s : register(s0);
SamplerState samplerLPV_GreenTrilinear_s : register(s1);
SamplerState samplerLPV_BlueTrilinear_s : register(s2);
Texture2D<float4> mapLPV_RedTrilinear : register(t0);
Texture2D<float4> mapLPV_GreenTrilinear : register(t1);
Texture2D<float4> mapLPV_BlueTrilinear : register(t2);
Texture2DMS<float4,2> mapDepthMsaa2 : register(t3);
Texture2DMS<float4,2> mapNormalsMsaa2 : register(t4);
Texture2DMS<float4,2> mapDiffuseMsaa2 : register(t5);


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


void main( 
  float4 v0 : SV_POSITION0,
  float4 v1 : COLOR0,
  float2 v2 : TEXCOORD0,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.x = 1 + -g_vParams1.x;
  r0.yzw = cbSharedPerViewData.vEyeVectorLR.xyz + -cbSharedPerViewData.vEyeVectorUL.xyz;
  r1.xy = v2.xy;
  r1.z = 1;
  r0.yzw = r1.xyz * r0.yzw + cbSharedPerViewData.vEyeVectorUL.xyz;
  r1.xy = (int2)v0.xy;
  r1.zw = float2(0,0);
  r2.xyzw = mapDepthMsaa2.Load(r1.xy, 0).xyzw;
  r1.z = cbSharedPerViewData.vViewRemap.z * r2.x + -cbSharedPerViewData.vViewRemap.y;
  r1.z = 1 / r1.z;
  r0.yzw = r1.zzz * r0.yzw;
  
  float4 r22;
  r22.w = r1.z;
  
  
  r2.xyz = g_mViewToLPV._m10_m11_m12 * r0.zzz;
  r2.xyz = r0.yyy * g_mViewToLPV._m00_m01_m02 + r2.xyz;
  r0.yzw = r0.www * g_mViewToLPV._m20_m21_m22 + r2.xyz;
  r0.yzw = g_mViewToLPV._m30_m31_m32 + r0.yzw;
  r2.xyz = -g_vParams1.xxx + abs(r0.yzw);
  r2.xyz = saturate(r2.xyz / r0.xxx);
  r3.xyz = r2.xyz * float3(-2,-2,-2) + float3(3,3,3);
  r2.xyz = r2.xyz * r2.xyz;
  r2.xyz = r3.xyz * r2.xyz;
  r0.x = max(r2.x, r2.y);
  r0.x = max(r0.x, r2.z);
  r0.x = 1 + -r0.x;
  r2.xyzw = mapNormalsMsaa2.Load(r1.xy, 0).xyzw;
  r1.xyzw = mapDiffuseMsaa2.Load(r1.xy, 0).xyzw;
  r2.xyz = float3(-0.5,-0.5,-0.5) + r2.xyz;
  r2.xyz = r2.xyz + r2.xyz;
  r3.xyz = g_mViewToLPV._m11_m12_m10 * -r2.yyy;
  r2.xyw = -r2.xxx * g_mViewToLPV._m01_m02_m00 + r3.xyz;
  r2.xyz = -r2.zzz * g_mViewToLPV._m21_m22_m20 + r2.xyw;
  
  float4 stereo = StereoParams.Load(0);
  r2.x -= stereo.x * (r22.w  - stereo.y) / -cbSharedPerViewData.mProjection._m00;
  
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r2.yzw = float3(-1.02332675,1.02332675,-1.02332675) * r2.xyz;
  r3.xyz = float3(1,1,1) + r0.yzw;
  r4.z = g_vLPVDimension.z;
  r4.x = 0.5;
  r3.xz = r4.xz * r3.xz;
  r1.w = 0.5 * r3.z;
  r3.z = floor(r1.w);
  r1.w = frac(r1.w);
  r3.y = r3.y * r4.x + r3.z;
  r3.w = r3.y / g_vLPVDimension.z;
  r3.y = 1 + r3.y;
  r4.y = r3.y / g_vLPVDimension.z;
  r5.xyzw = mapLPV_RedTrilinear.Sample(samplerLPV_RedTrilinear_s, r3.xw).xyzw;
  r4.x = r3.x;
  r6.xyzw = mapLPV_RedTrilinear.Sample(samplerLPV_RedTrilinear_s, r4.xy).xyzw;
  r6.xyzw = r6.xyzw * r1.wwww;
  r3.y = 1 + -r1.w;
  r5.xyzw = r3.yyyy * r5.xyzw + r6.xyzw;
  r2.x = 0.886226952;
  r3.z = dot(r2.xyzw, r5.xyzw);
  r5.x = max(0, r3.z);
  r6.xyzw = mapLPV_GreenTrilinear.Sample(samplerLPV_GreenTrilinear_s, r3.xw).xyzw;
  r7.xyzw = mapLPV_BlueTrilinear.Sample(samplerLPV_BlueTrilinear_s, r3.xw).xyzw;
  r8.xyzw = mapLPV_GreenTrilinear.Sample(samplerLPV_GreenTrilinear_s, r4.xy).xyzw;
  r4.xyzw = mapLPV_BlueTrilinear.Sample(samplerLPV_BlueTrilinear_s, r4.xy).xyzw;
  r4.xyzw = r4.xyzw * r1.wwww;
  r8.xyzw = r8.xyzw * r1.wwww;
  r6.xyzw = r3.yyyy * r6.xyzw + r8.xyzw;
  r3.xyzw = r3.yyyy * r7.xyzw + r4.xyzw;
  r1.w = dot(r2.xyzw, r3.xyzw);
  r2.x = dot(r2.xyzw, r6.xyzw);
  r5.y = max(0, r2.x);
  r5.z = max(0, r1.w);
  r2.xyz = r5.xyz * r0.xxx;
  r1.xyz = r2.xyz * r1.xyz;
  r2.xyz = cmp(float3(-1,-1,-1) >= r0.yzw);
  r0.xyz = cmp(r0.yzw >= float3(1,1,1));
  r0.xyz = (int3)r0.xyz | (int3)r2.xyz;
  r0.x = (int)r0.x | (int)r0.y;
  r0.x = (int)r0.x | (int)r0.z;
  o0.xyz = r0.xxx ? float3(0,0,0) : r1.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v1.2.19 on Sun Jan 17 12:34:42 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float2 gm_vTextureSizeInv;         // Offset:    0 Size:     8 [unused]
//   float4 g_vParams0;                 // Offset:   16 Size:    16 [unused]
//   float4 g_vParams1;                 // Offset:   32 Size:    16
//   float4 g_vLPVDimension;            // Offset:   48 Size:    16
//   row_major float4x4 g_mLightProjToView;// Offset:   64 Size:    64 [unused]
//   row_major float4x4 g_mLightViewToLPV;// Offset:  128 Size:    64 [unused]
//   row_major float4x4 g_mLightViewToWorld;// Offset:  192 Size:    64 [unused]
//   row_major float4x4 g_mInverseProjection;// Offset:  256 Size:    64 [unused]
//   row_major float4x4 g_mViewToLPV;   // Offset:  320 Size:    64
//   float4 g_mBackBufferSize;          // Offset:  384 Size:    16 [unused]
//
// }
//
// cbuffer _cbSharedPerViewData
// {
//
//   struct
//   {
//       
//       row_major float4x4 mProjection;// Offset:    0
//       row_major float4x4 mViewToViewport;// Offset:   64
//       row_major float4x4 mViewToWorld;// Offset:  128
//       float4 vViewRemap;             // Offset:  192
//       float4 vViewDepthRemap;        // Offset:  208
//       float4 vEyeVectorUL;           // Offset:  224
//       float4 vEyeVectorLR;           // Offset:  240
//       float4 v4ShadowRange;          // Offset:  256
//       float4 vViewSpaceUpVector;     // Offset:  272
//       float4 vGlobalLitFactor;       // Offset:  288
//       float4 vViewportSize;          // Offset:  304
//       float4 vEngineTime;            // Offset:  320
//       float4 vShaderColor0;          // Offset:  336
//       float4 vShaderColor1;          // Offset:  352
//       float4 vShaderColor2;          // Offset:  368
//       float4 vShaderColor3;          // Offset:  384
//       float4 vShaderColor4;          // Offset:  400
//       float4 vClipPlane;             // Offset:  416
//
//   } cbSharedPerViewData;             // Offset:    0 Size:   432
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samplerLPV_RedTrilinear           sampler      NA          NA    0        1
// samplerLPV_GreenTrilinear         sampler      NA          NA    1        1
// samplerLPV_BlueTrilinear          sampler      NA          NA    2        1
// mapLPV_RedTrilinear               texture  float4          2d    0        1
// mapLPV_GreenTrilinear             texture  float4          2d    1        1
// mapLPV_BlueTrilinear              texture  float4          2d    2        1
// mapDepthMsaa2                     texture  float4       2dMS2    3        1
// mapNormalsMsaa2                   texture  float4       2dMS2    4        1
// mapDiffuseMsaa2                   texture  float4       2dMS2    5        1
// _cbSharedPerViewData              cbuffer      NA          NA    1        1
// $Globals                          cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float   xy  
// COLOR                    0   xyzw        1     NONE   float       
// TEXCOORD                 0   xy          2     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 cb4[24], immediateIndexed
dcl_constantbuffer cb1[16], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture2dms(2) (float,float,float,float) t3
dcl_resource_texture2dms(2) (float,float,float,float) t4
dcl_resource_texture2dms(2) (float,float,float,float) t5
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 9
add r0.x, -cb4[2].x, l(1.000000)
add r0.yzw, -cb1[14].xxyz, cb1[15].xxyz
mov r1.xy, v2.xyxx
mov r1.z, l(1.000000)
mad r0.yzw, r1.xxyz, r0.yyzw, cb1[14].xxyz
ftoi r1.xy, v0.xyxx
mov r1.zw, l(0,0,0,0)
ldms r2.xyzw, r1.xyzw, t3.xyzw, l(0)
mad r1.z, cb1[12].z, r2.x, -cb1[12].y
div r1.z, l(1.000000, 1.000000, 1.000000, 1.000000), r1.z
mul r0.yzw, r0.yyzw, r1.zzzz
mul r2.xyz, r0.zzzz, cb4[21].xyzx
mad r2.xyz, r0.yyyy, cb4[20].xyzx, r2.xyzx
mad r0.yzw, r0.wwww, cb4[22].xxyz, r2.xxyz
add r0.yzw, r0.yyzw, cb4[23].xxyz
add r2.xyz, |r0.yzwy|, -cb4[2].xxxx
div_sat r2.xyz, r2.xyzx, r0.xxxx
mad r3.xyz, r2.xyzx, l(-2.000000, -2.000000, -2.000000, 0.000000), l(3.000000, 3.000000, 3.000000, 0.000000)
mul r2.xyz, r2.xyzx, r2.xyzx
mul r2.xyz, r2.xyzx, r3.xyzx
max r0.x, r2.y, r2.x
max r0.x, r2.z, r0.x
add r0.x, -r0.x, l(1.000000)
ldms r2.xyzw, r1.xyww, t4.xyzw, l(0)
ldms r1.xyzw, r1.xyww, t5.xyzw, l(0)
add r2.xyz, r2.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
add r2.xyz, r2.xyzx, r2.xyzx
mul r3.xyz, -r2.yyyy, cb4[21].yzxy
mad r2.xyw, -r2.xxxx, cb4[20].yzyx, r3.xyxz
mad r2.xyz, -r2.zzzz, cb4[22].yzxy, r2.xywx
dp3 r1.w, r2.xyzx, r2.xyzx
rsq r1.w, r1.w
mul r2.xyz, r1.wwww, r2.xyzx
mul r2.yzw, r2.xxyz, l(0.000000, -1.02332675, 1.02332675, -1.02332675)
add r3.xyz, r0.yzwy, l(1.000000, 1.000000, 1.000000, 0.000000)
mov r4.z, cb4[3].z
mov r4.x, l(0.500000)
mul r3.xz, r3.xxzx, r4.xxzx
mul r1.w, r3.z, l(0.500000)
round_ni r3.z, r1.w
frc r1.w, r1.w
mad r3.y, r3.y, r4.x, r3.z
div r3.w, r3.y, cb4[3].z
add r3.y, r3.y, l(1.000000)
div r4.y, r3.y, cb4[3].z
sample r5.xyzw, r3.xwxx, t0.xyzw, s0
mov r4.x, r3.x
sample r6.xyzw, r4.xyxx, t0.xyzw, s0
mul r6.xyzw, r1.wwww, r6.xyzw
add r3.y, -r1.w, l(1.000000)
mad r5.xyzw, r3.yyyy, r5.xyzw, r6.xyzw
mov r2.x, l(0.886226952)
dp4 r3.z, r2.xyzw, r5.xyzw
max r5.x, r3.z, l(0.000000)
sample r6.xyzw, r3.xwxx, t1.xyzw, s1
sample r7.xyzw, r3.xwxx, t2.xyzw, s2
sample r8.xyzw, r4.xyxx, t1.xyzw, s1
sample r4.xyzw, r4.xyxx, t2.xyzw, s2
mul r4.xyzw, r1.wwww, r4.xyzw
mul r8.xyzw, r1.wwww, r8.xyzw
mad r6.xyzw, r3.yyyy, r6.xyzw, r8.xyzw
mad r3.xyzw, r3.yyyy, r7.xyzw, r4.xyzw
dp4 r1.w, r2.xyzw, r3.xyzw
dp4 r2.x, r2.xyzw, r6.xyzw
max r5.y, r2.x, l(0.000000)
max r5.z, r1.w, l(0.000000)
mul r2.xyz, r0.xxxx, r5.xyzx
mul r1.xyz, r1.xyzx, r2.xyzx
ge r2.xyz, l(-1.000000, -1.000000, -1.000000, 0.000000), r0.yzwy
ge r0.xyz, r0.yzwy, l(1.000000, 1.000000, 1.000000, 0.000000)
or r0.xyz, r0.xyzx, r2.xyzx
or r0.x, r0.x, r0.y
or r0.x, r0.x, r0.z
movc o0.xyz, r0.xxxx, l(0,0,0,0), r1.xyzx
mov o0.w, l(0)
ret 
// Approximately 76 instruction slots used

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