//Shadows no MSAA
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);

}

cbuffer _cbSharedLightData : register(b2)
{

  struct
  {
    float4 vParams0;
    float4 vParams1;
    float4 vParams2;
    float4 vLightDiffuse;
    float4 vHalfLightBoxFadeNeg;
    float4 vHalfLightBoxFadePos;
    float4 vRcpLightBoxFadeNeg;
    float4 vRcpLightBoxFadePos;
    float4 vLightPosView;
    float4 vLightDirView;
    float4 vProjectorTilingOffset;
    row_major float4x4 mViewToShadowProjTrans;
    row_major float4x4 mViewToLightProjTrans;
    float4 vLightParams;
    float4 vRestrictLightBoxVectorX;
    float4 vRestrictLightBoxVectorY;
    float4 vRestrictLightBoxVectorZ;
    float4 vRestrictLightBoxPosition;
  } cbSharedLightData : packoffset(c0);

}
SamplerState samplerLightModel_s : register(s0);
SamplerState samplerLightProjectorMap0_s : register(s1);
SamplerState samplerShadowColor0BWhite_s : register(s2);
SamplerState samplerShadowColor1BWhite_s : register(s3);
SamplerState samplerShadowColor2BWhite_s : register(s4);
SamplerState samplerDeferred0_s : register(s5);
SamplerState samplerDeferred1_s : register(s6);
SamplerState samplerDeferred2_s : register(s7);
SamplerState samplerDeferred3_s : register(s8);
Texture2D<float4> mapLightModel : register(t0);
Texture2D<float4> mapLightProjectorMap0 : register(t1);
Texture2D<float4> mapShadowColor0BWhite : register(t2);
Texture2D<float4> mapShadowColor1BWhite : register(t3);
Texture2D<float4> mapShadowColor2BWhite : register(t4);
Texture2D<float4> mapDeferred0 : register(t5);
Texture2D<float4> mapDeferred1 : register(t6);
Texture2D<float4> mapDeferred2 : register(t7);
Texture2D<float4> mapDeferred3 : register(t8);

Texture2D<float4> StereoParams : register(t125);
Texture1D<float4> IniParams : register(t120);

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

  r0.x = 1 / v1.w;
  r0.yzw = v2.xyz * r0.xxx;
  r1.xy = v1.xy * r0.xx;
  r2.xyzw = mapDeferred0.Sample(samplerDeferred0_s, r1.xy).xyzw;
  r0.x = cbSharedPerViewData.vViewRemap.z * r2.x + -cbSharedPerViewData.vViewRemap.y;
  r0.x = 1 / r0.x;
  r0.xyz = r0.xxx * r0.yzw;
  
  float4 stereo = StereoParams.Load(0);
  r0.x -= stereo.x * (r0.x - stereo.y) / cbSharedPerViewData.mProjection._m00; 
  
  r2.xyz = cbSharedLightData.mViewToShadowProjTrans._m10_m11_m12 * r0.yyy;
  r2.xyz = r0.xxx * cbSharedLightData.mViewToShadowProjTrans._m00_m01_m02 + r2.xyz;
  r2.xyz = r0.zzz * cbSharedLightData.mViewToShadowProjTrans._m20_m21_m22 + r2.xyz;
  r2.xyz = cbSharedLightData.mViewToShadowProjTrans._m30_m31_m32 + r2.xyz;
  r3.xyz = cbSharedLightData.vHalfLightBoxFadePos.xyz * r2.xyz + cbSharedLightData.vRcpLightBoxFadePos.xyz;
  r4.xyzw = mapShadowColor2BWhite.SampleLevel(samplerShadowColor2BWhite_s, r3.xy, 0).xyzw;
  r0.w = saturate(-r4.x * r4.x + r4.y);
  r1.z = r4.x + -r3.z;
  r3.xyz = float3(-0.5,-0.5,-0.5) + r3.xyz;
  r3.xyz = saturate(cbSharedLightData.vParams2.xxx * abs(r3.xyz) + cbSharedLightData.vParams2.yyy);
  r1.w = dot(r3.xyz, r3.xyz);
  r1.w = min(1, r1.w);
  r1.z = cbSharedLightData.vLightParams.y * r1.z;
  r0.w = 0.00039999999 + r0.w;
  r0.w = min(1, r0.w);
  r0.w = rsqrt(r0.w);
  r0.w = saturate(r1.z * r0.w + 1);
  r1.z = 1 + -r0.w;
  r0.w = r1.w * r1.z + r0.w;
  r3.xyz = cbSharedLightData.vHalfLightBoxFadeNeg.xyz * r2.xyz + cbSharedLightData.vRcpLightBoxFadeNeg.xyz;
  r4.xyzw = mapShadowColor1BWhite.SampleLevel(samplerShadowColor1BWhite_s, r3.xy, 0).xyzw;
  r1.z = saturate(-r4.x * r4.x + r4.y);
  r1.w = r4.x + -r3.z;
  r3.xyz = float3(-0.5,-0.5,-0.5) + r3.xyz;
  r3.xyz = saturate(cbSharedLightData.vParams1.xxx * abs(r3.xyz) + cbSharedLightData.vParams1.yyy);
  r2.w = dot(r3.xyz, r3.xyz);
  r2.w = min(1, r2.w);
  r1.w = cbSharedLightData.vLightParams.y * r1.w;
  r1.z = 0.00039999999 + r1.z;
  r1.z = min(1, r1.z);
  r1.z = rsqrt(r1.z);
  r1.z = saturate(r1.w * r1.z + 1);
  r0.w = -r1.z + r0.w;
  r0.w = r2.w * r0.w + r1.z;
  r3.xyzw = mapShadowColor0BWhite.SampleLevel(samplerShadowColor0BWhite_s, r2.xy, 0).xyzw;
  r1.z = r3.x + -r2.z;
  r1.w = saturate(-r3.x * r3.x + r3.y);
  r1.w = 0.00039999999 + r1.w;
  r1.w = min(1, r1.w);
  r1.w = rsqrt(r1.w);
  r2.xyz = float3(-0.5,-0.5,-0.5) + r2.xyz;
  r2.xyz = saturate(cbSharedLightData.vParams0.xxx * abs(r2.xyz) + cbSharedLightData.vParams0.yyy);
  r2.x = dot(r2.xyz, r2.xyz);
  r2.x = min(1, r2.x);
  r1.z = cbSharedLightData.vLightParams.y * r1.z;
  r1.z = saturate(r1.z * r1.w + 1);
  r0.w = -r1.z + r0.w;
  r0.w = r2.x * r0.w + r1.z;
  r1.z = 1 + -r0.w;
  r0.w = cbSharedLightData.vLightDiffuse.w * r1.z + r0.w;
  r2.xyz = cbSharedLightData.mViewToLightProjTrans._m10_m11_m13 * r0.yyy;
  r2.xyz = r0.xxx * cbSharedLightData.mViewToLightProjTrans._m00_m01_m03 + r2.xyz;
  r2.xyz = r0.zzz * cbSharedLightData.mViewToLightProjTrans._m20_m21_m23 + r2.xyz;
  r2.xyz = cbSharedLightData.mViewToLightProjTrans._m30_m31_m33 + r2.xyz;
  r1.zw = r2.xy / r2.zz;
  r1.zw = r1.zw * cbSharedLightData.vProjectorTilingOffset.xy + cbSharedLightData.vProjectorTilingOffset.zw;
  r2.xyzw = mapLightProjectorMap0.SampleLevel(samplerLightProjectorMap0_s, r1.zw, -2).xyzw;
  r2.xyz = cbSharedLightData.vLightDiffuse.xyz * r2.xyz;
  r2.xyz = r2.xyz * r0.www;
  r0.w = dot(-r0.xyz, -r0.xyz);
  r0.w = rsqrt(r0.w);
  r0.xyz = -r0.xyz * r0.www;
  r3.xyzw = mapDeferred1.Sample(samplerDeferred1_s, r1.xy).xyzw;
  r3.xyz = float3(-0.5,-0.5,-0.5) + r3.xyz;
  r3.xyz = r3.xyz + r3.xyz;
  r0.w = dot(r3.xyz, r3.xyz);
  r0.w = rsqrt(r0.w);
  r3.xyz = r3.xyz * r0.www;
  r0.w = dot(r3.xyz, cbSharedLightData.vLightDirView.xyz);
  r1.z = r0.w + r0.w;
  r3.xyz = -r1.zzz * r3.xyz + cbSharedLightData.vLightDirView.xyz;
  r0.x = saturate(dot(r0.xyz, -r3.xyz));
  r3.xyzw = mapDeferred2.Sample(samplerDeferred2_s, r1.xy).xyzw;
  r1.xyzw = mapDeferred3.Sample(samplerDeferred3_s, r1.xy).xyzw;
  r0.y = r3.w;
  r0.y = dot(r0.xy, float2(0.248046875,0.75390625));
  r0.x = saturate(r0.w);
  r0.w = saturate(-r0.w);
  r4.xyzw = mapLightModel.Sample(samplerLightModel_s, r0.xy).xyzw;
  r0.x = r4.w * 1024 + -1000;
  r0.x = r1.y * r0.x;
  r0.x = exp2(r0.x);
  r0.y = dot(r3.xyz, float3(0.447058499,0.882354021,0.170587495));
  r5.xyz = r3.xyz * float3(2,2,2) + -r0.yyy;
  r0.y = 1 + -cbSharedLightData.vLightDiffuse.w;
  r0.y = r0.y * r1.w;
  r0.y = r0.y * r0.w;
  r0.yzw = r0.yyy * r5.xyz;
  r0.xyz = r1.xxx * r0.xxx + r0.yzw;
  r0.xyz = cbSharedLightData.vLightParams.xxx * r0.xyz;
  r0.xyz = r4.xyz * r3.xyz + r0.xyz;
  o0.xyz = r0.xyz * r2.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v1.2.6 on Sat Nov 07 07:12:57 2015
//
//
// Buffer Definitions: 
//
// 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
//
// }
//
// cbuffer _cbSharedLightData
// {
//
//   struct
//   {
//       
//       float4 vParams0;               // Offset:    0
//       float4 vParams1;               // Offset:   16
//       float4 vParams2;               // Offset:   32
//       float4 vLightDiffuse;          // Offset:   48
//       float4 vHalfLightBoxFadeNeg;   // Offset:   64
//       float4 vHalfLightBoxFadePos;   // Offset:   80
//       float4 vRcpLightBoxFadeNeg;    // Offset:   96
//       float4 vRcpLightBoxFadePos;    // Offset:  112
//       float4 vLightPosView;          // Offset:  128
//       float4 vLightDirView;          // Offset:  144
//       float4 vProjectorTilingOffset; // Offset:  160
//       row_major float4x4 mViewToShadowProjTrans;// Offset:  176
//       row_major float4x4 mViewToLightProjTrans;// Offset:  240
//       float4 vLightParams;           // Offset:  304
//       float4 vRestrictLightBoxVectorX;// Offset:  320
//       float4 vRestrictLightBoxVectorY;// Offset:  336
//       float4 vRestrictLightBoxVectorZ;// Offset:  352
//       float4 vRestrictLightBoxPosition;// Offset:  368
//
//   } cbSharedLightData;               // Offset:    0 Size:   384
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samplerLightModel                 sampler      NA          NA    0        1
// samplerLightProjectorMap0         sampler      NA          NA    1        1
// samplerShadowColor0BWhite         sampler      NA          NA    2        1
// samplerShadowColor1BWhite         sampler      NA          NA    3        1
// samplerShadowColor2BWhite         sampler      NA          NA    4        1
// samplerDeferred0                  sampler      NA          NA    5        1
// samplerDeferred1                  sampler      NA          NA    6        1
// samplerDeferred2                  sampler      NA          NA    7        1
// samplerDeferred3                  sampler      NA          NA    8        1
// mapLightModel                     texture  float4          2d    0        1
// mapLightProjectorMap0             texture  float4          2d    1        1
// mapShadowColor0BWhite             texture  float4          2d    2        1
// mapShadowColor1BWhite             texture  float4          2d    3        1
// mapShadowColor2BWhite             texture  float4          2d    4        1
// mapDeferred0                      texture  float4          2d    5        1
// mapDeferred1                      texture  float4          2d    6        1
// mapDeferred2                      texture  float4          2d    7        1
// mapDeferred3                      texture  float4          2d    8        1
// _cbSharedPerViewData              cbuffer      NA          NA    1        1
// _cbSharedLightData                cbuffer      NA          NA    2        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   xyz 
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb1[13], immediateIndexed
dcl_constantbuffer cb2[20], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_sampler s4, mode_default
dcl_sampler s5, mode_default
dcl_sampler s6, mode_default
dcl_sampler s7, mode_default
dcl_sampler s8, 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_texture2d (float,float,float,float) t3
dcl_resource_texture2d (float,float,float,float) t4
dcl_resource_texture2d (float,float,float,float) t5
dcl_resource_texture2d (float,float,float,float) t6
dcl_resource_texture2d (float,float,float,float) t7
dcl_resource_texture2d (float,float,float,float) t8
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 6
div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), v1.w
mul r0.yzw, r0.xxxx, v2.xxyz
mul r1.xy, r0.xxxx, v1.xyxx
sample r2.xyzw, r1.xyxx, t5.xyzw, s5
mad r0.x, cb1[12].z, r2.x, -cb1[12].y
div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
mul r0.xyz, r0.yzwy, r0.xxxx
mul r2.xyz, r0.yyyy, cb2[12].xyzx
mad r2.xyz, r0.xxxx, cb2[11].xyzx, r2.xyzx
mad r2.xyz, r0.zzzz, cb2[13].xyzx, r2.xyzx
add r2.xyz, r2.xyzx, cb2[14].xyzx
mad r3.xyz, cb2[5].xyzx, r2.xyzx, cb2[7].xyzx
sample_l r4.xyzw, r3.xyxx, t4.xyzw, s4, l(0.000000)
mad_sat r0.w, -r4.x, r4.x, r4.y
add r1.z, -r3.z, r4.x
add r3.xyz, r3.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
mad_sat r3.xyz, cb2[2].xxxx, |r3.xyzx|, cb2[2].yyyy
dp3 r1.w, r3.xyzx, r3.xyzx
min r1.w, r1.w, l(1.000000)
mul r1.z, r1.z, cb2[19].y
add r0.w, r0.w, l(0.000400)
min r0.w, r0.w, l(1.000000)
rsq r0.w, r0.w
mad_sat r0.w, r1.z, r0.w, l(1.000000)
add r1.z, -r0.w, l(1.000000)
mad r0.w, r1.w, r1.z, r0.w
mad r3.xyz, cb2[4].xyzx, r2.xyzx, cb2[6].xyzx
sample_l r4.xyzw, r3.xyxx, t3.xyzw, s3, l(0.000000)
mad_sat r1.z, -r4.x, r4.x, r4.y
add r1.w, -r3.z, r4.x
add r3.xyz, r3.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
mad_sat r3.xyz, cb2[1].xxxx, |r3.xyzx|, cb2[1].yyyy
dp3 r2.w, r3.xyzx, r3.xyzx
min r2.w, r2.w, l(1.000000)
mul r1.w, r1.w, cb2[19].y
add r1.z, r1.z, l(0.000400)
min r1.z, r1.z, l(1.000000)
rsq r1.z, r1.z
mad_sat r1.z, r1.w, r1.z, l(1.000000)
add r0.w, r0.w, -r1.z
mad r0.w, r2.w, r0.w, r1.z
sample_l r3.xyzw, r2.xyxx, t2.xyzw, s2, l(0.000000)
add r1.z, -r2.z, r3.x
mad_sat r1.w, -r3.x, r3.x, r3.y
add r1.w, r1.w, l(0.000400)
min r1.w, r1.w, l(1.000000)
rsq r1.w, r1.w
add r2.xyz, r2.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
mad_sat r2.xyz, cb2[0].xxxx, |r2.xyzx|, cb2[0].yyyy
dp3 r2.x, r2.xyzx, r2.xyzx
min r2.x, r2.x, l(1.000000)
mul r1.z, r1.z, cb2[19].y
mad_sat r1.z, r1.z, r1.w, l(1.000000)
add r0.w, r0.w, -r1.z
mad r0.w, r2.x, r0.w, r1.z
add r1.z, -r0.w, l(1.000000)
mad r0.w, cb2[3].w, r1.z, r0.w
mul r2.xyz, r0.yyyy, cb2[16].xywx
mad r2.xyz, r0.xxxx, cb2[15].xywx, r2.xyzx
mad r2.xyz, r0.zzzz, cb2[17].xywx, r2.xyzx
add r2.xyz, r2.xyzx, cb2[18].xywx
div r1.zw, r2.xxxy, r2.zzzz
mad r1.zw, r1.zzzw, cb2[10].xxxy, cb2[10].zzzw
sample_l r2.xyzw, r1.zwzz, t1.xyzw, s1, l(-2.000000)
mul r2.xyz, r2.xyzx, cb2[3].xyzx
mul r2.xyz, r0.wwww, r2.xyzx
dp3 r0.w, -r0.xyzx, -r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, -r0.xyzx
sample r3.xyzw, r1.xyxx, t6.xyzw, s6
add r3.xyz, r3.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
add r3.xyz, r3.xyzx, r3.xyzx
dp3 r0.w, r3.xyzx, r3.xyzx
rsq r0.w, r0.w
mul r3.xyz, r0.wwww, r3.xyzx
dp3 r0.w, r3.xyzx, cb2[9].xyzx
add r1.z, r0.w, r0.w
mad r3.xyz, -r1.zzzz, r3.xyzx, cb2[9].xyzx
dp3_sat r0.x, r0.xyzx, -r3.xyzx
sample r3.xyzw, r1.xyxx, t7.xyzw, s7
sample r1.xyzw, r1.xyxx, t8.xyzw, s8
mov r0.y, r3.w
dp2 r0.y, r0.xyxx, l(0.248046875, 0.753906250, 0.000000, 0.000000)
mov_sat r0.x, r0.w
mov_sat r0.w, -r0.w
sample r4.xyzw, r0.xyxx, t0.xyzw, s0
mad r0.x, r4.w, l(1024.000000), l(-1000.000000)
mul r0.x, r0.x, r1.y
exp r0.x, r0.x
dp3 r0.y, r3.xyzx, l(0.447058499, 0.882354, 0.170587495, 0.000000)
mad r5.xyz, r3.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), -r0.yyyy
add r0.y, -cb2[3].w, l(1.000000)
mul r0.y, r1.w, r0.y
mul r0.y, r0.w, r0.y
mul r0.yzw, r5.xxyz, r0.yyyy
mad r0.xyz, r1.xxxx, r0.xxxx, r0.yzwy
mul r0.xyz, r0.xyzx, cb2[19].xxxx
mad r0.xyz, r4.xyzx, r3.xyzx, r0.xyzx
mul o0.xyz, r2.xyzx, r0.xyzx
mov o0.w, l(0)
ret 
// Approximately 101 instruction slots used

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