// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 2c3c0ed23469e207-ps.txt
// 3DMigoto: 2c3c0ed23469e207 | 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 627
// a:              GpuProgramIndex 717
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from KyotoDeferredShading.shader.decompressed:
//      API d3d11
//      Shader model ps_4_0
//      undeciphered1: 201510240 264 6 8
// a:   Keywords { "SPOT" "SHADOWS_DEPTH" "SHADOWS_SOFT" "SHADOWS_SPLIT_SPHERES" "SPECULAR_ONLY" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
// 5:   Keywords { "SPOT" "SHADOWS_DEPTH" "SHADOWS_SOFT" "SPECULAR_ONLY" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
//      undeciphered2: 1 7 4 7 0 0
//      undeciphered3: 0 0
//      ConstBuffer "$Globals" 400
//      Vector 48 [unity_ColorSpaceLuminance]
//      Vector 128 [_LightPos]
//      Vector 144 [_LightColor]
//      Vector 240 [_ShadowOffsets0]
//      Vector 256 [_ShadowOffsets1]
//      Vector 272 [_ShadowOffsets2]
//      Vector 288 [_ShadowOffsets3]
//      Vector 368 [_ShadowColor]
//      ScalarInt 388 [_TexelDensityViewEnabled]
//      Matrix 176 [unity_WorldToLight]
//      ConstBuffer "UnityPerCamera" 144
//      Vector 64 [_WorldSpaceCameraPos] 3
//      Vector 80 [_ProjectionParams]
//      Vector 112 [_ZBufferParams]
//      ConstBuffer "UnityPerCameraRare" 352
//      Matrix 288 [unity_CameraToWorld]
//      ConstBuffer "UnityShadows" 416
//      Vector 384 [_LightShadowData]
//      Vector 400 [unity_ShadowFadeCenterAndType]
//      Matrix 128 [unity_WorldToShadow0]
//      Matrix 192 [unity_WorldToShadow1]
//      Matrix 256 [unity_WorldToShadow2]
//      Matrix 320 [unity_WorldToShadow3]
//      SetTexture 0 [_CameraGBufferTexture0] 2D 4
//      SetTexture 1 [_CameraGBufferTexture1] 2D 5
//      SetTexture 2 [_CameraGBufferTexture2] 2D 6
//      SetTexture 3 [_CameraDepthTexture] 2D 0
//      SetTexture 4 [_LightTexture0] 2D 2
//      SetTexture 5 [_LightTextureB0] 2D 1
//      SetTexture 6 [_ShadowMapTexture] 2D 3
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityPerCameraRare" 2
//      BindCB "UnityShadows" 3
//
// 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:58:46 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[25], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[26], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_comparison
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_texture2d (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 16

// 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) r11.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 2c3c0ed23469e207-ps.txt

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

ilt r0.x, l(0), cb0[24].y
if_nz r0.x
  div r0.xy, v1.xyxx, v1.wwww
  sample r0.xyzw, r0.xyxx, t0.xyzw, s4
  mov o0.xyzw, r0.xyzw
  ret
endif
div r0.xy, v1.xyxx, v1.wwww
sample r1.xyzw, r0.xyxx, t0.xyzw, s4
sample r2.xyzw, r0.xyxx, t1.xyzw, s5
sample r3.xyzw, r0.xyxx, t2.xyzw, s6
div r0.z, cb1[5].z, v2.z
mul r1.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.yzw, r0.xxxx, r1.xxyz

// copy depth from r0.w to r14.x:
mov r14.x, r0.w


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

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

mul r4.xyz, r0.zzzz, cb2[19].xyzx
mad r4.xyz, cb2[18].xyzx, r0.yyyy, r4.xyzx
mad r4.xyz, cb2[20].xyzx, r0.wwww, r4.xyzx
add r4.xyz, r4.xyzx, cb2[21].xyzx

if_z r11.w
  mad r4.xyz, -r15.xxxx, cb10[0].xyzx, r4.xyzw
endif

add r5.xyz, r4.xyzx, -cb3[25].xyzx
dp3 r0.y, r5.xyzx, r5.xyzx
sqrt r0.y, r0.y
mad r0.x, -r1.z, r0.x, r0.y
mad r0.x, cb3[25].w, r0.x, r0.w
add r0.yzw, -r4.xxyz, cb0[8].xxyz
dp3 r1.x, r0.yzwy, r0.yzwy
rsq r1.y, r1.x
mul r5.xyz, r0.yzwy, r1.yyyy
mul r6.xyz, r4.yyyy, cb0[12].xywx
mad r6.xyz, cb0[11].xywx, r4.xxxx, r6.xyzx
mad r6.xyz, cb0[13].xywx, r4.zzzz, r6.xyzx
add r6.xyz, r6.xyzx, cb0[14].xywx
div r6.xy, r6.xyxx, r6.zzzz
sample_b r7.xyzw, r6.xyxx, t4.xyzw, s2, l(-8.000000)
lt r1.z, r6.z, l(0.000000)
and r1.z, r1.z, l(0x3f800000)
mul r1.z, r1.z, r7.w
mul r1.x, r1.x, cb0[8].w
sample r6.xyzw, r1.xxxx, t5.xyzw, s1
mul r1.x, r1.z, r6.x
mad_sat r0.x, r0.x, cb3[24].z, cb3[24].w
mul r6.xyzw, r4.yyyy, cb3[9].xyzw
mad r6.xyzw, cb3[8].xyzw, r4.xxxx, r6.xyzw
mad r6.xyzw, cb3[10].xyzw, r4.zzzz, r6.xyzw
add r6.xyzw, r6.xyzw, cb3[11].xyzw
div r6.xyz, r6.xyzx, r6.wwww
add r7.xyz, r6.xyzx, cb0[15].xyzx
sample_c_lz r7.x, r7.xyxx, t6.xxxx, s3, r7.z
add r8.xyz, r6.xyzx, cb0[16].xyzx
sample_c_lz r7.y, r8.xyxx, t6.xxxx, s3, r8.z
add r8.xyz, r6.xyzx, cb0[17].xyzx
sample_c_lz r7.z, r8.xyxx, t6.xxxx, s3, r8.z
add r6.xyz, r6.xyzx, cb0[18].xyzx
sample_c_lz r7.w, r6.xyxx, t6.xxxx, s3, r6.z
add r1.z, -cb3[24].x, l(1.000000)
mad r6.xyzw, r7.xyzw, r1.zzzz, cb3[24].xxxx
dp4 r1.z, r6.xyzw, l(0.250000, 0.250000, 0.250000, 0.250000)
add_sat r0.x, r0.x, r1.z
mad r3.xyz, r3.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r1.z, r3.xyzx, r3.xyzx
rsq r1.z, r1.z
mul r3.xyz, r1.zzzz, r3.xyzx
eq r1.z, r3.w, l(1.000000)
if_nz r1.z
  add r1.z, -r1.w, l(1.000000)
  mad r6.xyz, -cb0[23].xyzx, r1.zzzz, cb0[9].xyzx
  mul r7.xyz, r1.wwww, cb0[23].xyzx
  mad r6.xyz, -cb0[23].xyzx, r1.wwww, r6.xyzx
  mad r6.xyz, r0.xxxx, r6.xyzx, r7.xyzx
  mul r6.xyz, r1.xxxx, r6.xyzx
  add r7.xyz, r4.xyzx, -r12.xyzx
  dp3 r1.z, r7.xyzx, r7.xyzx
  rsq r1.z, r1.z
  mul r7.xyz, r1.zzzz, r7.xyzx
  add r8.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
  mad r9.xyz, r0.yzwy, r1.yyyy, -r7.xyzx
  dp3 r1.z, r9.xyzx, r9.xyzx
  max r1.z, r1.z, l(0.001000)
  rsq r1.z, r1.z
  mul r9.xyz, r1.zzzz, r9.xyzx
  dp3 r1.z, r3.xyzx, -r7.xyzx
  lt r4.w, r1.z, l(0.000000)
  add r1.z, -r1.z, l(0.000010)
  mad r10.xyz, -r7.xyzx, r1.zzzz, r3.xyzx
  movc r10.xyz, r4.wwww, r10.xyzx, r3.xyzx
  dp3 r1.z, r10.xyzx, r5.xyzx
  max r1.z, r1.z, l(0.000000)
  dp3 r4.w, r10.xyzx, r9.xyzx
  max r4.w, r4.w, l(0.000000)
  dp3 r5.w, r10.xyzx, -r7.xyzx
  max r5.w, r5.w, l(0.000000)
  dp3 r6.w, r5.xyzx, r9.xyzx
  max r6.w, r6.w, l(0.000000)
  mul r7.x, r8.x, r8.x
  mad r7.y, -r8.x, r8.x, l(1.000000)
  mad r7.z, r5.w, r7.y, r7.x
  mad r7.y, r1.z, r7.y, r7.x
  mul r5.w, r5.w, r7.y
  mad r5.w, r1.z, r7.z, r5.w
  add r5.w, r5.w, l(0.000010)
  div r5.w, l(2.000000), r5.w
  mul r7.y, r7.x, r7.x
  mul r4.w, r4.w, r4.w
  mad r7.x, r7.x, r7.x, l(-1.000000)
  mad r4.w, r4.w, r7.x, l(1.000000)
  mul r7.x, r4.w, l(3.14159274)
  mad r4.w, r7.x, r4.w, l(1.000000012E-007)
  div r4.w, r7.y, r4.w
  mul r4.w, r4.w, r5.w
  mul r4.w, r4.w, l(0.785398185)
  eq r5.w, cb0[3].w, l(0.000000)
  max r7.x, r4.w, l(0.000100)
  sqrt r7.x, r7.x
  movc r4.w, r5.w, r7.x, r4.w
  mul r1.z, r1.z, r4.w
  max r1.z, r1.z, l(0.000000)
  mul r6.xyz, r6.xyzx, r1.zzzz
  add r1.z, -r6.w, l(1.000000)
  mul r4.w, r1.z, r1.z
  mul r4.w, r4.w, r4.w
  mul r1.z, r1.z, r4.w
  mad r7.xyz, r8.yzwy, r1.zzzz, r2.xyzx
  mul r6.xyz, r6.xyzx, r7.xyzx
  min r6.xyz, r6.xyzx, l(8.000000, 8.000000, 8.000000, 0.000000)
else
  lt r1.z, l(0.600000), r3.w
  if_nz r1.z
    add r1.z, -r1.w, l(1.000000)
    mad r7.xyz, -cb0[23].xyzx, r1.zzzz, cb0[9].xyzx
    mul r8.xyz, r1.wwww, cb0[23].xyzx
    mad r7.xyz, -cb0[23].xyzx, r1.wwww, r7.xyzx
    mad r7.xyz, r0.xxxx, r7.xyzx, r8.xyzx
    mul r7.xyz, r1.xxxx, r7.xyzx
    add r8.xyz, r4.xyzx, -r12.xyzx
    dp3 r1.z, r8.xyzx, r8.xyzx
    rsq r1.z, r1.z
    mul r8.xyz, r1.zzzz, r8.xyzx
    dp3 r1.z, r3.xyzx, r5.xyzx
    max r1.z, r1.z, l(0.000000)
    add r9.xy, -r2.wxww, l(1.000000, 1.000000, 0.000000, 0.000000)
    mad r10.xyz, r0.yzwy, r1.yyyy, -r8.xyzx
    dp3 r4.w, r10.xyzx, r10.xyzx
    rsq r4.w, r4.w
    mul r10.xyz, r4.wwww, r10.xyzx
    dp3 r4.w, r3.xyzx, r10.xyzx
    max r4.w, r4.w, l(0.000000)
    dp3 r5.w, r3.xyzx, -r8.xyzx
    max r5.w, r5.w, l(0.000000)
    dp3 r6.w, r5.xyzx, r10.xyzx
    max r6.w, r6.w, l(0.000000)
    mul r7.w, r9.x, r9.x
    mul r8.x, r7.w, l(0.500000)
    mad r8.y, -r7.w, l(0.500000), l(1.000000)
    mad r8.z, r1.z, r8.y, r8.x
    mad r5.w, r5.w, r8.y, r8.x
    mad r5.w, r8.z, r5.w, l(0.000010)
    div r5.w, l(1.000000, 1.000000, 1.000000, 1.000000), r5.w
    mul r8.x, r7.w, r7.w
    mul r4.w, r4.w, r4.w
    mad r7.w, r7.w, r7.w, l(-1.000000)
    mad r4.w, r4.w, r7.w, l(1.000000)
    mul r7.w, r4.w, l(3.14159274)
    mad r4.w, r7.w, r4.w, l(1.000000012E-007)
    div r4.w, r8.x, r4.w
    mul r4.w, r4.w, r5.w
    mul r1.z, r1.z, r4.w
    eq r4.w, cb0[3].w, l(0.000000)
    movc r4.w, r4.w, l(0.616850257), l(0.785398185)
    mul r1.z, r1.z, r4.w
    max r1.z, r1.z, l(0.000000)
    mul r7.xyz, r7.xyzx, r1.zzzz
    add r1.z, -r6.w, l(1.000000)
    mul r4.w, r1.z, r1.z
    mul r4.w, r4.w, r4.w
    mul r1.z, r1.z, r4.w
    mad r1.z, r9.y, r1.z, r2.x
    mul r6.xyz, r1.zzzz, r7.xyzx
  else
    lt r1.z, l(0.300000), r3.w
    if_nz r1.z
      add r1.z, -r1.w, l(1.000000)
      mad r7.xyz, -cb0[23].xyzx, r1.zzzz, cb0[9].xyzx
      mul r8.xyz, r1.wwww, cb0[23].xyzx
      mad r7.xyz, -cb0[23].xyzx, r1.wwww, r7.xyzx
      mad r7.xyz, r0.xxxx, r7.xyzx, r8.xyzx
      mul r7.xyz, r1.xxxx, r7.xyzx
      add r8.xyz, r4.xyzx, -r12.xyzx
      dp3 r1.z, r8.xyzx, r8.xyzx
      rsq r1.z, r1.z
      mul r8.xyz, r1.zzzz, r8.xyzx
      max r1.z, r2.y, r2.x
      max r1.z, r2.z, r1.z
      mad r9.xyz, r0.yzwy, r1.yyyy, -r8.xyzx
      dp3 r3.w, r9.xyzx, r9.xyzx
      rsq r3.w, r3.w
      mul r9.xyz, r3.wwww, r9.xyzx
      dp3_sat r3.w, r9.xyzx, -r8.xyzx
      dp3 r4.w, r3.xyzx, r9.xyzx
      max r4.w, r4.w, l(0.000000)
      min r4.w, r4.w, l(0.999999)
      mul r5.w, r4.w, r4.w
      dp3_sat r6.w, r3.xyzx, -r8.xyzx
      dp3_sat r7.w, r3.xyzx, r5.xyzx
      add r8.x, -r2.w, l(1.000000)
      add r8.y, -r1.z, l(1.000000)
      add r3.w, -r3.w, l(1.000000)
      mul r8.z, r3.w, r3.w
      mul r8.z, r8.z, r8.z
      mul r3.w, r3.w, r8.z
      mad r1.z, r8.y, r3.w, r1.z
      mad r3.w, -r4.w, r4.w, l(1.000000)
      div r4.w, r5.w, r3.w
      mul r3.w, r3.w, r3.w
      mad r5.w, r8.x, r8.x, l(0.000001)
      mad r8.x, r5.w, l(4.000000), l(1.000000)
      mul r8.x, r8.x, l(3.14159274)
      div r8.x, l(1.000000, 1.000000, 1.000000, 1.000000), r8.x
      div r4.w, -r4.w, r5.w
      mul r4.w, r4.w, l(1.442695)
      exp r4.w, r4.w
      mul r4.w, r4.w, l(4.000000)
      div r3.w, r4.w, r3.w
      add r3.w, r3.w, l(1.000000)
      mul r3.w, r3.w, r8.x
      add r4.w, r6.w, r7.w
      mad r4.w, -r7.w, r6.w, r4.w
      mul r4.w, r4.w, l(4.000000)
      div r4.w, l(1.000000, 1.000000, 1.000000, 1.000000), r4.w
      mul r1.z, r1.z, r3.w
      mul r1.z, r4.w, r1.z
      min r1.z, r1.z, l(4.000000)
      mul r1.z, r7.w, r1.z
      mul r8.xyz, r2.xyzx, r1.zzzz
      mul r7.xyz, r7.xyzx, r8.xyzx
      mul r6.xyz, r7.wwww, r7.xyzx
    else
      add r1.z, -r1.w, l(1.000000)
      mad r7.xyz, -cb0[23].xyzx, r1.zzzz, cb0[9].xyzx
      mul r8.xyz, r1.wwww, cb0[23].xyzx
      mad r7.xyz, -cb0[23].xyzx, r1.wwww, r7.xyzx
      mad r7.xyz, r0.xxxx, r7.xyzx, r8.xyzx
      mul r1.xzw, r1.xxxx, r7.xxyz
      add r7.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
      add r4.xyz, r4.xyzx, -r12.xyzx
      dp3 r0.x, r4.xyzx, r4.xyzx
      rsq r0.x, r0.x
      mul r4.xyz, r0.xxxx, r4.xyzx
      dp3 r0.x, r3.xyzx, r5.xyzx
      mad r0.yzw, r0.yyzw, r1.yyyy, -r4.xxyz
      dp3 r1.y, r0.yzwy, r0.yzwy
      max r1.y, r1.y, l(0.001000)
      rsq r1.y, r1.y
      mul r0.yzw, r0.yyzw, r1.yyyy
      dp3 r1.y, r3.xyzx, r0.yzwy
      max r1.y, r1.y, l(0.000000)
      dp3 r2.w, r3.xyzx, -r4.xyzx
      max r2.w, r2.w, l(0.000000)
      dp3 r0.y, r5.xyzx, r0.yzwy
      max r0.xy, r0.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000)
      max r0.z, r7.x, l(0.010000)
      mul r0.w, r0.z, r0.z
      mad r0.z, -r0.z, r0.z, l(1.000000)
      mad r3.x, r2.w, r0.z, r0.w
      mad r0.z, r0.x, r0.z, r0.w
      mul r0.z, r0.z, r2.w
      mad r0.z, r0.x, r3.x, r0.z
      add r0.z, r0.z, l(0.000010)
      div r0.z, l(2.000000), r0.z
      mul r2.w, r0.w, r0.w
      mul r1.y, r1.y, r1.y
      mad r0.w, r0.w, r0.w, l(-1.000000)
      mad r0.w, r1.y, r0.w, l(1.000000)
      mul r1.y, r0.w, l(3.14159274)
      mad r0.w, r1.y, r0.w, l(1.000000012E-007)
      div r0.w, r2.w, r0.w
      mul r0.z, r0.w, r0.z
      mul r0.z, r0.z, l(0.785398185)
      mul r0.x, r0.x, r0.z
      max r0.x, r0.x, l(0.000000)
      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 r0.yzw, r7.yyzw, r0.yyyy, r2.xxyz
      mul r0.yzw, r0.yyzw, r1.xxzw
      mul r6.xyz, r0.xxxx, r0.yzwy
    endif
  endif
endif
mov o0.xyz, r6.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used