// ---- Created with 3Dmigoto v1.2.39 on Wed Jun 15 12:11:23 2016

cbuffer _Globals : register(b0)
{
  float4x4 ScreenToWorldMatrix : packoffset(c0);
  bool bDecompressSceneColor : packoffset(c4);
  float4 ShadowModulateColor : packoffset(c5);
  float4 LightPosition : packoffset(c6);
  float4x4 ScreenToWorld : packoffset(c7);
  float3 FalloffParameters : packoffset(c11);
  float3 SpotDirection : packoffset(c12);
  float2 SpotAngles : packoffset(c13);
  float4 SampleOffsets[2] : packoffset(c14);
  float3 ShadowBufferSizeAndSoftTransitionScale : packoffset(c16);
  float2 ShadowTexelSize : packoffset(c17);
  float LightingChannelMask : packoffset(c17.z);
  float SkipModShadow : packoffset(c17.w);
  float4x4 ScreenToShadowMatrix : packoffset(c18);
}

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 DiffuseGBufferTextureSampler_s : register(s0);
SamplerState SceneDepthTextureSampler_s : register(s1);
SamplerState NvStereoFixTextureSampler_s : register(s2);
SamplerState ShadowDepthTextureSampler_s : register(s3);
Texture2D<float4> DiffuseGBufferTexture : register(t0);
Texture2D<float4> SceneDepthTexture : register(t1);
Texture2D<float4> NvStereoFixTexture : register(t2);
Texture2D<float4> ShadowDepthTexture : register(t3);


// 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.xy = r20.xy / v0.ww;
  r0.zw = r0.xy * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
  r0.z = DiffuseGBufferTexture.SampleLevel(DiffuseGBufferTextureSampler_s, r0.zw, 0).w;
  r0.z = 64 * r0.z;
  r0.w = cmp(0 != SkipModShadow);
  r0.z = (int)r0.z;
  r1.x = LightingChannelMask;
  r0.z = (int)r0.z & (int)r1.x;
  r0.z = cmp((int)r0.z != 0);
  r0.z = (int)r0.z | (int)r0.w;
  if (r0.z != 0) {
    r0.z = cmp(0 != NvStereoEnabled);
    if (r0.z != 0) {
      r1.xy = NvStereoFixTexture.Sample(NvStereoFixTextureSampler_s, float2(0.0625,0)).xy;
      r0.w = v0.w + -r1.y;
      r1.x = r1.x * r0.w + v0.x;
      r1.yz = v0.yw;
    }
    r1.xyz = r0.zzz ? r1.xyz : v0.xyw;
    r0.zw = r1.xy / r1.zz;
    r0.zw = r0.zw * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
    r0.z = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r0.zw, 0).x;
    r0.z = min(0.999000013, r0.z);
    r0.z = r0.z * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
    r0.z = 1 / r0.z;
    r0.xy = r0.xy * r0.zz;

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

    r1.xyzw = ScreenToShadowMatrix._m01_m11_m21_m31 * r0.yyyy;
    r1.xyzw = ScreenToShadowMatrix._m00_m10_m20_m30 * r0.xxxx + r1.xyzw;
    r1.xyzw = ScreenToShadowMatrix._m02_m12_m22_m32 * r0.zzzz + r1.xyzw;
    r1.xyzw = ScreenToShadowMatrix._m03_m13_m23_m33 + r1.xyzw;
    r1.xy = r1.xy / r1.ww;
    r0.w = min(0.999000013, r1.z);
    r1.zw = ShadowBufferSizeAndSoftTransitionScale.xy * r1.xy;
    r1.zw = frac(r1.zw);
    r1.xy = r1.xy * ShadowBufferSizeAndSoftTransitionScale.xy + float2(-1,-1);
    r1.xy = floor(r1.xy);
    r2.xyzw = float4(0.5,0.5,0.5,1.5) + r1.xyxy;
    r2.xyzw = ShadowTexelSize.xyxy * r2.xyzw;
    r2.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.xy, 0).x;
    r2.x = r2.x + -r0.w;
    r3.x = saturate(r2.x * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r2.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.zw, 0).x;
    r2.x = r2.x + -r0.w;
    r3.y = saturate(r2.x * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r2.xyzw = float4(0.5,2.5,1.5,0.5) + r1.xyxy;
    r2.xyzw = ShadowTexelSize.xyxy * r2.xyzw;
    r2.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.xy, 0).x;
    r2.x = r2.x + -r0.w;
    r3.z = saturate(r2.x * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r2.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r2.zw, 0).x;
    r2.x = r2.x + -r0.w;
    r2.x = saturate(r2.x * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r4.xyzw = float4(1.5,1.5,1.5,2.5) + r1.xyxy;
    r4.xyzw = ShadowTexelSize.xyxy * r4.xyzw;
    r2.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.xy, 0).x;
    r2.w = r2.w + -r0.w;
    r2.y = saturate(r2.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r2.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.zw, 0).x;
    r2.w = r2.w + -r0.w;
    r2.z = saturate(r2.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r4.xyzw = float4(2.5,0.5,2.5,1.5) + r1.xyxy;
    r4.xyzw = ShadowTexelSize.xyxy * r4.xyzw;
    r2.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.xy, 0).x;
    r2.w = r2.w + -r0.w;
    r5.x = saturate(r2.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r2.w = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r4.zw, 0).x;
    r2.w = r2.w + -r0.w;
    r5.y = saturate(r2.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r1.xy = float2(2.5,2.5) + r1.xy;
    r1.xy = ShadowTexelSize.xy * r1.xy;
    r1.x = ShadowDepthTexture.SampleLevel(ShadowDepthTextureSampler_s, r1.xy, 0).x;
    r0.w = r1.x + -r0.w;
    r5.z = saturate(r0.w * ShadowBufferSizeAndSoftTransitionScale.z + 1);
    r4.xyzw = r2.xyyz + -r3.xyyz;
    r3.xyzw = r1.zzzz * r4.xyzw + r3.xyyz;
    r1.xy = r3.yw + -r3.xz;
    r1.xy = r1.ww * r1.xy + r3.xz;
    r3.xyzw = r5.xyyz + -r2.xyyz;
    r2.xyzw = r1.zzzz * r3.xyzw + r2.xyyz;
    r2.yw = r2.yw + -r2.xz;
    r1.zw = r1.ww * r2.yw + r2.xz;
    r0.w = r1.x + r1.y;
    r0.w = r0.w + r1.z;
    r0.w = r0.w + r1.w;
    r0.w = saturate(0.25 * r0.w);
    r1.xyz = ScreenToWorld._m01_m11_m21 * r0.yyy;
    r1.xyz = ScreenToWorld._m00_m10_m20 * r0.xxx + r1.xyz;
    r0.xyz = ScreenToWorld._m02_m12_m22 * r0.zzz + r1.xyz;
    r0.xyz = ScreenToWorld._m03_m13_m23 + r0.xyz;
    r0.xyz = LightPosition.xyz + -r0.xyz;
    r0.xyz = LightPosition.www * r0.xyz;
    r1.x = dot(r0.xyz, r0.xyz);
    r1.y = sqrt(r1.x);
    r1.y = r1.y * FalloffParameters.y + FalloffParameters.z;
    r1.y = max(0, r1.y);
    r1.y = -r1.y * r1.y + 1;
    r1.y = max(0, r1.y);
    r1.y = log2(r1.y);
    r1.y = FalloffParameters.x * r1.y;
    r1.y = exp2(r1.y);
    r1.x = rsqrt(r1.x);
    r0.xyz = r1.xxx * r0.xyz;
    r0.x = dot(r0.xyz, -SpotDirection.xyz);
    r0.x = -SpotAngles.x + r0.x;
    r0.x = saturate(SpotAngles.y * r0.x);
    r0.x = r0.x * r0.x;
    r0.x = r1.y * r0.x;
    r1.xyzw = float4(-1,-1,-1,-1) + ShadowModulateColor.xyzw;
    r1.xyzw = r0.xxxx * r1.xyzw + float4(1,1,1,1);
    r0.x = r0.w * r0.w;
    r2.xyzw = float4(1,1,1,1) + -r1.xyzw;
    o0.xyzw = r0.xxxx * r2.xyzw + r1.xyzw;
  } else {
    o0.xyzw = float4(1,1,1,1);
  }
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Wed Jun 15 12:11:23 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 ShadowModulateColor;        // Offset:   80 Size:    16
//   float4 LightPosition;              // Offset:   96 Size:    16
//   float4x4 ScreenToWorld;            // Offset:  112 Size:    64
//   float3 FalloffParameters;          // Offset:  176 Size:    12
//   float3 SpotDirection;              // Offset:  192 Size:    12
//   float2 SpotAngles;                 // Offset:  208 Size:     8
//   float4 SampleOffsets[2];           // Offset:  224 Size:    32 [unused]
//   float3 ShadowBufferSizeAndSoftTransitionScale;// Offset:  256 Size:    12
//   float2 ShadowTexelSize;            // Offset:  272 Size:     8
//   float LightingChannelMask;         // Offset:  280 Size:     4
//   float SkipModShadow;               // Offset:  284 Size:     4
//   float4x4 ScreenToShadowMatrix;     // Offset:  288 Size:    64
//
// }
//
// 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
// ------------------------------ ---------- ------- ----------- ---- --------
// DiffuseGBufferTextureSampler      sampler      NA          NA    0        1
// SceneDepthTextureSampler          sampler      NA          NA    1        1
// NvStereoFixTextureSampler         sampler      NA          NA    2        1
// ShadowDepthTextureSampler         sampler      NA          NA    3        1
// DiffuseGBufferTexture             texture  float4          2d    0        1
// SceneDepthTexture                 texture  float4          2d    1        1
// NvStereoFixTexture                texture  float4          2d    2        1
// ShadowDepthTexture                texture  float4          2d    3        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[22], immediateIndexed
dcl_constantbuffer cb2[3], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, 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_input_ps linear v0.xyw
dcl_output o0.xyzw
dcl_temps 6
div r0.xy, v0.xyxx, v0.wwww
mad r0.zw, r0.xxxy, cb2[0].xxxy, cb2[0].wwwz
sample_l_indexable(texture2d)(float,float,float,float) r0.z, r0.zwzz, t0.xywz, s0, l(0.000000)
mul r0.z, r0.z, l(64.000000)
ne r0.w, l(0.000000, 0.000000, 0.000000, 0.000000), cb0[17].w
ftoi r0.z, r0.z
ftoi r1.x, cb0[17].z
and r0.z, r0.z, r1.x
ine r0.z, r0.z, l(0)
or r0.z, r0.z, r0.w
if_nz r0.z
  ne r0.z, l(0.000000, 0.000000, 0.000000, 0.000000), cb2[2].x
  if_nz r0.z
    sample_indexable(texture2d)(float,float,float,float) r1.xy, l(0.062500, 0.000000, 0.000000, 0.000000), t2.xyzw, s2
    add r0.w, -r1.y, v0.w
    mad r1.x, r1.x, r0.w, v0.x
    mov r1.yz, v0.yywy
  endif 
  movc r1.xyz, r0.zzzz, r1.xyzx, v0.xywx
  div r0.zw, r1.xxxy, r1.zzzz
  mad r0.zw, r0.zzzw, cb2[0].xxxy, cb2[0].wwwz
  sample_l_indexable(texture2d)(float,float,float,float) r0.z, r0.zwzz, t1.yzxw, s1, l(0.000000)
  min r0.z, r0.z, l(0.999000)
  mad r0.z, r0.z, cb2[1].z, -cb2[1].w
  div r0.z, l(1.000000, 1.000000, 1.000000, 1.000000), r0.z
  mul r0.xy, r0.zzzz, r0.xyxx
  mul r1.xyzw, r0.yyyy, cb0[19].xyzw
  mad r1.xyzw, cb0[18].xyzw, r0.xxxx, r1.xyzw
  mad r1.xyzw, cb0[20].xyzw, r0.zzzz, r1.xyzw
  add r1.xyzw, r1.xyzw, cb0[21].xyzw
  div r1.xy, r1.xyxx, r1.wwww
  min r0.w, r1.z, l(0.999000)
  mul r1.zw, r1.xxxy, cb0[16].xxxy
  frc r1.zw, r1.zzzw
  mad r1.xy, r1.xyxx, cb0[16].xyxx, l(-1.000000, -1.000000, 0.000000, 0.000000)
  round_ni r1.xy, r1.xyxx
  add r2.xyzw, r1.xyxy, l(0.500000, 0.500000, 0.500000, 1.500000)
  mul r2.xyzw, r2.xyzw, cb0[17].xyxy
  sample_l_indexable(texture2d)(float,float,float,float) r2.x, r2.xyxx, t3.xyzw, s3, l(0.000000)
  add r2.x, -r0.w, r2.x
  mad_sat r3.x, r2.x, cb0[16].z, l(1.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r2.x, r2.zwzz, t3.xyzw, s3, l(0.000000)
  add r2.x, -r0.w, r2.x
  mad_sat r3.y, r2.x, cb0[16].z, l(1.000000)
  add r2.xyzw, r1.xyxy, l(0.500000, 2.500000, 1.500000, 0.500000)
  mul r2.xyzw, r2.xyzw, cb0[17].xyxy
  sample_l_indexable(texture2d)(float,float,float,float) r2.x, r2.xyxx, t3.xyzw, s3, l(0.000000)
  add r2.x, -r0.w, r2.x
  mad_sat r3.z, r2.x, cb0[16].z, l(1.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r2.x, r2.zwzz, t3.xyzw, s3, l(0.000000)
  add r2.x, -r0.w, r2.x
  mad_sat r2.x, r2.x, cb0[16].z, l(1.000000)
  add r4.xyzw, r1.xyxy, l(1.500000, 1.500000, 1.500000, 2.500000)
  mul r4.xyzw, r4.xyzw, cb0[17].xyxy
  sample_l_indexable(texture2d)(float,float,float,float) r2.w, r4.xyxx, t3.yzwx, s3, l(0.000000)
  add r2.w, -r0.w, r2.w
  mad_sat r2.y, r2.w, cb0[16].z, l(1.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r2.w, r4.zwzz, t3.yzwx, s3, l(0.000000)
  add r2.w, -r0.w, r2.w
  mad_sat r2.z, r2.w, cb0[16].z, l(1.000000)
  add r4.xyzw, r1.xyxy, l(2.500000, 0.500000, 2.500000, 1.500000)
  mul r4.xyzw, r4.xyzw, cb0[17].xyxy
  sample_l_indexable(texture2d)(float,float,float,float) r2.w, r4.xyxx, t3.yzwx, s3, l(0.000000)
  add r2.w, -r0.w, r2.w
  mad_sat r5.x, r2.w, cb0[16].z, l(1.000000)
  sample_l_indexable(texture2d)(float,float,float,float) r2.w, r4.zwzz, t3.yzwx, s3, l(0.000000)
  add r2.w, -r0.w, r2.w
  mad_sat r5.y, r2.w, cb0[16].z, l(1.000000)
  add r1.xy, r1.xyxx, l(2.500000, 2.500000, 0.000000, 0.000000)
  mul r1.xy, r1.xyxx, cb0[17].xyxx
  sample_l_indexable(texture2d)(float,float,float,float) r1.x, r1.xyxx, t3.xyzw, s3, l(0.000000)
  add r0.w, -r0.w, r1.x
  mad_sat r5.z, r0.w, cb0[16].z, l(1.000000)
  add r4.xyzw, -r3.xyyz, r2.xyyz
  mad r3.xyzw, r1.zzzz, r4.xyzw, r3.xyyz
  add r1.xy, -r3.xzxx, r3.ywyy
  mad r1.xy, r1.wwww, r1.xyxx, r3.xzxx
  add r3.xyzw, -r2.xyyz, r5.xyyz
  mad r2.xyzw, r1.zzzz, r3.xyzw, r2.xyyz
  add r2.yw, -r2.xxxz, r2.yyyw
  mad r1.zw, r1.wwww, r2.yyyw, r2.xxxz
  add r0.w, r1.y, r1.x
  add r0.w, r1.z, r0.w
  add r0.w, r1.w, r0.w
  mul_sat r0.w, r0.w, l(0.250000)
  mul r1.xyz, r0.yyyy, cb0[8].xyzx
  mad r1.xyz, cb0[7].xyzx, r0.xxxx, r1.xyzx
  mad r0.xyz, cb0[9].xyzx, r0.zzzz, r1.xyzx
  add r0.xyz, r0.xyzx, cb0[10].xyzx
  add r0.xyz, -r0.xyzx, cb0[6].xyzx
  mul r0.xyz, r0.xyzx, cb0[6].wwww
  dp3 r1.x, r0.xyzx, r0.xyzx
  sqrt r1.y, r1.x
  mad r1.y, r1.y, cb0[11].y, cb0[11].z
  max r1.y, r1.y, l(0.000000)
  mad r1.y, -r1.y, r1.y, l(1.000000)
  max r1.y, r1.y, l(0.000000)
  log r1.y, r1.y
  mul r1.y, r1.y, cb0[11].x
  exp r1.y, r1.y
  rsq r1.x, r1.x
  mul r0.xyz, r0.xyzx, r1.xxxx
  dp3 r0.x, r0.xyzx, -cb0[12].xyzx
  add r0.x, r0.x, -cb0[13].x
  mul_sat r0.x, r0.x, cb0[13].y
  mul r0.x, r0.x, r0.x
  mul r0.x, r0.x, r1.y
  add r1.xyzw, cb0[5].xyzw, l(-1.000000, -1.000000, -1.000000, -1.000000)
  mad r1.xyzw, r0.xxxx, r1.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
  mul r0.x, r0.w, r0.w
  add r2.xyzw, -r1.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
  mad o0.xyzw, r0.xxxx, r2.xyzw, r1.xyzw
else 
  mov o0.xyzw, l(1.000000,1.000000,1.000000,1.000000)
endif 
ret 
// Approximately 116 instruction slots used

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