// Shadows
// 2086774709c648e0 VS
cbuffer cPSScene : register(b2)
{

  struct
  {
    float4x4 m_projectionView;
    float4x4 m_projection;
    float4x4 m_view;
    float4x4 m_shadowProjection;
    float4x4 m_shadowProjection2;
    float4 m_eyepos;
    float4 m_projectionParam;
    float4 m_viewportSize;
    float4 m_exposure;
    float4 m_fogParam[3];
    float4 m_fogColor;
    float4 m_cameraCenterOffset;
    float4 m_shadowMapResolutions;
  } g_psScene : packoffset(c0);

}

cbuffer cPSLight : 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_psLight : packoffset(c0);

}

cbuffer cPSMaterial : register(b4)
{

  struct
  {
    float4 m_materials[8];
  } g_psMaterial : packoffset(c0);

}

SamplerState g_samplerPoint_Wrap_s : register(s8);
SamplerState g_samplerPoint_Clamp_s : register(s9);
SamplerState g_samplerLinear_Clamp_s : register(s11);
SamplerComparisonState g_samplerComparisonLess_Linear_Clmap_s : register(s15);
Texture2D<float4> g_NormalTexture : register(t0);
Texture2D<float4> g_SpecularTexture : register(t1);
Texture2D<float4> g_DepthTexture : register(t2);
Texture2D<float4> g_ShadowTexture : register(t3);
Texture3D<float4> g_lut2 : register(t8);
Texture2D<float4> g_lut1 : register(t9);
Texture2D<float4> g_MaterialTexture : register(t10);


// 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,
  out float4 o0 : SV_Target0,
  out float4 o1 : SV_Target1)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xyzw = floor(v0.xyxy);
  r0.xyzw = r0.xyzw * float4(0.5,0.5,0.5,0.5) + float4(0.100000001,0.100000001,0.100000001,0.100000001);
  r0.xyzw = frac(r0.xyzw);
  r0.xyzw = cmp(r0.xyzw >= float4(0.300000012,0.300000012,0.300000012,0.300000012));
  r0.xyzw = r0.xyzw ? float4(0.625,0.625,-0.375,-0.375) : float4(0.375,0.375,-0.625,-0.625);
  r1.xy = v1.xy / v1.ww;
  r1.xy = -g_psScene.m_cameraCenterOffset.xy + r1.xy;
  r1.xy = g_psScene.m_projectionParam.xy * r1.xy;
  r1.zw = v2.xy / v2.ww;
  r2.x = g_DepthTexture.Sample(g_samplerPoint_Wrap_s, r1.zw).x;
  r2.x = -g_psScene.m_projectionParam.w + r2.x;
  r2.z = g_psScene.m_projectionParam.z / r2.x;
  r2.xy = r2.zz * r1.xy;
  r2.w = 1;
  
  float4 stereo = StereoParams.Load(0);
  r2.x -= stereo.x * (r2.z - stereo.y) / g_psScene.m_projection._m00;
  
  r1.x = dot(r2.xyzw, g_psScene.m_shadowProjection._m00_m10_m20_m30);
  r1.y = dot(r2.xyzw, g_psScene.m_shadowProjection._m01_m11_m21_m31);
  r3.x = dot(r2.xyzw, g_psScene.m_shadowProjection._m03_m13_m23_m33);
  r4.z = dot(r2.xyzw, g_psScene.m_shadowProjection._m02_m12_m22_m32);
  r2.w = r3.x / g_psScene.m_shadowMapResolutions.y;
  r5.xy = r0.zy * r2.ww + r1.xy;
  r5.z = r4.z;
  r3.yzw = r5.xyz / r3.xxx;
  r3.y = g_ShadowTexture.SampleCmp(g_samplerComparisonLess_Linear_Clmap_s, r3.yz, r3.w).x;
  r4.xy = r0.xy * r2.ww + r1.xy;
  r4.xyz = r4.xyz / r3.xxx;
  r0.y = g_ShadowTexture.SampleCmp(g_samplerComparisonLess_Linear_Clmap_s, r4.xy, r4.z).x;
  r0.y = r0.y + r3.y;
  r5.xy = r0.xw * r2.ww + r1.xy;
  r4.xy = r0.zw * r2.ww + r1.xy;
  r0.xzw = r5.xyz / r3.xxx;
  r4.z = r5.z;
  r3.xyz = r4.xyz / r3.xxx;
  r1.x = g_ShadowTexture.SampleCmp(g_samplerComparisonLess_Linear_Clmap_s, r3.xy, r3.z).x;
  r0.x = g_ShadowTexture.SampleCmp(g_samplerComparisonLess_Linear_Clmap_s, r0.xz, r0.w).x;
  r0.x = r0.y + r0.x;
  r0.x = r0.x + r1.x;
  r0.yzw = g_psLight.m_lightSourcePos.xyz + -r2.xyz;
  r1.x = dot(r0.yzw, r0.yzw);
  r1.y = rsqrt(r1.x);
  r3.xyz = r1.yyy * r0.yzw;
  r2.w = dot(g_psLight.m_lightSourceDir.xyz, -r3.xyz);
  r3.w = -g_psMaterial.m_materials[6].x + r2.w;
  r2.w = -g_psLight.m_lightSourceParam2.x + r2.w;
  r2.w = saturate(g_psLight.m_lightSourceParam2.y * r2.w);
  r2.w = log2(r2.w);
  r2.w = g_psLight.m_lightSourceParam2.z * r2.w;
  r2.w = exp2(r2.w);
  r3.w = saturate(g_psMaterial.m_materials[6].y * r3.w);
  r3.w = r3.w * r3.w;
  r0.x = r3.w * r0.x;
  r0.x = -r0.x * 0.25 + 1;
  r0.x = r0.x * r0.x + -1;
  r0.x = g_psLight.m_lightSourceParam3.z * r0.x + 1;
  r3.w = 1 / r1.x;
  r3.w = -g_psLight.m_lightSourceParam1.w * r1.x + r3.w;
  r1.x = r1.x * r1.y;
  r1.x = max(g_psMaterial.m_materials[7].x, r1.x);
  r1.x = g_psLight.m_lightSourceColor.w / r1.x;
  r3.w = min(g_psMaterial.m_materials[7].w, r3.w);
  r3.w = max(0, r3.w);
  r4.xyz = g_psLight.m_lightSourceColor.xyz * r3.www;
  r4.xyz = r4.xyz * r2.www;
  r4.xyz = g_psScene.m_exposure.zzz * r4.xyz;
  r5.xyz = g_NormalTexture.Sample(g_samplerPoint_Wrap_s, r1.zw).xyz;
  r6.xyzw = g_SpecularTexture.Sample(g_samplerPoint_Wrap_s, r1.zw).yxzw;
  r1.zw = r5.xy * float2(2,2) + float2(-1,-1);
  r2.w = dot(r5.zz, r5.zz);
  r5.z = -1 + r2.w;
  r2.w = dot(r1.zw, r1.zw);
  r3.w = -r5.z * r5.z + 1;
  r2.w = r3.w * r2.w + 1.00000001e-007;
  r1.zw = r3.ww * r1.zw;
  r2.w = rsqrt(r2.w);
  r5.xy = r2.ww * r1.zw;
  r1.z = dot(r3.xyz, r5.xyz);
  r1.w = -r1.z * r1.z + 1;
  r1.w = r1.w * r6.w + r1.z;
  r1.xz = saturate(float2(0.899999976,4) * r1.xz);
  r7.x = r6.z;
  r7.yz = float2(0.25,0.75);
  r8.xyzw = g_MaterialTexture.Sample(g_samplerPoint_Clamp_s, r7.xy).xyzw;
  r7.yz = g_MaterialTexture.Sample(g_samplerPoint_Clamp_s, r7.xz).xw;
  r8.xyzw = r8.wxyz * r6.wxxx;
  r1.w = saturate(max(r8.x, r1.w));
  r8.xyz = r8.yzw * r4.xyz;
  r4.xyz = r1.www * r4.xyz;
  r4.xyz = r4.xyz * r0.xxx;
  o0.xyz = g_psLight.m_lightSourceParam3.yyy * r4.xyz;
  o0.w = 1;
  r1.w = dot(r2.xyz, r2.xyz);
  r1.w = rsqrt(r1.w);
  r2.xyz = r2.xyz * r1.www;
  r1.w = dot(-r2.xyz, r5.xyz);
  r1.w = r1.w + r1.w;
  r4.xyz = r5.xyz * -r1.www + -r2.xyz;
  r0.yzw = -r0.yzw * r1.yyy + -r4.xyz;
  r1.y = dot(r0.yzw, r0.yzw);
  r1.y = sqrt(r1.y);
  r1.x = r1.x / r1.y;
  r1.x = min(1, r1.x);
  r0.yzw = r1.xxx * r0.yzw + r3.xyz;
  r1.x = dot(r0.yzw, r0.yzw);
  r1.x = rsqrt(r1.x);
  r0.yzw = r0.yzw * r1.xxx + -r2.xyz;
  r1.x = dot(r0.yzw, r0.yzw);
  r1.x = rsqrt(r1.x);
  r0.yzw = r1.xxx * r0.yzw;
  r6.x = saturate(dot(r0.yzw, r5.xyz));
  r7.x = dot(r0.yzw, r3.xyz);
  r6.z = r7.z;
  r0.y = g_lut1.Sample(g_samplerLinear_Clamp_s, r7.xy).x;
  r1.xyw = r6.xyz * r6.xyz;
  r1.xyw = r1.xyw * float3(0.984375,0.9375,0.9375) + float3(0.0078125,0.03125,0.03125);
  r0.zw = g_lut2.Sample(g_samplerLinear_Clamp_s, r1.xyw).xy;
  r0.zw = r0.zw * r0.zw;
  r0.z = r0.z / r0.w;
  r0.y = r0.y * r0.z;
  r0.y = r0.y * r1.z;
  r0.yzw = r8.xyz * r0.yyy;
  r0.xyz = r0.yzw * r0.xxx;
  o1.xyz = g_psLight.m_lightSourceParam3.xxx * r0.xyz;
  o1.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.24 on Mon Jan 18 12:09:25 2016
//
//
// Buffer Definitions: 
//
// cbuffer cPSScene
// {
//
//   struct PSScene
//   {
//       
//       float4x4 m_projectionView;     // Offset:    0
//       float4x4 m_projection;         // Offset:   64
//       float4x4 m_view;               // Offset:  128
//       float4x4 m_shadowProjection;   // Offset:  192
//       float4x4 m_shadowProjection2;  // Offset:  256
//       float4 m_eyepos;               // Offset:  320
//       float4 m_projectionParam;      // Offset:  336
//       float4 m_viewportSize;         // Offset:  352
//       float4 m_exposure;             // Offset:  368
//       float4 m_fogParam[3];          // Offset:  384
//       float4 m_fogColor;             // Offset:  432
//       float4 m_cameraCenterOffset;   // Offset:  448
//       float4 m_shadowMapResolutions; // Offset:  464
//
//   } g_psScene;                       // Offset:    0 Size:   480
//
// }
//
// cbuffer cPSLight
// {
//
//   struct PSLight
//   {
//       
//       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_psLight;                       // Offset:    0 Size:   176
//
// }
//
// cbuffer cPSMaterial
// {
//
//   struct PSMaterial
//   {
//       
//       float4 m_materials[8];         // Offset:    0
//
//   } g_psMaterial;                    // Offset:    0 Size:   128
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_samplerPoint_Wrap               sampler      NA          NA    8        1
// g_samplerPoint_Clamp              sampler      NA          NA    9        1
// g_samplerLinear_Clamp             sampler      NA          NA   11        1
// g_samplerComparisonLess_Linear_Clmap  sampler_c      NA          NA   15        1
// g_NormalTexture                   texture  float4          2d    0        1
// g_SpecularTexture                 texture  float4          2d    1        1
// g_DepthTexture                    texture  float4          2d    2        1
// g_ShadowTexture                   texture  float4          2d    3        1
// g_lut2                            texture  float4          3d    8        1
// g_lut1                            texture  float4          2d    9        1
// g_MaterialTexture                 texture  float4          2d   10        1
// cPSScene                          cbuffer      NA          NA    2        1
// cPSLight                          cbuffer      NA          NA    3        1
// cPSMaterial                       cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xy  
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyzw        2     NONE   float   xy w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
// SV_Target                1   xyzw        1   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb2[30], immediateIndexed
dcl_constantbuffer cb3[9], immediateIndexed
dcl_constantbuffer cb4[8], immediateIndexed
dcl_sampler s8, mode_default
dcl_sampler s9, mode_default
dcl_sampler s11, mode_default
dcl_sampler s15, mode_comparison
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_texture3d (float,float,float,float) t8
dcl_resource_texture2d (float,float,float,float) t9
dcl_resource_texture2d (float,float,float,float) t10
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyw
dcl_output o0.xyzw
dcl_output o1.xyzw
dcl_temps 9
round_ni r0.xyzw, v0.xyxy
mad r0.xyzw, r0.xyzw, l(0.500000, 0.500000, 0.500000, 0.500000), l(0.100000, 0.100000, 0.100000, 0.100000)
frc r0.xyzw, r0.xyzw
ge r0.xyzw, r0.xyzw, l(0.300000, 0.300000, 0.300000, 0.300000)
movc r0.xyzw, r0.xyzw, l(0.625000,0.625000,-0.375000,-0.375000), l(0.375000,0.375000,-0.625000,-0.625000)
div r1.xy, v1.xyxx, v1.wwww
add r1.xy, r1.xyxx, -cb2[28].xyxx
mul r1.xy, r1.xyxx, cb2[21].xyxx
div r1.zw, v2.xxxy, v2.wwww
sample_indexable(texture2d)(float,float,float,float) r2.x, r1.zwzz, t2.xyzw, s8
add r2.x, r2.x, -cb2[21].w
div r2.z, cb2[21].z, r2.x
mul r2.xy, r1.xyxx, r2.zzzz
mov r2.w, l(1.000000)
dp4 r1.x, r2.xyzw, cb2[12].xyzw
dp4 r1.y, r2.xyzw, cb2[13].xyzw
dp4 r3.x, r2.xyzw, cb2[15].xyzw
dp4 r4.z, r2.xyzw, cb2[14].xyzw
div r2.w, r3.x, cb2[29].y
mad r5.xy, r0.zyzz, r2.wwww, r1.xyxx
mov r5.z, r4.z
div r3.yzw, r5.xxyz, r3.xxxx
sample_c_indexable(texture2d)(float,float,float,float) r3.y, r3.yzyy, t3.xxxx, s15, r3.w
mad r4.xy, r0.xyxx, r2.wwww, r1.xyxx
div r4.xyz, r4.xyzx, r3.xxxx
sample_c_indexable(texture2d)(float,float,float,float) r0.y, r4.xyxx, t3.xxxx, s15, r4.z
add r0.y, r3.y, r0.y
mad r5.xy, r0.xwxx, r2.wwww, r1.xyxx
mad r4.xy, r0.zwzz, r2.wwww, r1.xyxx
div r0.xzw, r5.xxyz, r3.xxxx
mov r4.z, r5.z
div r3.xyz, r4.xyzx, r3.xxxx
sample_c_indexable(texture2d)(float,float,float,float) r1.x, r3.xyxx, t3.xxxx, s15, r3.z
sample_c_indexable(texture2d)(float,float,float,float) r0.x, r0.xzxx, t3.xxxx, s15, r0.w
add r0.x, r0.x, r0.y
add r0.x, r1.x, r0.x
add r0.yzw, -r2.xxyz, cb3[3].xxyz
dp3 r1.x, r0.yzwy, r0.yzwy
rsq r1.y, r1.x
mul r3.xyz, r0.yzwy, r1.yyyy
dp3 r2.w, cb3[5].xyzx, -r3.xyzx
add r3.w, r2.w, -cb4[6].x
add r2.w, r2.w, -cb3[7].x
mul_sat r2.w, r2.w, cb3[7].y
log r2.w, r2.w
mul r2.w, r2.w, cb3[7].z
exp r2.w, r2.w
mul_sat r3.w, r3.w, cb4[6].y
mul r3.w, r3.w, r3.w
mul r0.x, r0.x, r3.w
mad r0.x, -r0.x, l(0.250000), l(1.000000)
mad r0.x, r0.x, r0.x, l(-1.000000)
mad r0.x, cb3[8].z, r0.x, l(1.000000)
div r3.w, l(1.000000, 1.000000, 1.000000, 1.000000), r1.x
mad r3.w, -cb3[6].w, r1.x, r3.w
mul r1.x, r1.y, r1.x
max r1.x, r1.x, cb4[7].x
div r1.x, cb3[4].w, r1.x
min r3.w, r3.w, cb4[7].w
max r3.w, r3.w, l(0.000000)
mul r4.xyz, r3.wwww, cb3[4].xyzx
mul r4.xyz, r2.wwww, r4.xyzx
mul r4.xyz, r4.xyzx, cb2[23].zzzz
sample_indexable(texture2d)(float,float,float,float) r5.xyz, r1.zwzz, t0.xyzw, s8
sample_indexable(texture2d)(float,float,float,float) r6.xyzw, r1.zwzz, t1.yxzw, s8
mad r1.zw, r5.xxxy, l(0.000000, 0.000000, 2.000000, 2.000000), l(0.000000, 0.000000, -1.000000, -1.000000)
dp2 r2.w, r5.zzzz, r5.zzzz
add r5.z, r2.w, l(-1.000000)
dp2 r2.w, r1.zwzz, r1.zwzz
mad r3.w, -r5.z, r5.z, l(1.000000)
mad r2.w, r3.w, r2.w, l(1.000000012E-007)
mul r1.zw, r1.zzzw, r3.wwww
rsq r2.w, r2.w
mul r5.xy, r1.zwzz, r2.wwww
dp3 r1.z, r3.xyzx, r5.xyzx
mad r1.w, -r1.z, r1.z, l(1.000000)
mad r1.w, r1.w, r6.w, r1.z
mul_sat r1.xz, r1.xxzx, l(0.900000, 0.000000, 4.000000, 0.000000)
mov r7.x, r6.z
mov r7.yz, l(0,0.250000,0.750000,0)
sample_indexable(texture2d)(float,float,float,float) r8.xyzw, r7.xyxx, t10.xyzw, s9
sample_indexable(texture2d)(float,float,float,float) r7.yz, r7.xzxx, t10.yxwz, s9
mul r8.xyzw, r6.wxxx, r8.wxyz
max_sat r1.w, r1.w, r8.x
mul r8.xyz, r4.xyzx, r8.yzwy
mul r4.xyz, r4.xyzx, r1.wwww
mul r4.xyz, r0.xxxx, r4.xyzx
mul o0.xyz, r4.xyzx, cb3[8].yyyy
mov o0.w, l(1.000000)
dp3 r1.w, r2.xyzx, r2.xyzx
rsq r1.w, r1.w
mul r2.xyz, r1.wwww, r2.xyzx
dp3 r1.w, -r2.xyzx, r5.xyzx
add r1.w, r1.w, r1.w
mad r4.xyz, r5.xyzx, -r1.wwww, -r2.xyzx
mad r0.yzw, -r0.yyzw, r1.yyyy, -r4.xxyz
dp3 r1.y, r0.yzwy, r0.yzwy
sqrt r1.y, r1.y
div r1.x, r1.x, r1.y
min r1.x, r1.x, l(1.000000)
mad r0.yzw, r1.xxxx, r0.yyzw, r3.xxyz
dp3 r1.x, r0.yzwy, r0.yzwy
rsq r1.x, r1.x
mad r0.yzw, r0.yyzw, r1.xxxx, -r2.xxyz
dp3 r1.x, r0.yzwy, r0.yzwy
rsq r1.x, r1.x
mul r0.yzw, r0.yyzw, r1.xxxx
dp3_sat r6.x, r0.yzwy, r5.xyzx
dp3 r7.x, r0.yzwy, r3.xyzx
mov r6.z, r7.z
sample_indexable(texture2d)(float,float,float,float) r0.y, r7.xyxx, t9.yxzw, s11
mul r1.xyw, r6.xyxz, r6.xyxz
mad r1.xyw, r1.xyxw, l(0.984375, 0.937500, 0.000000, 0.937500), l(0.00781250000, 0.031250, 0.000000, 0.031250)
sample_indexable(texture3d)(float,float,float,float) r0.zw, r1.xywx, t8.zwxy, s11
mul r0.zw, r0.zzzw, r0.zzzw
div r0.z, r0.z, r0.w
mul r0.y, r0.z, r0.y
mul r0.y, r1.z, r0.y
mul r0.yzw, r0.yyyy, r8.xxyz
mul r0.xyz, r0.xxxx, r0.yzwy
mul o1.xyz, r0.xyzx, cb3[8].xxxx
mov o1.w, l(1.000000)
ret 
// Approximately 123 instruction slots used

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