// ---- Created with 3Dmigoto v1.2.35 on Tue Apr 26 22:30:26 2016

cbuffer cbSceneParam : register(b8)
{
  float4 FC_FarClipInfo : packoffset(c0);
  float4 FC_ScreenSize : packoffset(c1);
  float4 FC_DepthComputeParam : packoffset(c2);
  float4 SC_CameraPos : packoffset(c3);
  float4 VC_ClipPlane : packoffset(c4);
  float4x3 FC_MatrixView : packoffset(c5);
  float4x4 FC_MatrixInvViewProj : packoffset(c8);
  float4x4 FC_MatrixInvProj : packoffset(c12);
  float4x4 FC_MatrixProj : packoffset(c16);
  float4x4 FC_MatrixInvView : packoffset(c20);
  float4x4 VC_MatrixViewProj : packoffset(c24);
  float4 FC_ShadowMapParam : packoffset(c28);
  float4 FC_ShadowColor : packoffset(c29);
  float4 FC_ShadowDir : packoffset(c30);
  float4x4 VC_ShadowMapMatrix : packoffset(c31);
  float FC_ShadowDepthRate : packoffset(c35);
  float FC_ShadowDepthScale : packoffset(c35.y);
  float FC_ShadowKernelScale : packoffset(c35.z);
  float FC_ShadowRandTexInvScale : packoffset(c35.w);
  float FC_ShadowTexInvScaleX : packoffset(c36);
  float FC_ShadowTexInvScaleY : packoffset(c36.y);
  float FC_ShadowDepthOffsetScale : packoffset(c36.z);
  float4 FC_ShadowViewKernelScale : packoffset(c37);
  float4x4 FC_ProjSpaceToShadowMatrix[4] : packoffset(c38);
  float4 FC_CascadeSelectDist : packoffset(c54);
  float FC_FrustumNear : packoffset(c55);
  float FC_FrustumSliceScale : packoffset(c55.y);
  float FC_FrustumSliceBias : packoffset(c55.z);
  uint FC_LightTile_Width : packoffset(c56);
  uint FC_LightTile_NumCellX : packoffset(c56.y);
  float4 FC_CloudShadowParam0 : packoffset(c57);
  float4 FC_CloudShadowParam1 : packoffset(c58);
  float FC_ShadowScale0 : packoffset(c59);
  float FC_ShadowScale1 : packoffset(c59.y);
}

cbuffer cbPerScene : register(b0)
{
  float4x4 g_InvProjMatrix : packoffset(c0);
  float4x4 g_ProjSpaceToShadowMatrix[4] : packoffset(c4);
  float4 g_CascadeSelectDist : packoffset(c20);
}

SamplerState SS_ClampPoint_s : register(s7);
SamplerComparisonState SS_Shadow_s : register(s12);
Texture2D<float4> g_DepthTexture : register(t1);
Texture2D<float4> g_ShadowTexture : register(t32);


// 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)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.z = g_DepthTexture.Sample(SS_ClampPoint_s, v1.xy).x;
  r1.xyz = float3(65025,255,1) * r0.zzz;
  r0.xy = v2.xy;
  r0.w = 1;
  r2.x = dot(r0.xyzw, g_InvProjMatrix._m00_m10_m20_m30);
  r2.y = dot(r0.xyzw, g_InvProjMatrix._m01_m11_m21_m31);
  r2.z = dot(r0.xyzw, g_InvProjMatrix._m02_m12_m22_m32);
  r2.w = dot(r0.xyzw, g_InvProjMatrix._m03_m13_m23_m33);
  r0.xyz = r2.xyz / r2.www;
  r3.xyz = cmp(g_CascadeSelectDist.xyz < r0.zzz);
  r0.x = dot(r0.xyz, r0.xyz);
  r0.x = sqrt(r0.x);
  r0.x = FC_ShadowMapParam.x + -r0.x;
  r0.x = saturate(FC_ShadowMapParam.y * r0.x);
  r0.yzw = r3.xyz ? float3(1,1,1) : 0;
  r0.y = (int)r0.z + (int)r0.y;
  r0.y = (int)r0.w + (int)r0.y;
  r0.y = (uint)r0.y << 2;
  r3.x = dot(r2.xyzw, g_ProjSpaceToShadowMatrix[r0.y/4]._m00_m10_m20_m30);
  r3.y = dot(r2.xyzw, g_ProjSpaceToShadowMatrix[r0.y/4]._m01_m11_m21_m31);
  r3.z = dot(r2.xyzw, g_ProjSpaceToShadowMatrix[r0.y/4]._m02_m12_m22_m32);
  r3.w = dot(r2.xyzw, g_ProjSpaceToShadowMatrix[r0.y/4]._m03_m13_m23_m33);
  r2.xy = FC_ShadowMapParam.zw * r3.ww;
  r2.w = -r2.x;
  r2.z = 0;
  r4.xyzw = r3.xyzw + r2.ywzz;
  r0.yzw = r4.xyz / r4.www;
  r4.y = g_ShadowTexture.SampleCmpLevelZero(SS_Shadow_s, r0.yz, r0.w).x;
  r5.xyzw = r3.xyzw + r2.xyzz;
  r0.yzw = r5.xyz / r5.www;
  r4.x = g_ShadowTexture.SampleCmpLevelZero(SS_Shadow_s, r0.yz, r0.w).x;
  r5.xyzw = r2.xyzz * float4(-1,-1,1,1) + r3.xyzw;
  r2.xyzw = r2.yxzz * float4(-1,1,1,1) + r3.xyzw;
  r0.yzw = r2.xyz / r2.www;
  r4.w = g_ShadowTexture.SampleCmpLevelZero(SS_Shadow_s, r0.yz, r0.w).x;
  r0.yzw = r5.xyz / r5.www;
  r4.z = g_ShadowTexture.SampleCmpLevelZero(SS_Shadow_s, r0.yz, r0.w).x;
  r0.y = dot(r4.xyzw, float4(0.25,0.25,0.25,0.25));
  r0.y = 1 + -r0.y;
  o0.w = -r0.x * r0.y + 1;
  r1.xy = frac(r1.xy);
  o0.yz = -r1.xy * float2(0.00392156886,0.00392156886) + r1.yz;
  o0.x = r1.x;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//
// Buffer Definitions: 
//
// cbuffer cbSceneParam
// {
//
//   float4 FC_FarClipInfo;             // Offset:    0 Size:    16 [unused]
//   float4 FC_ScreenSize;              // Offset:   16 Size:    16 [unused]
//   float4 FC_DepthComputeParam;       // Offset:   32 Size:    16 [unused]
//   float4 SC_CameraPos;               // Offset:   48 Size:    16 [unused]
//   float4 VC_ClipPlane;               // Offset:   64 Size:    16 [unused]
//   float4x3 FC_MatrixView;            // Offset:   80 Size:    48 [unused]
//   float4x4 FC_MatrixInvViewProj;     // Offset:  128 Size:    64 [unused]
//   float4x4 FC_MatrixInvProj;         // Offset:  192 Size:    64 [unused]
//   float4x4 FC_MatrixProj;            // Offset:  256 Size:    64 [unused]
//   float4x4 FC_MatrixInvView;         // Offset:  320 Size:    64 [unused]
//   float4x4 VC_MatrixViewProj;        // Offset:  384 Size:    64 [unused]
//   float4 FC_ShadowMapParam;          // Offset:  448 Size:    16
//   float4 FC_ShadowColor;             // Offset:  464 Size:    16 [unused]
//   float4 FC_ShadowDir;               // Offset:  480 Size:    16 [unused]
//   float4x4 VC_ShadowMapMatrix;       // Offset:  496 Size:    64 [unused]
//   float FC_ShadowDepthRate;          // Offset:  560 Size:     4 [unused]
//   float FC_ShadowDepthScale;         // Offset:  564 Size:     4 [unused]
//   float FC_ShadowKernelScale;        // Offset:  568 Size:     4 [unused]
//   float FC_ShadowRandTexInvScale;    // Offset:  572 Size:     4 [unused]
//   float FC_ShadowTexInvScaleX;       // Offset:  576 Size:     4 [unused]
//   float FC_ShadowTexInvScaleY;       // Offset:  580 Size:     4 [unused]
//   float FC_ShadowDepthOffsetScale;   // Offset:  584 Size:     4 [unused]
//   float4 FC_ShadowViewKernelScale;   // Offset:  592 Size:    16 [unused]
//   float4x4 FC_ProjSpaceToShadowMatrix[4];// Offset:  608 Size:   256 [unused]
//   float4 FC_CascadeSelectDist;       // Offset:  864 Size:    16 [unused]
//   float FC_FrustumNear;              // Offset:  880 Size:     4 [unused]
//   float FC_FrustumSliceScale;        // Offset:  884 Size:     4 [unused]
//   float FC_FrustumSliceBias;         // Offset:  888 Size:     4 [unused]
//   uint FC_LightTile_Width;           // Offset:  896 Size:     4 [unused]
//   uint FC_LightTile_NumCellX;        // Offset:  900 Size:     4 [unused]
//   float4 FC_CloudShadowParam0;       // Offset:  912 Size:    16 [unused]
//   float4 FC_CloudShadowParam1;       // Offset:  928 Size:    16 [unused]
//   float FC_ShadowScale0;             // Offset:  944 Size:     4 [unused]
//   float FC_ShadowScale1;             // Offset:  948 Size:     4 [unused]
//
// }
//
// cbuffer cbPerScene
// {
//
//   float4x4 g_InvProjMatrix;          // Offset:    0 Size:    64
//   float4x4 g_ProjSpaceToShadowMatrix[4];// Offset:   64 Size:   256
//   float4 g_CascadeSelectDist;        // Offset:  320 Size:    16
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SS_ClampPoint                     sampler      NA          NA    7        1
// SS_Shadow                       sampler_c      NA          NA   12        1
// g_DepthTexture                    texture  float4          2d    1        1
// g_ShadowTexture                   texture  float4          2d   32        1
// cbPerScene                        cbuffer      NA          NA    0        1
// cbSceneParam                      cbuffer      NA          NA    8        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xy          1     NONE   float   xy  
// TEXCOORD                 1   xyzw        2     NONE   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb8[29], immediateIndexed
dcl_constantbuffer cb0[21], dynamicIndexed
dcl_sampler s7, mode_default
dcl_sampler s12, mode_comparison
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t32
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xy
dcl_output o0.xyzw
dcl_temps 6
sample_indexable(texture2d)(float,float,float,float) r0.z, v1.xyxx, t1.yzxw, s7
mul r1.xyz, r0.zzzz, l(65025.000000, 255.000000, 1.000000, 0.000000)
mov r0.xy, v2.xyxx
mov r0.w, l(1.000000)
dp4 r2.x, r0.xyzw, cb0[0].xyzw
dp4 r2.y, r0.xyzw, cb0[1].xyzw
dp4 r2.z, r0.xyzw, cb0[2].xyzw
dp4 r2.w, r0.xyzw, cb0[3].xyzw
div r0.xyz, r2.xyzx, r2.wwww
lt r3.xyz, cb0[20].xyzx, r0.zzzz
dp3 r0.x, r0.xyzx, r0.xyzx
sqrt r0.x, r0.x
add r0.x, -r0.x, cb8[28].x
mul_sat r0.x, r0.x, cb8[28].y
and r0.yzw, r3.xxyz, l(0, 1, 1, 1)
iadd r0.y, r0.z, r0.y
iadd r0.y, r0.w, r0.y
ishl r0.y, r0.y, l(2)
dp4 r3.x, r2.xyzw, cb0[r0.y + 4].xyzw
dp4 r3.y, r2.xyzw, cb0[r0.y + 5].xyzw
dp4 r3.z, r2.xyzw, cb0[r0.y + 6].xyzw
dp4 r3.w, r2.xyzw, cb0[r0.y + 7].xyzw
mul r2.xy, r3.wwww, cb8[28].zwzz
mov r2.w, -r2.x
mov r2.z, l(0)
add r4.xyzw, r2.ywzz, r3.xyzw
div r0.yzw, r4.xxyz, r4.wwww
sample_c_lz_indexable(texture2d)(float,float,float,float) r4.y, r0.yzyy, t32.xxxx, s12, r0.w
add r5.xyzw, r2.xyzz, r3.xyzw
div r0.yzw, r5.xxyz, r5.wwww
sample_c_lz_indexable(texture2d)(float,float,float,float) r4.x, r0.yzyy, t32.xxxx, s12, r0.w
mad r5.xyzw, r2.xyzz, l(-1.000000, -1.000000, 1.000000, 1.000000), r3.xyzw
mad r2.xyzw, r2.yxzz, l(-1.000000, 1.000000, 1.000000, 1.000000), r3.xyzw
div r0.yzw, r2.xxyz, r2.wwww
sample_c_lz_indexable(texture2d)(float,float,float,float) r4.w, r0.yzyy, t32.xxxx, s12, r0.w
div r0.yzw, r5.xxyz, r5.wwww
sample_c_lz_indexable(texture2d)(float,float,float,float) r4.z, r0.yzyy, t32.xxxx, s12, r0.w
dp4 r0.y, r4.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
add r0.y, -r0.y, l(1.000000)
mad o0.w, -r0.x, r0.y, l(1.000000)
frc r1.xy, r1.xyxx
mad o0.yz, -r1.xxyx, l(0.000000, 0.003922, 0.003922, 0.000000), r1.yyzy
mov o0.x, r1.x
ret 
// Approximately 44 instruction slots used

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