// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed de9a9194504b577f-ps.txt
// 3DMigoto: de9a9194504b577f | 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 418
// a:              GpuProgramIndex 508
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from KyotoDeferredShading.shader.decompressed:
//      API d3d11
//      Shader model ps_4_0
//      undeciphered1: 201510240 227 10 8
// 5:   Keywords { "POINT" "SHADOWS_CUBE" "SHADOWS_SOFT" "DIFFUSE_ONLY" "KYOTO_TEXEL_DENSITY" }
// a:   Keywords { "POINT" "SHADOWS_CUBE" "SHADOWS_SOFT" "SHADOWS_SPLIT_SPHERES" "DIFFUSE_ONLY" "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:09 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 15

// 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) r10.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 de9a9194504b577f-ps.txt

mul r10.w, -r10.x, r10.y
ne r12.x, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r12.x
  mul r10.w, r10.w, v2.w
  mad r11.xyz, -r10.wwww, cb2[18].xyzw, cb1[4].xyzw
else
  mad r11.xyz, -r10.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 r2.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, r2.xyzx

// copy depth from r0.z to r13.x:
mov r13.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 de9a9194504b577f-ps.txt

add r14.x, r13.x, -r10.y
mul r14.x, r10.x, r14.x
ne r10.w, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r10.w
  mad r0.x, -r14.x, v2.w, r0.x
endif

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

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

add r2.xyz, r0.xyzx, -cb0[8].xyzx
dp3 r0.w, r2.xyzx, r2.xyzx
rsq r4.x, r0.w
mul r4.yzw, r2.xxyz, r4.xxxx
mul r5.x, r0.w, cb0[8].w
sample r5.xyzw, r5.xxxx, 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 r5.yzw, r2.xxyz, l(0.000000, 0.00781250000, 0.00781250000, 0.00781250000)
sample r6.xyzw, r5.yzwy, t5.xyzw, s2
add r5.yzw, r2.xxyz, l(0.000000, -0.00781250000, -0.00781250000, 0.00781250000)
sample r7.xyzw, r5.yzwy, t5.xyzw, s2
add r5.yzw, r2.xxyz, l(0.000000, -0.00781250000, 0.00781250000, -0.00781250000)
sample r8.xyzw, r5.yzwy, t5.xyzw, s2
add r5.yzw, r2.xxyz, l(0.000000, 0.00781250000, -0.00781250000, -0.00781250000)
sample r9.xyzw, r5.yzwy, t5.yzwx, s2
mov r9.x, r6.x
mov r9.y, r7.x
mov r9.z, r8.x
lt r6.xyzw, r9.xyzw, r0.wwww
movc r6.xyzw, r6.xyzw, cb4[24].xxxx, l(1.000000,1.000000,1.000000,1.000000)
dp4 r0.w, r6.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.y, r3.xyzx, r3.xyzx
rsq r5.y, r5.y
mul r3.xyz, r3.xyzx, r5.yyyy
eq r5.y, r3.w, l(1.000000)
if_nz r5.y
  add r5.y, -r1.w, l(1.000000)
  mad r5.yzw, -cb0[19].xxyz, r5.yyyy, cb0[9].xxyz
  mul r6.xyz, r1.wwww, cb0[19].xyzx
  mad r5.yzw, -cb0[19].xxyz, r1.wwww, r5.yyzw
  mad r5.yzw, r0.wwww, r5.yyzw, r6.xxyz
  mul r5.yzw, r5.xxxx, r5.yyzw
  add r6.xyz, r0.xyzx, -r11.xyzx
  dp3 r6.w, r6.xyzx, r6.xyzx
  rsq r6.w, r6.w
  mul r6.xyz, r6.wwww, r6.xyzx
  add r6.w, -r2.w, l(1.000000)
  mad r7.xyz, -r2.xyzx, r4.xxxx, -r6.xyzx
  dp3 r7.w, r7.xyzx, r7.xyzx
  max r7.w, r7.w, l(0.001000)
  rsq r7.w, r7.w
  mul r7.xyz, r7.wwww, r7.xyzx
  dp3 r7.w, r3.xyzx, -r6.xyzx
  lt r8.x, r7.w, l(0.000000)
  add r7.w, -r7.w, l(0.000010)
  mad r8.yzw, -r6.xxyz, r7.wwww, r3.xxyz
  movc r8.xyz, r8.xxxx, r8.yzwy, r3.xyzx
  dp3 r7.w, r8.xyzx, -r4.yzwy
  max r7.w, r7.w, l(0.000000)
  dp3 r8.w, r8.xyzx, r7.xyzx
  max r8.w, r8.w, l(0.000000)
  dp3 r6.x, r8.xyzx, -r6.xyzx
  dp3 r6.y, -r4.yzwy, r7.xyzx
  max r6.xy, r6.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
  mul r6.z, r6.w, r6.w
  mad r6.w, -r6.w, r6.w, l(1.000000)
  mad r7.x, r6.x, r6.w, r6.z
  mad r6.w, r7.w, r6.w, r6.z
  mul r6.x, r6.w, r6.x
  mad r6.x, r7.w, r7.x, r6.x
  add r6.x, r6.x, l(0.000010)
  div r6.x, l(2.000000), r6.x
  mul r6.w, r6.z, r6.z
  mul r7.x, r8.w, r8.w
  mad r6.z, r6.z, r6.z, l(-1.000000)
  mad r6.z, r7.x, r6.z, l(1.000000)
  mul r7.x, r6.z, l(3.14159274)
  mad r6.z, r7.x, r6.z, l(1.000000012E-007)
  div r6.z, r6.w, r6.z
  mul r6.x, r6.z, r6.x
  mul r6.x, r6.x, l(0.785398185)
  eq r6.z, cb0[3].w, l(0.000000)
  max r6.w, r6.x, l(0.000100)
  sqrt r6.w, r6.w
  movc r6.x, r6.z, r6.w, r6.x
  mul r6.x, r7.w, r6.x
  max r6.x, r6.x, l(0.000000)
  mul r7.xyz, r5.yzwy, r7.wwww
  mul r5.yzw, r5.yyzw, r6.xxxx
  add r6.x, -r6.y, l(1.000000)
  mul r6.y, r6.x, r6.x
  mul r6.y, r6.y, r6.y
  mul r6.x, r6.x, r6.y
  mul r5.yzw, r5.yyzw, r6.xxxx
  mad r5.yzw, r1.xxyz, r7.xxyz, r5.yyzw
  min r6.xyz, r5.yzwy, l(8.000000, 8.000000, 8.000000, 0.000000)
else
  lt r5.y, l(0.600000), r3.w
  if_nz r5.y
    add r5.y, -r1.w, l(1.000000)
    mad r5.yzw, -cb0[19].xxyz, r5.yyyy, cb0[9].xxyz
    mul r7.xyz, r1.wwww, cb0[19].xyzx
    mad r5.yzw, -cb0[19].xxyz, r1.wwww, r5.yyzw
    mad r5.yzw, r0.wwww, r5.yyzw, r7.xxyz
    mul r5.yzw, r5.xxxx, r5.yyzw
    add r7.xyz, r0.xyzx, -r11.xyzx
    dp3 r7.w, r7.xyzx, r7.xyzx
    rsq r7.w, r7.w
    mul r7.xyz, r7.wwww, r7.xyzx
    dp3 r7.w, r3.xyzx, -r4.yzwy
    max r8.x, r7.w, l(0.000000)
    mad r9.x, r7.w, l(0.500000), l(0.500000)
    mov r9.y, l(0)
    sample_l r9.xyzw, r9.xyxx, t6.xyzw, s6, l(0.000000)
    add r7.w, -r2.w, l(1.000000)
    mad r8.yzw, -r2.xxyz, r4.xxxx, -r7.xxyz
    dp3 r9.w, r8.yzwy, r8.yzwy
    rsq r9.w, r9.w
    mul r8.yzw, r8.yyzw, r9.wwww
    dp3 r9.w, r3.xyzx, r8.yzwy
    max r9.w, r9.w, l(0.000000)
    dp3 r7.x, r3.xyzx, -r7.xyzx
    dp3 r7.y, -r4.yzwy, r8.yzwy
    max r7.xy, r7.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
    mul r7.z, r7.w, r7.w
    mul r7.w, r7.z, l(0.500000)
    mad r8.y, -r7.z, l(0.500000), l(1.000000)
    mad r8.z, r8.x, r8.y, r7.w
    mad r7.x, r7.x, r8.y, r7.w
    mad r7.x, r8.z, r7.x, l(0.000010)
    div r7.x, l(1.000000, 1.000000, 1.000000, 1.000000), r7.x
    mul r7.w, r7.z, r7.z
    mul r8.y, r9.w, r9.w
    mad r7.z, r7.z, r7.z, l(-1.000000)
    mad r7.z, r8.y, r7.z, l(1.000000)
    mul r8.y, r7.z, l(3.14159274)
    mad r7.z, r8.y, r7.z, l(1.000000012E-007)
    div r7.z, r7.w, r7.z
    mul r7.x, r7.z, r7.x
    mul r7.x, r8.x, r7.x
    eq r7.z, cb0[3].w, l(0.000000)
    movc r7.z, r7.z, l(0.616850257), l(0.785398185)
    mul r7.x, r7.z, r7.x
    max r7.x, r7.x, l(0.000000)
    mul r8.xyz, r1.xyzx, r5.yzwy
    mul r5.yzw, r5.yyzw, r7.xxxx
    add r7.x, -r7.y, l(1.000000)
    mul r7.y, r7.x, r7.x
    mul r7.y, r7.y, r7.y
    mul r7.x, r7.x, r7.y
    mul r5.yzw, r5.yyzw, r7.xxxx
    mad r6.xyz, r8.xyzx, r9.xyzx, r5.yzwy
  else
    lt r3.w, l(0.300000), r3.w
    if_nz r3.w
      add r3.w, -r1.w, l(1.000000)
      mad r5.yzw, -cb0[19].xxyz, r3.wwww, cb0[9].xxyz
      mul r7.xyz, r1.wwww, cb0[19].xyzx
      mad r5.yzw, -cb0[19].xxyz, r1.wwww, r5.yyzw
      mad r5.yzw, r0.wwww, r5.yyzw, r7.xxyz
      mul r5.yzw, r5.xxxx, r5.yyzw
      add r7.xyz, r0.xyzx, -r11.xyzx
      dp3 r3.w, r7.xyzx, r7.xyzx
      rsq r3.w, r3.w
      mul r7.xyz, r3.wwww, r7.xyzx
      mad r8.xyz, -r2.xyzx, r4.xxxx, -r7.xyzx
      dp3 r3.w, r8.xyzx, r8.xyzx
      rsq r3.w, r3.w
      mul r8.xyz, r3.wwww, r8.xyzx
      dp3_sat r3.w, r3.xyzx, -r7.xyzx
      dp3_sat r7.x, r3.xyzx, -r4.yzwy
      add r7.y, -r2.w, l(1.000000)
      dp3_sat r7.z, -r4.yzwy, r8.xyzx
      add r7.w, -r7.x, l(1.000000)
      mul r8.x, r7.w, r7.w
      mul r8.x, r8.x, r8.x
      mul r7.w, r7.w, r8.x
      add r3.w, -r3.w, l(1.000000)
      mul r8.x, r3.w, r3.w
      mul r8.x, r8.x, r8.x
      mul r3.w, r3.w, r8.x
      add r8.x, r7.z, r7.z
      mul r7.z, r7.z, r8.x
      mad r7.y, r7.z, r7.y, l(-0.500000)
      mad r7.z, r7.y, r7.w, l(1.000000)
      mad r3.w, r7.y, r3.w, l(1.000000)
      mul r3.w, r3.w, r7.z
      mul r3.w, r7.x, r3.w
      mul r5.yzw, r5.yyzw, r3.wwww
      mul r6.xyz, r1.xyzx, r5.yzwy
    else
      add r3.w, -r1.w, l(1.000000)
      mad r5.yzw, -cb0[19].xxyz, r3.wwww, cb0[9].xxyz
      mul r7.xyz, r1.wwww, cb0[19].xyzx
      mad r5.yzw, -cb0[19].xxyz, r1.wwww, r5.yyzw
      mad r5.yzw, r0.wwww, r5.yyzw, r7.xxyz
      mul r5.xyz, r5.xxxx, r5.yzwy
      add r0.w, -r2.w, l(1.000000)
      add r0.xyz, r0.xyzx, -r11.xyzx
      dp3 r1.w, r0.xyzx, r0.xyzx
      rsq r1.w, r1.w
      mul r0.xyz, r0.xyzx, r1.wwww
      dp3 r1.w, r3.xyzx, -r4.yzwy
      max r1.w, r1.w, l(0.000000)
      mad r2.xyz, -r2.xyzx, r4.xxxx, -r0.xyzx
      dp3 r2.w, r2.xyzx, r2.xyzx
      max r2.w, r2.w, l(0.001000)
      rsq r2.w, r2.w
      mul r2.xyz, r2.wwww, r2.xyzx
      dp3 r2.w, r3.xyzx, r2.xyzx
      max r2.w, r2.w, l(0.000000)
      dp3 r0.x, r3.xyzx, -r0.xyzx
      dp3 r0.y, -r4.yzwy, r2.xyzx
      max r0.xyz, r0.xywx, l(0.000000, 0.000000, 0.010000, 0.000000)
      mul r0.w, r0.z, r0.z
      mad r0.z, -r0.z, r0.z, l(1.000000)
      mad r2.x, r0.x, r0.z, r0.w
      mad r0.z, r1.w, r0.z, r0.w
      mul r0.x, r0.z, r0.x
      mad r0.x, r1.w, r2.x, r0.x
      add r0.x, r0.x, l(0.000010)
      div r0.x, l(2.000000), r0.x
      mul r0.z, r0.w, r0.w
      mul r2.x, r2.w, r2.w
      mad r0.w, r0.w, r0.w, l(-1.000000)
      mad r0.w, r2.x, r0.w, l(1.000000)
      mul r2.x, r0.w, l(3.14159274)
      mad r0.w, r2.x, r0.w, l(1.000000012E-007)
      div r0.z, r0.z, r0.w
      mul r0.x, r0.z, r0.x
      mul r0.x, r0.x, l(0.785398185)
      mul r0.x, r1.w, r0.x
      max r0.x, r0.x, l(0.000000)
      mul r1.xyz, r1.xyzx, r5.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
      mul r0.yzw, r0.yyyy, r5.xxyz
      mul r0.xyz, r0.xxxx, r0.yzwy
      mad r6.xyz, r1.xyzx, r1.wwww, r0.xyzx
    endif
  endif
endif
mov r6.w, l(1.000000)
exp o0.xyzw, -r6.xyzw
ret
// Approximately 0 instruction slots used