//dynamic shadows
// ---- Created with 3Dmigoto v1.2.39 on Tue Jun 14 08:56:12 2016

cbuffer _Globals : register(b0)
{
  float4x4 ScreenToWorldMatrix : packoffset(c0);
  bool bDecompressSceneColor : packoffset(c4);
  float4 SampleOffsets[2] : packoffset(c5);
  float3 ShadowBufferSizeAndSoftTransitionScale : packoffset(c7);
  float2 ShadowTexelSize : packoffset(c8);
  float LightingChannelMask : packoffset(c8.z);
  float SkipModShadow : packoffset(c8.w);
  float ShadowFadeFraction : packoffset(c9);
  float4x4 ScreenToShadowMatrix : packoffset(c10);
  float4 LightPositionAndInvRadius : packoffset(c14);
  float4x4 ShadowViewProjectionMatrices[6] : packoffset(c15);
  float ShadowmapResolution : packoffset(c39);
}

cbuffer PSOffsetConstants : register(b2)
{
  float4 ScreenPositionScaleBias : packoffset(c0);
  float4 MinZ_MaxZRatio : packoffset(c1);
  float NvStereoEnabled : packoffset(c2);
  float4 DiffuseOverrideParameter : packoffset(c3);
  float4 SpecularOverrideParameter : packoffset(c4);
  float4 CameraPositionPS : packoffset(c5);
  float4 ScreenAndTexelSize : packoffset(c6);
}

SamplerState SceneDepthTextureSampler_s : register(s0);
SamplerState NvStereoFixTextureSampler_s : register(s1);
SamplerState ShadowDepthTextureSampler_s : register(s2);
Texture2D<float4> SceneDepthTexture : register(t0);
Texture2D<float4> NvStereoFixTexture : register(t1);
Texture2D<float4> ShadowDepthTexture : register(t2);


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


void main( 
  float4 v0 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5,r20;
  uint4 bitmask, uiDest;
  float4 fDest;

r20.xyw = v0.xyw;
float4 stereo = StereoParams.Load(0);
r20.x += stereo.x*(r20.w - stereo.y);

  r0.x = cmp(0 != NvStereoEnabled);
  if (r0.x != 0) {
    r0.yz = NvStereoFixTexture.Sample(NvStereoFixTextureSampler_s, float2(0.0625,0)).xy;
    r0.z = v0.w + -r0.z;
    r1.x = r0.y * r0.z + v0.x;
    r1.yz = v0.yw;
  }
  r0.xyz = r0.xxx ? r1.xyz : v0.xyw;
  r0.xy = r0.xy / r0.zz;
  r0.xy = r0.xy * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
  r0.x = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r0.xy, 0).x;
  r0.x = min(0.999000013, r0.x);
  r0.x = r0.x * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r0.x = 1 / r0.x;
  r0.yz = r20.xy / v0.ww; //v0.xy
  r0.yz = r0.yz * r0.xx;

r0.y -= stereo.x*(r0.x - stereo.y);

  r1.xyzw = ScreenToShadowMatrix._m01_m11_m21_m31 * r0.zzzz;
  r1.xyzw = ScreenToShadowMatrix._m00_m10_m20_m30 * r0.yyyy + r1.xyzw;
  r0.xyzw = ScreenToShadowMatrix._m02_m12_m22_m32 * r0.xxxx + r1.xyzw;
  r0.xyzw = ScreenToShadowMatrix._m03_m13_m23_m33 + r0.xyzw;
  r0.xy = r0.xy / r0.ww;
  r0.z = min(0.999000013, r0.z);
  r1.xy = ShadowBufferSizeAndSoftTransitionScale.xy * r0.xy;
  r1.xy = frac(r1.xy);
  r0.xy = r0.xy * ShadowBufferSizeAndSoftTransitionScale.xy + float2(-1,-1);
  r0.xy = floor(r0.xy);
  r2.xyzw = float4(0.5,0.5,0.5,1.5) + r0.xyxy;
  r2.xyzw = ShadowTexelSize.xyxy * r2.xyzw;
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.xy, 0).x;
  r0.w = r0.w + -r0.z;
  r3.x = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.zw, 0).x;
  r0.w = r0.w + -r0.z;
  r3.y = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r2.xyzw = float4(0.5,2.5,1.5,0.5) + r0.xyxy;
  r2.xyzw = ShadowTexelSize.xyxy * r2.xyzw;
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.xy, 0).x;
  r0.w = r0.w + -r0.z;
  r3.z = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.zw, 0).x;
  r0.w = r0.w + -r0.z;
  r2.x = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r4.xyzw = float4(1.5,1.5,1.5,2.5) + r0.xyxy;
  r4.xyzw = ShadowTexelSize.xyxy * r4.xyzw;
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.xy, 0).x;
  r0.w = r0.w + -r0.z;
  r2.y = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.zw, 0).x;
  r0.w = r0.w + -r0.z;
  r2.z = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r4.xyzw = float4(2.5,0.5,2.5,1.5) + r0.xyxy;
  r4.xyzw = ShadowTexelSize.xyxy * r4.xyzw;
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.xy, 0).x;
  r0.w = r0.w + -r0.z;
  r5.x = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.zw, 0).x;
  r0.w = r0.w + -r0.z;
  r5.y = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.xy = float2(2.5,2.5) + r0.xy;
  r0.xy = ShadowTexelSize.xy * r0.xy;
  r0.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r0.xy, 0).x;
  r0.x = r0.x + -r0.z;
  r5.z = saturate(r0.x * ShadowBufferSizeAndSoftTransitionScale.z + 1);
  r0.xyzw = r2.xyyz + -r3.xyyz;
  r0.xyzw = r1.xxxx * r0.xyzw + r3.xyyz;
  r0.yw = r0.yw + -r0.xz;
  r0.xy = r1.yy * r0.yw + r0.xz;
  r3.xyzw = r5.xyyz + -r2.xyyz;
  r2.xyzw = r1.xxxx * r3.xyzw + r2.xyyz;
  r0.zw = r2.yw + -r2.xz;
  r0.zw = r1.yy * r0.zw + r2.xz;
  r0.x = r0.x + r0.y;
  r0.x = r0.x + r0.z;
  r0.x = r0.x + r0.w;
  r0.x = saturate(0.25 * r0.x);
  r0.x = r0.x * r0.x + -1;
  r0.x = ShadowFadeFraction * r0.x + 1;
  o0.xyzw = sqrt(r0.xxxx);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Tue Jun 14 08:56:12 2016
//
//
// Note: shader requires additional functionality:
//       Early depth-stencil
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4x4 ScreenToWorldMatrix;      // Offset:    0 Size:    64 [unused]
//   bool bDecompressSceneColor;        // Offset:   64 Size:     4 [unused]
//   float4 SampleOffsets[2];           // Offset:   80 Size:    32 [unused]
//   float3 ShadowBufferSizeAndSoftTransitionScale;// Offset:  112 Size:    12
//   float2 ShadowTexelSize;            // Offset:  128 Size:     8
//   float LightingChannelMask;         // Offset:  136 Size:     4 [unused]
//   float SkipModShadow;               // Offset:  140 Size:     4 [unused]
//   float ShadowFadeFraction;          // Offset:  144 Size:     4
//   float4x4 ScreenToShadowMatrix;     // Offset:  160 Size:    64
//   float4 LightPositionAndInvRadius;  // Offset:  224 Size:    16 [unused]
//   float4x4 ShadowViewProjectionMatrices[6];// Offset:  240 Size:   384 [unused]
//   float ShadowmapResolution;         // Offset:  624 Size:     4 [unused]
//
// }
//
// cbuffer PSOffsetConstants
// {
//
//   float4 ScreenPositionScaleBias;    // Offset:    0 Size:    16
//   float4 MinZ_MaxZRatio;             // Offset:   16 Size:    16
//   float NvStereoEnabled;             // Offset:   32 Size:     4
//   float4 DiffuseOverrideParameter;   // Offset:   48 Size:    16 [unused]
//   float4 SpecularOverrideParameter;  // Offset:   64 Size:    16 [unused]
//   float4 CameraPositionPS;           // Offset:   80 Size:    16 [unused]
//   float4 ScreenAndTexelSize;         // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SceneDepthTextureSampler          sampler      NA          NA    0        1
// NvStereoFixTextureSampler         sampler      NA          NA    1        1
// ShadowDepthTextureSampler         sampler      NA          NA    2        1
// SceneDepthTexture                 texture  float4          2d    0        1
// NvStereoFixTexture                texture  float4          2d    1        1
// ShadowDepthTexture                texture  float4          2d    2        1
// $Globals                          cbuffer      NA          NA    0        1
// PSOffsetConstants                 cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xyzw        0     NONE   float   xy w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed | forceEarlyDepthStencil
dcl_constantbuffer cb0[14], immediateIndexed
dcl_constantbuffer cb2[3], 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_input_ps linear v0.xyw
dcl_output o0.xyzw
dcl_temps 6
ne r0.x, l(0.000000, 0.000000, 0.000000, 0.000000), cb2[2].x
if_nz r0.x
  sample_indexable(texture2d)(float,float,float,float) r0.yz, l(0.062500, 0.000000, 0.000000, 0.000000), t1.zxyw, s1
  add r0.z, -r0.z, v0.w
  mad r1.x, r0.y, r0.z, v0.x
  mov r1.yz, v0.yywy
endif 
movc r0.xyz, r0.xxxx, r1.xyzx, v0.xywx
div r0.xy, r0.xyxx, r0.zzzz
mad r0.xy, r0.xyxx, cb2[0].xyxx, cb2[0].wzww
sample_l_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t0.xyzw, s0, l(0.000000)
min r0.x, r0.x, l(0.999000)
mad r0.x, r0.x, cb2[1].z, -cb2[1].w
div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
div r0.yz, v0.xxyx, v0.wwww
mul r0.yz, r0.xxxx, r0.yyzy
mul r1.xyzw, r0.zzzz, cb0[11].xyzw
mad r1.xyzw, cb0[10].xyzw, r0.yyyy, r1.xyzw
mad r0.xyzw, cb0[12].xyzw, r0.xxxx, r1.xyzw
add r0.xyzw, r0.xyzw, cb0[13].xyzw
div r0.xy, r0.xyxx, r0.wwww
min r0.z, r0.z, l(0.999000)
mul r1.xy, r0.xyxx, cb0[7].xyxx
frc r1.xy, r1.xyxx
mad r0.xy, r0.xyxx, cb0[7].xyxx, l(-1.000000, -1.000000, 0.000000, 0.000000)
round_ni r0.xy, r0.xyxx
add r2.xyzw, r0.xyxy, l(0.500000, 0.500000, 0.500000, 1.500000)
mul r2.xyzw, r2.xyzw, cb0[8].xyxy
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r2.xyxx, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r3.x, r0.w, cb0[7].z, l(1.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r2.zwzz, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r3.y, r0.w, cb0[7].z, l(1.000000)
add r2.xyzw, r0.xyxy, l(0.500000, 2.500000, 1.500000, 0.500000)
mul r2.xyzw, r2.xyzw, cb0[8].xyxy
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r2.xyxx, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r3.z, r0.w, cb0[7].z, l(1.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r2.zwzz, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r2.x, r0.w, cb0[7].z, l(1.000000)
add r4.xyzw, r0.xyxy, l(1.500000, 1.500000, 1.500000, 2.500000)
mul r4.xyzw, r4.xyzw, cb0[8].xyxy
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r4.xyxx, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r2.y, r0.w, cb0[7].z, l(1.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r4.zwzz, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r2.z, r0.w, cb0[7].z, l(1.000000)
add r4.xyzw, r0.xyxy, l(2.500000, 0.500000, 2.500000, 1.500000)
mul r4.xyzw, r4.xyzw, cb0[8].xyxy
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r4.xyxx, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r5.x, r0.w, cb0[7].z, l(1.000000)
sample_l_indexable(texture2d)(float,float,float,float) r0.w, r4.zwzz, t2.yzwx, s2, l(0.000000)
add r0.w, -r0.z, r0.w
mad_sat r5.y, r0.w, cb0[7].z, l(1.000000)
add r0.xy, r0.xyxx, l(2.500000, 2.500000, 0.000000, 0.000000)
mul r0.xy, r0.xyxx, cb0[8].xyxx
sample_l_indexable(texture2d)(float,float,float,float) r0.x, r0.xyxx, t2.xyzw, s2, l(0.000000)
add r0.x, -r0.z, r0.x
mad_sat r5.z, r0.x, cb0[7].z, l(1.000000)
add r0.xyzw, -r3.xyyz, r2.xyyz
mad r0.xyzw, r1.xxxx, r0.xyzw, r3.xyyz
add r0.yw, -r0.xxxz, r0.yyyw
mad r0.xy, r1.yyyy, r0.ywyy, r0.xzxx
add r3.xyzw, -r2.xyyz, r5.xyyz
mad r2.xyzw, r1.xxxx, r3.xyzw, r2.xyyz
add r0.zw, -r2.xxxz, r2.yyyw
mad r0.zw, r1.yyyy, r0.zzzw, r2.xxxz
add r0.x, r0.y, r0.x
add r0.x, r0.z, r0.x
add r0.x, r0.w, r0.x
mul_sat r0.x, r0.x, l(0.250000)
mad r0.x, r0.x, r0.x, l(-1.000000)
mad r0.x, cb0[9].x, r0.x, l(1.000000)
sqrt o0.xyzw, r0.xxxx
ret 
// Approximately 79 instruction slots used

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