//Shadows PS 2
cbuffer PER_BATCH : register(b0)
{
  float4 g_LightPos : packoffset(c0);
  float4 g_LightDiffuse : packoffset(c1);
  row_major float4x4 g_mLightProj : packoffset(c2);
  float4 g_ScreenScale : packoffset(c6);
  float4 vWBasisX : packoffset(c7);
  float4 vWBasisY : packoffset(c8);
  float4 vWBasisZ : packoffset(c9);
  float4 irreg_kernel_2d[8] : packoffset(c10);
  float4 SSDOParams : packoffset(c18);
}
SamplerState _tex0_s : register(s0);
SamplerState _tex1_s : register(s1);
SamplerState _tex2_s : register(s2);
SamplerState _tex8_s : register(s8);
Texture2D<float4> _tex0 : register(t0);
Texture2D<float4> _tex1 : register(t1);
Texture2D<float4> _tex2 : register(t2);
Texture2D<float4> _tex8 : register(t8);

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

void main( 
  float4 v0 : SV_POSITION0,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1,
  
  float4 g_VS_NearFarClipDist : TEXCOORD2,
  float4 g_VS_ScreenSize : TEXCOORD3)
  
{
  float4 r0,r1,r2,r3,r4,r5,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

  r1.xy = v0.xy * g_ScreenScale.xy + g_ScreenScale.zw;
  r0.w = _tex0.Sample(_tex0_s, r1.xy).x;
  
  float4 stereo = StereoParams.Load(0);
  float depth = r0.w * g_VS_NearFarClipDist.y;
  v0.x -= stereo.x * (depth - stereo.y) / depth * g_VS_ScreenSize.x / 2;
  
  r0.xyz = vWBasisX.xyz * v0.xxx + vWBasisZ.xyz;
  r0.xyz = vWBasisY.xyz * v0.yyy + r0.xyz;
  
  
  r2.xyz = r0.xyz * r0.www;
  r0.xyz = -r0.xyz * r0.www + g_LightPos.xyz;
  r2.w = 1;
  r3.x = dot(g_mLightProj._m00_m01_m02_m03, r2.xyzw);
  r3.y = dot(g_mLightProj._m10_m11_m12_m13, r2.xyzw);
  r0.w = dot(g_mLightProj._m30_m31_m32_m33, r2.xyzw);
  r1.zw = r3.xy / r0.ww;
  r3.xyz = _tex2.SampleLevel(_tex2_s, r1.zw, 0).xyz;
  r4.xyzw = _tex1.Sample(_tex1_s, r1.xy).xyzw;
  r1.xyzw = _tex8.Sample(_tex8_s, r1.xy).xyzw;
  r4.xyz = r4.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r5.xy = r4.ww * float2(40.5845261,255) + float2(0.318309993,9.99999997e-007);
  r0.w = dot(r4.xyz, r4.xyz);
  r0.w = rsqrt(r0.w);
  r4.xyz = r4.xyz * r0.www;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = rsqrt(r0.w);
  r6.xyz = r0.xyz * r0.www;
  r0.xyz = g_LightPos.www * r0.xyz;
  r0.x = dot(r0.xyz, r0.xyz);
  r0.x = 1 + -r0.x;
  r0.x = max(0, r0.x);
  r0.y = saturate(dot(r6.xyz, r4.xyz));
  r3.xyz = r0.yyy * r3.xyz;
  r3.xyz = g_LightDiffuse.xyz * r3.xyz;
  r0.xzw = r3.xyz * r0.xxx;
  r1.xyz = r1.xyz * float3(2,2,2) + float3(-1,-1,-1);
  r1.x = saturate(dot(r6.xyz, r1.xyz));
  r0.y = -r1.x + r0.y;
  r0.y = max(0, r0.y);
  r0.y = sqrt(r0.y);
  r0.y = r0.y * r1.w;
  r0.y = saturate(SSDOParams.x * r0.y);
  r0.y = 1 + -r0.y;
  r0.xyz = r0.xzw * r0.yyy;
  o0.xyz = r0.xyz;
  r0.xyz = g_LightDiffuse.www * r0.xyz;
  o0.w = 0;
  r0.w = dot(-r2.xyz, -r2.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = -r2.xyz * r0.www + r6.xyz;
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r0.w = saturate(dot(r4.xyz, r1.xyz));
  r0.w = log2(r0.w);
  r0.w = r5.y * r0.w;
  r0.w = exp2(r0.w);
  r0.w = r5.x * r0.w;
  o1.xyz = r0.xyz * r0.www;
  o1.w = 0;
  return;
}