// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed f566da773f4d9e7f-ps.txt
// 3DMigoto: f566da773f4d9e7f | Matched 4 variants of 1 shaders: Hidden/Kyoto/KyotoDeferredShading
//
//       Unity headers extracted from KyotoDeferredShading.shader
//       Shader "Hidden/Kyoto/KyotoDeferredShading" {
//         Properties {
//         [HideInInspector]  _LightTexture0 ("", any) = "" { }
//         [HideInInspector]  _LightTextureB0 ("", 2D) = "" { }
//         [HideInInspector]  _ShadowMapTexture ("", any) = "" { }
//         [HideInInspector]  _SrcBlend ("", Float) = 1.000000
//         [HideInInspector]  _DstBlend ("", Float) = 1.000000
//          _SkinDiffusionProfile ("Skin Diffusion Lookup", 2D) = "gray" { }
//         }
//         Fallback Off
//         SubShader 1/1 {
//           Pass 1/2 {
//             Tags { "SHADOWSUPPORT"="true" }
//             ZWrite Off
//             Blend [_SrcBlend] [_DstBlend]
//             GpuProgramID 15946
//             Program "fp" {
//               SubProgram "d3d11 " {
// 5:              GpuProgramIndex 388
// a:              GpuProgramIndex 478
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from KyotoDeferredShading.shader.decompressed:
//      API d3d11
//      Shader model ps_4_0
//      undeciphered1: 201510240 266 10 8
// 5:   Keywords { "POINT" "SHADOWS_CUBE" "SHADOWS_SOFT" "KYOTO_TEXEL_DENSITY" }
// a:   Keywords { "POINT" "SHADOWS_CUBE" "SHADOWS_SOFT" "SHADOWS_SPLIT_SPHERES" "KYOTO_TEXEL_DENSITY" }
//      undeciphered2: 1 7 5 7 0 0
//      undeciphered3: 0 0
//      ConstBuffer "$Globals" 336
//      Vector 48 [unity_ColorSpaceLuminance]
//      Vector 128 [_LightPos]
//      Vector 144 [_LightColor]
//      Vector 304 [_ShadowColor]
//      ScalarInt 324 [_TexelDensityViewEnabled]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 80 [_ProjectionParams]
//      Vector 112 [_ZBufferParams]
//      ConstBuffer "UnityPerCameraRare" 352
//      Matrix 288 [unity_CameraToWorld]
//      ConstBuffer "UnityLighting" 720
//      Vector 16 [_LightPositionRange]
//      ConstBuffer "UnityShadows" 416
//      Vector 384 [_LightShadowData]
//      SetTexture 0 [_CameraGBufferTexture0] 2D 3
//      SetTexture 1 [_CameraGBufferTexture1] 2D 4
//      SetTexture 2 [_CameraGBufferTexture2] 2D 5
//      SetTexture 3 [_CameraDepthTexture] 2D 0
//      SetTexture 4 [_LightTextureB0] 2D 1
//      SetTexture 5 [_ShadowMapTexture] CUBE 2
//      SetTexture 6 [_SkinDiffusionProfile] 2D 6
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityPerCameraRare" 2
//      BindCB "UnityLighting" 3
//      BindCB "UnityShadows" 4
//
// Headers extracted with DarkStarSword's extract_unity53_shaders.py
// https://github.com/DarkStarSword/3d-fixes

//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.12 on Thu Dec 06 16:59:11 2018
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyz         2     NONE   float   xyz
// TEXCOORD                 3      w        2     NONE   float      w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[21], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[2], immediateIndexed
dcl_constantbuffer cb4[25], 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_sampler s5, mode_default
dcl_sampler s6, 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_resource_texturecube (float,float,float,float) t5
dcl_resource_texture2d (float,float,float,float) t6
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 17

// New input from vertex shader with unity_CameraInvProjection[0].x:
dcl_input_ps linear v2.w
dcl_constantbuffer cb10[4], immediateIndexed

// 3DMigoto StereoParams:
dcl_resource_texture2d (float,float,float,float) t125

ld_indexable(texture2d)(float,float,float,float) r12.xyzw, l(0, 0, 0, 0), t125.xyzw


// Unity reflection/specular fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed f566da773f4d9e7f-ps.txt

mul r12.w, -r12.x, r12.y
ne r14.x, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r14.x
  mul r12.w, r12.w, v2.w
  mad r13.xyz, -r12.wwww, cb2[18].xyzw, cb1[4].xyzw
else
  mad r13.xyz, -r12.wwww, cb10[0].xyzw, cb1[4].xyzw
endif

ilt r0.x, l(0), cb0[20].y
if_nz r0.x
  div r0.xy, v1.xyxx, v1.wwww
  sample r0.xyzw, r0.xyxx, t0.xyzw, s3
  mov o0.xyzw, r0.xyzw
  ret
endif
div r0.xy, v1.xyxx, v1.wwww
sample r1.xyzw, r0.xyxx, t0.xyzw, s3
sample r2.xyzw, r0.xyxx, t1.xyzw, s4
sample r3.xyzw, r0.xyxx, t2.xyzw, s5
div r0.z, cb1[5].z, v2.z
mul r4.xyz, r0.zzzz, v2.xyzx
sample r0.xyzw, r0.xyxx, t3.xyzw, s0
mad r0.x, cb1[7].x, r0.x, cb1[7].y
div r0.x, l(1.000000, 1.000000, 1.000000, 1.000000), r0.x
mul r0.xyz, r0.xxxx, r4.xyzx

// copy depth from r0.z to r15.x:
mov r15.x, r0.z


// Unity light/shadow fix (pixel shader stage) inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed f566da773f4d9e7f-ps.txt

add r16.x, r15.x, -r12.y
mul r16.x, r12.x, r16.x
ne r12.w, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r12.w
  mad r0.x, -r16.x, v2.w, r0.x
endif

mul r4.xyz, r0.yyyy, cb2[19].xyzx
mad r0.xyw, cb2[18].xyxz, r0.xxxx, r4.xyxz
mad r0.xyz, cb2[20].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb2[21].xyzx

if_z r12.w
  mad r0.xyz, -r16.xxxx, cb10[0].xyzx, r0.xyzw
endif

add r4.xyz, r0.xyzx, -cb0[8].xyzx
dp3 r0.w, r4.xyzx, r4.xyzx
rsq r4.w, r0.w
mul r5.xyz, r4.wwww, r4.xyzx
mul r5.w, r0.w, cb0[8].w
sample r6.xyzw, r5.wwww, t4.xyzw, s1
sqrt r0.w, r0.w
mul r0.w, r0.w, cb3[1].w
mul r0.w, r0.w, l(0.970000)
add r6.yzw, r4.xxyz, l(0.000000, 0.00781250000, 0.00781250000, 0.00781250000)
sample r7.xyzw, r6.yzwy, t5.xyzw, s2
add r6.yzw, r4.xxyz, l(0.000000, -0.00781250000, -0.00781250000, 0.00781250000)
sample r8.xyzw, r6.yzwy, t5.xyzw, s2
add r6.yzw, r4.xxyz, l(0.000000, -0.00781250000, 0.00781250000, -0.00781250000)
sample r9.xyzw, r6.yzwy, t5.xyzw, s2
add r6.yzw, r4.xxyz, l(0.000000, 0.00781250000, -0.00781250000, -0.00781250000)
sample r10.xyzw, r6.yzwy, t5.yzwx, s2
mov r10.x, r7.x
mov r10.y, r8.x
mov r10.z, r9.x
lt r7.xyzw, r10.xyzw, r0.wwww
movc r7.xyzw, r7.xyzw, cb4[24].xxxx, l(1.000000,1.000000,1.000000,1.000000)
dp4 r0.w, r7.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
mad r3.xyz, r3.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r5.w, r3.xyzx, r3.xyzx
rsq r5.w, r5.w
mul r3.xyz, r3.xyzx, r5.wwww
eq r5.w, r3.w, l(1.000000)
if_nz r5.w
  add r5.w, -r1.w, l(1.000000)
  mad r6.yzw, -cb0[19].xxyz, r5.wwww, cb0[9].xxyz
  mul r7.xyz, r1.wwww, cb0[19].xyzx
  mad r6.yzw, -cb0[19].xxyz, r1.wwww, r6.yyzw
  mad r6.yzw, r0.wwww, r6.yyzw, r7.xxyz
  mul r6.yzw, r6.xxxx, r6.yyzw
  add r7.xyz, r0.xyzx, -r13.xyzx
  dp3 r5.w, r7.xyzx, r7.xyzx
  rsq r5.w, r5.w
  mul r7.xyz, r5.wwww, r7.xyzx
  add r8.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
  mad r9.xyz, -r4.xyzx, r4.wwww, -r7.xyzx
  dp3 r5.w, r9.xyzx, r9.xyzx
  max r5.w, r5.w, l(0.001000)
  rsq r5.w, r5.w
  mul r9.xyz, r5.wwww, r9.xyzx
  dp3 r5.w, r3.xyzx, -r7.xyzx
  lt r7.w, r5.w, l(0.000000)
  add r5.w, -r5.w, l(0.000010)
  mad r10.xyz, -r7.xyzx, r5.wwww, r3.xyzx
  movc r10.xyz, r7.wwww, r10.xyzx, r3.xyzx
  dp3 r5.w, r10.xyzx, -r5.xyzx
  max r5.w, r5.w, l(0.000000)
  dp3 r7.w, r10.xyzx, r9.xyzx
  dp3 r7.x, r10.xyzx, -r7.xyzx
  dp3 r7.y, -r5.xyzx, r9.xyzx
  max r7.xyw, r7.xyxw, l(0.000000, 0.000000, 0.000000, 0.000000)
  mul r7.z, r8.x, r8.x
  mad r8.x, -r8.x, r8.x, l(1.000000)
  mad r9.x, r7.x, r8.x, r7.z
  mad r8.x, r5.w, r8.x, r7.z
  mul r7.x, r7.x, r8.x
  mad r7.x, r5.w, r9.x, r7.x
  add r7.x, r7.x, l(0.000010)
  div r7.x, l(2.000000), r7.x
  mul r8.x, r7.z, r7.z
  mul r7.w, r7.w, r7.w
  mad r7.z, r7.z, r7.z, l(-1.000000)
  mad r7.z, r7.w, r7.z, l(1.000000)
  mul r7.w, r7.z, l(3.14159274)
  mad r7.z, r7.w, r7.z, l(1.000000012E-007)
  div r7.z, r8.x, r7.z
  mul r7.x, r7.z, r7.x
  mul r7.x, r7.x, l(0.785398185)
  eq r7.z, cb0[3].w, l(0.000000)
  max r7.w, r7.x, l(0.000100)
  sqrt r7.w, r7.w
  movc r7.x, r7.z, r7.w, r7.x
  mul r7.x, r5.w, r7.x
  max r7.x, r7.x, l(0.000000)
  mul r9.xyz, r5.wwww, r6.yzwy
  mul r6.yzw, r6.yyzw, r7.xxxx
  add r5.w, -r7.y, l(1.000000)
  mul r7.x, r5.w, r5.w
  mul r7.x, r7.x, r7.x
  mul r5.w, r5.w, r7.x
  mad r7.xyz, r8.yzwy, r5.wwww, r2.xyzx
  mul r6.yzw, r6.yyzw, r7.xxyz
  mad r6.yzw, r1.xxyz, r9.xxyz, r6.yyzw
  min r7.xyz, r6.yzwy, l(8.000000, 8.000000, 8.000000, 0.000000)
else
  lt r5.w, l(0.600000), r3.w
  if_nz r5.w
    add r5.w, -r1.w, l(1.000000)
    mad r6.yzw, -cb0[19].xxyz, r5.wwww, cb0[9].xxyz
    mul r8.xyz, r1.wwww, cb0[19].xyzx
    mad r6.yzw, -cb0[19].xxyz, r1.wwww, r6.yyzw
    mad r6.yzw, r0.wwww, r6.yyzw, r8.xxyz
    mul r6.yzw, r6.xxxx, r6.yyzw
    add r8.xyz, r0.xyzx, -r13.xyzx
    dp3 r5.w, r8.xyzx, r8.xyzx
    rsq r5.w, r5.w
    mul r8.xyz, r5.wwww, r8.xyzx
    dp3 r5.w, r3.xyzx, -r5.xyzx
    max r8.w, r5.w, l(0.000000)
    mad r9.x, r5.w, l(0.500000), l(0.500000)
    mov r9.y, r2.y
    sample_l r9.xyzw, r9.xyxx, t6.xyzw, s6, l(0.000000)
    add r10.xy, -r2.wxww, l(1.000000, 1.000000, 0.000000, 0.000000)
    mad r11.xyz, -r4.xyzx, r4.wwww, -r8.xyzx
    dp3 r5.w, r11.xyzx, r11.xyzx
    rsq r5.w, r5.w
    mul r11.xyz, r5.wwww, r11.xyzx
    dp3 r5.w, r3.xyzx, r11.xyzx
    max r5.w, r5.w, l(0.000000)
    dp3 r8.x, r3.xyzx, -r8.xyzx
    dp3 r8.y, -r5.xyzx, r11.xyzx
    max r8.xy, r8.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
    mul r8.z, r10.x, r10.x
    mul r9.w, r8.z, l(0.500000)
    mad r10.x, -r8.z, l(0.500000), l(1.000000)
    mad r10.z, r8.w, r10.x, r9.w
    mad r8.x, r8.x, r10.x, r9.w
    mad r8.x, r10.z, r8.x, l(0.000010)
    div r8.x, l(1.000000, 1.000000, 1.000000, 1.000000), r8.x
    mul r9.w, r8.z, r8.z
    mul r5.w, r5.w, r5.w
    mad r8.z, r8.z, r8.z, l(-1.000000)
    mad r5.w, r5.w, r8.z, l(1.000000)
    mul r8.z, r5.w, l(3.14159274)
    mad r5.w, r8.z, r5.w, l(1.000000012E-007)
    div r5.w, r9.w, r5.w
    mul r5.w, r5.w, r8.x
    mul r5.w, r8.w, r5.w
    eq r8.x, cb0[3].w, l(0.000000)
    movc r8.x, r8.x, l(0.616850257), l(0.785398185)
    mul r5.w, r5.w, r8.x
    max r5.w, r5.w, l(0.000000)
    mul r8.xzw, r1.xxyz, r6.yyzw
    mul r6.yzw, r6.yyzw, r5.wwww
    add r5.w, -r8.y, l(1.000000)
    mul r8.y, r5.w, r5.w
    mul r8.y, r8.y, r8.y
    mul r5.w, r5.w, r8.y
    mad r5.w, r10.y, r5.w, r2.x
    mul r6.yzw, r5.wwww, r6.yyzw
    mad r7.xyz, r8.xzwx, r9.xyzx, r6.yzwy
  else
    lt r3.w, l(0.300000), r3.w
    if_nz r3.w
      add r3.w, -r1.w, l(1.000000)
      mad r6.yzw, -cb0[19].xxyz, r3.wwww, cb0[9].xxyz
      mul r8.xyz, r1.wwww, cb0[19].xyzx
      mad r6.yzw, -cb0[19].xxyz, r1.wwww, r6.yyzw
      mad r6.yzw, r0.wwww, r6.yyzw, r8.xxyz
      mul r6.yzw, r6.xxxx, r6.yyzw
      add r8.xyz, r0.xyzx, -r13.xyzx
      dp3 r3.w, r8.xyzx, r8.xyzx
      rsq r3.w, r3.w
      mul r8.xyz, r3.wwww, r8.xyzx
      max r3.w, r2.y, r2.x
      max r3.w, r2.z, r3.w
      mad r9.xyz, -r4.xyzx, r4.wwww, -r8.xyzx
      dp3 r5.w, r9.xyzx, r9.xyzx
      rsq r5.w, r5.w
      mul r9.xyz, r5.wwww, r9.xyzx
      dp3_sat r5.w, r9.xyzx, -r8.xyzx
      dp3 r8.w, r3.xyzx, r9.xyzx
      max r8.w, r8.w, l(0.000000)
      min r8.w, r8.w, l(0.999999)
      mul r9.w, r8.w, r8.w
      dp3_sat r8.x, r3.xyzx, -r8.xyzx
      dp3_sat r8.y, r3.xyzx, -r5.xyzx
      add r8.z, -r2.w, l(1.000000)
      add r10.x, -r3.w, l(1.000000)
      add r5.w, -r5.w, l(1.000000)
      mul r10.y, r5.w, r5.w
      mul r10.y, r10.y, r10.y
      mul r5.w, r5.w, r10.y
      mad r3.w, r10.x, r5.w, r3.w
      mad r5.w, -r8.w, r8.w, l(1.000000)
      div r8.w, r9.w, r5.w
      mul r5.w, r5.w, r5.w
      mad r9.w, r8.z, r8.z, l(0.000001)
      mad r10.x, r9.w, l(4.000000), l(1.000000)
      mul r10.x, r10.x, l(3.14159274)
      div r10.x, l(1.000000, 1.000000, 1.000000, 1.000000), r10.x
      div r8.w, -r8.w, r9.w
      mul r8.w, r8.w, l(1.442695)
      exp r8.w, r8.w
      mul r8.w, r8.w, l(4.000000)
      div r5.w, r8.w, r5.w
      add r5.w, r5.w, l(1.000000)
      mul r5.w, r5.w, r10.x
      add r8.w, r8.x, r8.y
      mad r8.w, -r8.y, r8.x, r8.w
      mul r8.w, r8.w, l(4.000000)
      div r8.w, l(1.000000, 1.000000, 1.000000, 1.000000), r8.w
      mul r3.w, r3.w, r5.w
      mul r3.w, r8.w, r3.w
      min r3.w, r3.w, l(4.000000)
      mul r3.w, r8.y, r3.w
      dp3_sat r5.w, -r5.xyzx, r9.xyzx
      add r8.xw, -r8.xxxy, l(1.000000, 0.000000, 0.000000, 1.000000)
      mul r9.x, r8.w, r8.w
      mul r9.x, r9.x, r9.x
      mul r8.w, r8.w, r9.x
      mul r9.x, r8.x, r8.x
      mul r9.x, r9.x, r9.x
      mul r8.x, r8.x, r9.x
      mul r5.w, r5.w, r5.w
      dp2 r5.w, r5.wwww, r8.zzzz
      add r5.w, r5.w, l(-0.500000)
      mad r8.z, r5.w, r8.w, l(1.000000)
      mad r5.w, r5.w, r8.x, l(1.000000)
      mul r5.w, r5.w, r8.z
      mul r5.w, r8.y, r5.w
      mul r8.xzw, r6.yyzw, r5.wwww
      mul r9.xyz, r2.xyzx, r3.wwww
      mul r6.yzw, r6.yyzw, r9.xxyz
      mul r6.yzw, r8.yyyy, r6.yyzw
      mad r7.xyz, r8.xzwx, r1.xyzx, r6.yzwy
    else
      add r3.w, -r1.w, l(1.000000)
      mad r6.yzw, -cb0[19].xxyz, r3.wwww, cb0[9].xxyz
      mul r8.xyz, r1.wwww, cb0[19].xyzx
      mad r6.yzw, -cb0[19].xxyz, r1.wwww, r6.yyzw
      mad r6.yzw, r0.wwww, r6.yyzw, r8.xxyz
      mul r6.xyz, r6.xxxx, r6.yzwy
      add r8.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
      add r0.xyz, r0.xyzx, -r13.xyzx
      dp3 r0.w, r0.xyzx, r0.xyzx
      rsq r0.w, r0.w
      mul r0.xyz, r0.wwww, r0.xyzx
      dp3 r0.w, r3.xyzx, -r5.xyzx
      mad r4.xyz, -r4.xyzx, r4.wwww, -r0.xyzx
      dp3 r1.w, r4.xyzx, r4.xyzx
      max r1.w, r1.w, l(0.001000)
      rsq r1.w, r1.w
      mul r4.xyz, r1.wwww, r4.xyzx
      dp3 r1.w, r3.xyzx, r4.xyzx
      max r1.w, r1.w, l(0.000000)
      dp3 r0.x, r3.xyzx, -r0.xyzx
      dp3 r0.y, -r5.xyzx, r4.xyzx
      max r0.xyw, r0.xyxw, l(0.000000, 0.000000, 0.000000, 0.000000)
      max r0.z, r8.x, l(0.010000)
      mul r2.w, r0.z, r0.z
      mad r0.z, -r0.z, r0.z, l(1.000000)
      mad r3.x, r0.x, r0.z, r2.w
      mad r0.z, r0.w, r0.z, r2.w
      mul r0.x, r0.z, r0.x
      mad r0.x, r0.w, r3.x, r0.x
      add r0.x, r0.x, l(0.000010)
      div r0.x, l(2.000000), r0.x
      mul r0.z, r2.w, r2.w
      mul r1.w, r1.w, r1.w
      mad r2.w, r2.w, r2.w, l(-1.000000)
      mad r1.w, r1.w, r2.w, l(1.000000)
      mul r2.w, r1.w, l(3.14159274)
      mad r1.w, r2.w, r1.w, l(1.000000012E-007)
      div r0.z, r0.z, r1.w
      mul r0.x, r0.z, r0.x
      mul r0.x, r0.x, l(0.785398185)
      mul r0.x, r0.w, r0.x
      max r0.x, r0.x, l(0.000000)
      mul r1.xyz, r1.xyzx, r6.xyzx
      add r0.y, -r0.y, l(1.000000)
      mul r0.z, r0.y, r0.y
      mul r0.z, r0.z, r0.z
      mul r0.y, r0.y, r0.z
      mad r2.xyz, r8.yzwy, r0.yyyy, r2.xyzx
      mul r2.xyz, r2.xyzx, r6.xyzx
      mul r0.xyz, r0.xxxx, r2.xyzx
      mad r7.xyz, r1.xyzx, r0.wwww, r0.xyzx
    endif
  endif
endif
mov r7.w, l(1.000000)
exp o0.xyzw, -r7.xyzw
ret
// Approximately 0 instruction slots used