// ---- Created with 3Dmigoto v1.2.39 on Tue Jun 14 10:51:10 2016

cbuffer _Globals : register(b0)
{
  float4x4 ScreenToWorldMatrix : packoffset(c0);
  bool bDecompressSceneColor : packoffset(c4);
  float4 LightColorAndFalloffExponent : packoffset(c5);
  float3 DistanceFieldParameters : packoffset(c6);
  float4x4 ScreenToShadowMatrix : packoffset(c7);
  float4 ShadowBufferAndTexelSize : packoffset(c11);
  float ShadowOverrideFactor : packoffset(c12);
  float SSSMultiplier : packoffset(c12.y);
  bool bReceiveDynamicShadows : packoffset(c12.z);
  bool bEnableDistanceShadowFading : packoffset(c12.w);
  float2 DistanceFadeParameters : packoffset(c13);
  float4 IBLPositionAndWeight0 : packoffset(c14);
  float4 IBLPositionAndWeight1 : packoffset(c15);
  float4 IBLPositionAndWeight2 : packoffset(c16);
  float4 IBLPositionAndWeight3 : packoffset(c17);
  float4x4 IBLProxyOBB0 : packoffset(c18);
  float4x4 IBLProxyOBB1 : packoffset(c22);
  float4x4 IBLProxyOBB2 : packoffset(c26);
  float4 IBLUseProxyVolume : packoffset(c30);
  float4x4 IBLLastProxyOBB0 : packoffset(c31);
  float4x4 IBLLastProxyOBB1 : packoffset(c35);
  float4x4 IBLLastProxyOBB2 : packoffset(c39);
  float4 IBLUseLastProxyVolume : packoffset(c43);
  float ForcedIBLWeight : packoffset(c44);
  float AdditionalReflections : packoffset(c44.y);
  float4 DeferredRenderingParameters : packoffset(c45);
  float4 LightPositionAndInvRadius : packoffset(c46);
  float4 LightDirectionAndChannel : packoffset(c47);
  float2 SpotAngles : packoffset(c48);
}

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 WorldNormalGBufferTextureSampler_s : register(s0);
SamplerState SpecularGBufferTextureSampler_s : register(s1);
SamplerState DiffuseGBufferTextureSampler_s : register(s2);
SamplerState SceneDepthTextureSampler_s : register(s3);
SamplerState LightAttenuationTextureSampler_s : register(s4);
Texture2D<float4> WorldNormalGBufferTexture : register(t0);
Texture2D<float4> SpecularGBufferTexture : register(t1);
Texture2D<float4> DiffuseGBufferTexture : register(t2);
Texture2D<float4> SceneDepthTexture : register(t3);
Texture2D<float4> LightAttenuationTexture : register(t4);


// 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,r6;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v0.xy / v0.ww;
  r0.zw = r0.xy * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
  r1.xyzw = WorldNormalGBufferTexture.SampleLevel(WorldNormalGBufferTextureSampler_s, r0.zw, 0).xyzw;
  r1.xyzw = r1.xyzw * float4(2,2,2,1) + float4(-1,-1,-1,-0);
  r1.w = cmp(0 < r1.w);
  if (r1.w != 0) {
    r2.xyzw = DiffuseGBufferTexture.SampleLevel(DiffuseGBufferTextureSampler_s, r0.zw, 0).xyzw;
    r1.w = 64 * r2.w;
    r1.w = (int)r1.w;
    r2.w = (int)LightDirectionAndChannel.w;
    r1.w = (int)r1.w & (int)r2.w;
    if (r1.w != 0) {
      r1.w = SceneDepthTexture.SampleLevel(SceneDepthTextureSampler_s, r0.zw, 0).x;
      r1.w = min(0.999000013, r1.w);
      r1.w = r1.w * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
      r1.w = 1 / r1.w;
      r0.xy = r1.ww * r0.xy;

float4 stereo = StereoParams.Load(0);
r0.x -= stereo.x*(r1.w - stereo.y);

      r3.xyz = ScreenToWorldMatrix._m01_m11_m21 * r0.yyy;
      r3.xyz = ScreenToWorldMatrix._m00_m10_m20 * r0.xxx + r3.xyz;
      r3.xyz = ScreenToWorldMatrix._m02_m12_m22 * r1.www + r3.xyz;
      r3.xyz = ScreenToWorldMatrix._m03_m13_m23 + r3.xyz;
      r4.xyz = LightPositionAndInvRadius.xyz + -r3.xyz;
      r4.xyz = LightPositionAndInvRadius.www * r4.xyz;
      r0.x = dot(r4.xyz, r4.xyz);
      r0.y = min(1, r0.x);
      r0.y = 1 + -r0.y;
      r0.y = log2(r0.y);
      r0.y = LightColorAndFalloffExponent.w * r0.y;
      r0.y = exp2(r0.y);
      r1.w = cmp(0 < r0.y);
      if (r1.w != 0) {
        r3.xyz = -CameraPositionPS.xyz + r3.xyz;
        r1.w = dot(r3.xyz, r3.xyz);
        r1.w = rsqrt(r1.w);
        r3.xyz = r3.xyz * r1.www;
        r5.xyzw = SpecularGBufferTexture.SampleLevel(SpecularGBufferTextureSampler_s, r0.zw, 0).xyzw;
        r6.xyz = LightAttenuationTexture.SampleLevel(LightAttenuationTextureSampler_s, r0.zw, 0).xyz;
        r6.xyz = r6.xyz * r6.xyz;
        r0.x = rsqrt(r0.x);
        r0.xzw = r4.xyz * r0.xxx;
        r1.w = dot(r3.xyz, r1.xyz);
        r1.w = r1.w + r1.w;
        r3.xyz = r1.xyz * -r1.www + r3.xyz;
        r1.w = cmp(r5.w < 0.501960814);
        r2.w = r5.w * r5.w;
        r1.w = r1.w ? -0 : -0.501960814;
        r1.w = r2.w * 500 + r1.w;
        r1.w = 2.00787401 * r1.w;
        r1.x = saturate(dot(r1.xyz, r0.xzw));
        r1.y = cmp(r1.x < 9.99999997e-007);
        r1.x = r1.y ? 0 : r1.x;
        r0.x = saturate(dot(r3.xyz, r0.xzw));
        r0.z = cmp(r0.x < 9.99999997e-007);
        r0.x = log2(r0.x);
        r0.x = r1.w * r0.x;
        r0.x = exp2(r0.x);
        r0.x = r0.z ? 0 : r0.x;
        r0.xzw = r0.xxx * r5.xyz;
        r0.xzw = r2.xyz * r1.xxx + r0.xzw;
        r1.xyz = r6.xyz * r0.yyy;
        r1.xyz = LightColorAndFalloffExponent.xyz * r1.xyz;
        r0.xyz = r1.xyz * r0.xzw;
      } else {
        r0.xyz = float3(0,0,0);
      }
    } else {
      r0.xyz = float3(0,0,0);
    }
  } else {
    r0.xyz = float3(0,0,0);
  }
  o0.xyz = r0.xyz;
  o0.w = 0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Tue Jun 14 10:51:10 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4x4 ScreenToWorldMatrix;      // Offset:    0 Size:    64
//   bool bDecompressSceneColor;        // Offset:   64 Size:     4 [unused]
//   float4 LightColorAndFalloffExponent;// Offset:   80 Size:    16
//   float3 DistanceFieldParameters;    // Offset:   96 Size:    12 [unused]
//   float4x4 ScreenToShadowMatrix;     // Offset:  112 Size:    64 [unused]
//   float4 ShadowBufferAndTexelSize;   // Offset:  176 Size:    16 [unused]
//   float ShadowOverrideFactor;        // Offset:  192 Size:     4 [unused]
//   float SSSMultiplier;               // Offset:  196 Size:     4 [unused]
//   bool bReceiveDynamicShadows;       // Offset:  200 Size:     4 [unused]
//   bool bEnableDistanceShadowFading;  // Offset:  204 Size:     4 [unused]
//   float2 DistanceFadeParameters;     // Offset:  208 Size:     8 [unused]
//   float4 IBLPositionAndWeight0;      // Offset:  224 Size:    16 [unused]
//   float4 IBLPositionAndWeight1;      // Offset:  240 Size:    16 [unused]
//   float4 IBLPositionAndWeight2;      // Offset:  256 Size:    16 [unused]
//   float4 IBLPositionAndWeight3;      // Offset:  272 Size:    16 [unused]
//   float4x4 IBLProxyOBB0;             // Offset:  288 Size:    64 [unused]
//   float4x4 IBLProxyOBB1;             // Offset:  352 Size:    64 [unused]
//   float4x4 IBLProxyOBB2;             // Offset:  416 Size:    64 [unused]
//   float4 IBLUseProxyVolume;          // Offset:  480 Size:    16 [unused]
//   float4x4 IBLLastProxyOBB0;         // Offset:  496 Size:    64 [unused]
//   float4x4 IBLLastProxyOBB1;         // Offset:  560 Size:    64 [unused]
//   float4x4 IBLLastProxyOBB2;         // Offset:  624 Size:    64 [unused]
//   float4 IBLUseLastProxyVolume;      // Offset:  688 Size:    16 [unused]
//   float ForcedIBLWeight;             // Offset:  704 Size:     4 [unused]
//   float AdditionalReflections;       // Offset:  708 Size:     4 [unused]
//   float4 DeferredRenderingParameters;// Offset:  720 Size:    16 [unused]
//   float4 LightPositionAndInvRadius;  // Offset:  736 Size:    16
//   float4 LightDirectionAndChannel;   // Offset:  752 Size:    16
//   float2 SpotAngles;                 // Offset:  768 Size:     8 [unused]
//
// }
//
// cbuffer PSOffsetConstants
// {
//
//   float4 ScreenPositionScaleBias;    // Offset:    0 Size:    16
//   float4 MinZ_MaxZRatio;             // Offset:   16 Size:    16
//   float NvStereoEnabled;             // Offset:   32 Size:     4 [unused]
//   float4 DiffuseOverrideParameter;   // Offset:   48 Size:    16 [unused]
//   float4 SpecularOverrideParameter;  // Offset:   64 Size:    16 [unused]
//   float4 CameraPositionPS;           // Offset:   80 Size:    16
//   float4 ScreenAndTexelSize;         // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// WorldNormalGBufferTextureSampler    sampler      NA          NA    0        1
// SpecularGBufferTextureSampler     sampler      NA          NA    1        1
// DiffuseGBufferTextureSampler      sampler      NA          NA    2        1
// SceneDepthTextureSampler          sampler      NA          NA    3        1
// LightAttenuationTextureSampler    sampler      NA          NA    4        1
// WorldNormalGBufferTexture         texture  float4          2d    0        1
// SpecularGBufferTexture            texture  float4          2d    1        1
// DiffuseGBufferTexture             texture  float4          2d    2        1
// SceneDepthTexture                 texture  float4          2d    3        1
// LightAttenuationTexture           texture  float4          2d    4        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
dcl_constantbuffer cb0[48], immediateIndexed
dcl_constantbuffer cb2[6], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_sampler s4, 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_resource_texture2d (float,float,float,float) t4
dcl_input_ps linear v0.xyw
dcl_output o0.xyzw
dcl_temps 7
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) r1.xyzw, r0.zwzz, t0.xyzw, s0, l(0.000000)
mad r1.xyzw, r1.xyzw, l(2.000000, 2.000000, 2.000000, 1.000000), l(-1.000000, -1.000000, -1.000000, -0.000000)
lt r1.w, l(0.000000), r1.w
if_nz r1.w
  sample_l_indexable(texture2d)(float,float,float,float) r2.xyzw, r0.zwzz, t2.xyzw, s2, l(0.000000)
  mul r1.w, r2.w, l(64.000000)
  ftoi r1.w, r1.w
  ftoi r2.w, cb0[47].w
  and r1.w, r1.w, r2.w
  if_nz r1.w
    sample_l_indexable(texture2d)(float,float,float,float) r1.w, r0.zwzz, t3.yzwx, s3, l(0.000000)
    min r1.w, r1.w, l(0.999000)
    mad r1.w, r1.w, cb2[1].z, -cb2[1].w
    div r1.w, l(1.000000, 1.000000, 1.000000, 1.000000), r1.w
    mul r0.xy, r0.xyxx, r1.wwww
    mul r3.xyz, r0.yyyy, cb0[1].xyzx
    mad r3.xyz, cb0[0].xyzx, r0.xxxx, r3.xyzx
    mad r3.xyz, cb0[2].xyzx, r1.wwww, r3.xyzx
    add r3.xyz, r3.xyzx, cb0[3].xyzx
    add r4.xyz, -r3.xyzx, cb0[46].xyzx
    mul r4.xyz, r4.xyzx, cb0[46].wwww
    dp3 r0.x, r4.xyzx, r4.xyzx
    min r0.y, r0.x, l(1.000000)
    add r0.y, -r0.y, l(1.000000)
    log r0.y, r0.y
    mul r0.y, r0.y, cb0[5].w
    exp r0.y, r0.y
    lt r1.w, l(0.000000), r0.y
    if_nz r1.w
      add r3.xyz, r3.xyzx, -cb2[5].xyzx
      dp3 r1.w, r3.xyzx, r3.xyzx
      rsq r1.w, r1.w
      mul r3.xyz, r1.wwww, r3.xyzx
      sample_l_indexable(texture2d)(float,float,float,float) r5.xyzw, r0.zwzz, t1.xyzw, s1, l(0.000000)
      sample_l_indexable(texture2d)(float,float,float,float) r6.xyz, r0.zwzz, t4.xyzw, s4, l(0.000000)
      mul r6.xyz, r6.xyzx, r6.xyzx
      rsq r0.x, r0.x
      mul r0.xzw, r0.xxxx, r4.xxyz
      dp3 r1.w, r3.xyzx, r1.xyzx
      add r1.w, r1.w, r1.w
      mad r3.xyz, r1.xyzx, -r1.wwww, r3.xyzx
      lt r1.w, r5.w, l(0.501960814)
      mul r2.w, r5.w, r5.w
      movc r1.w, r1.w, l(-0.000000), l(-0.501960814)
      mad r1.w, r2.w, l(500.000000), r1.w
      mul r1.w, r1.w, l(2.007874)
      dp3_sat r1.x, r1.xyzx, r0.xzwx
      lt r1.y, r1.x, l(0.000001)
      movc r1.x, r1.y, l(0), r1.x
      dp3_sat r0.x, r3.xyzx, r0.xzwx
      lt r0.z, r0.x, l(0.000001)
      log r0.x, r0.x
      mul r0.x, r0.x, r1.w
      exp r0.x, r0.x
      movc r0.x, r0.z, l(0), r0.x
      mul r0.xzw, r5.xxyz, r0.xxxx
      mad r0.xzw, r2.xxyz, r1.xxxx, r0.xxzw
      mul r1.xyz, r0.yyyy, r6.xyzx
      mul r1.xyz, r1.xyzx, cb0[5].xyzx
      mul r0.xyz, r0.xzwx, r1.xyzx
    else 
      mov r0.xyz, l(0,0,0,0)
    endif 
  else 
    mov r0.xyz, l(0,0,0,0)
  endif 
else 
  mov r0.xyz, l(0,0,0,0)
endif 
mov o0.xyz, r0.xyzx
mov o0.w, l(0)
ret 
// Approximately 74 instruction slots used

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