// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 47a6e606808751a5-ps.txt
// 3DMigoto: 47a6e606808751a5 | 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 561
// a:              GpuProgramIndex 651
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from KyotoDeferredShading.shader.decompressed:
//      API d3d11
//      Shader model ps_4_0
//      undeciphered1: 201510240 254 5 8
// a:   Keywords { "DIRECTIONAL_COOKIE" "SHADOWS_OFF" "SHADOWS_SPLIT_SPHERES" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
// 5:   Keywords { "DIRECTIONAL_COOKIE" "SHADOWS_OFF" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
//      undeciphered2: 1 6 3 6 0 0
//      undeciphered3: 0 0
//      ConstBuffer "$Globals" 336
//      Vector 48 [unity_ColorSpaceLuminance]
//      Vector 112 [_LightDir]
//      Vector 144 [_LightColor]
//      Vector 304 [_ShadowColor]
//      Float 320 [_OcclusionDirectLightScalar]
//      ScalarInt 324 [_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]
//      SetTexture 0 [_CameraGBufferTexture0] 2D 2
//      SetTexture 1 [_CameraGBufferTexture1] 2D 3
//      SetTexture 2 [_CameraGBufferTexture2] 2D 4
//      SetTexture 3 [_CameraDepthTexture] 2D 0
//      SetTexture 4 [_LightTexture0] 2D 1
//      SetTexture 5 [_SkinDiffusionProfile] 2D 5
//      BindCB "$Globals" 0
//      BindCB "UnityPerCamera" 1
//      BindCB "UnityPerCameraRare" 2
//
// 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:49 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_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_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_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 47a6e606808751a5-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, s2
  mov o0.xyzw, r0.xyzw
  ret
endif
div r0.xy, v1.xyxx, v1.wwww
sample r1.xyzw, r0.xyxx, t0.xyzw, s2
sample r2.xyzw, r0.xyxx, t1.xyzw, s3
sample r3.xyzw, r0.xyxx, t2.xyzw, s4
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 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 47a6e606808751a5-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 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 r10.w
  mad r0.xyz, -r14.xxxx, cb10[0].xyzx, r0.xyzw
endif

mul r4.xy, r0.yyyy, cb0[12].xyxx
mad r4.xy, cb0[11].xyxx, r0.xxxx, r4.xyxx
mad r4.xy, cb0[13].xyxx, r0.zzzz, r4.xyxx
add r4.xy, r4.xyxx, cb0[14].xyxx
sample_b r4.xyzw, r4.xyxx, t4.xyzw, s1, l(-8.000000)
mad r3.xyz, r3.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r0.w, r3.xyzx, r3.xyzx
rsq r0.w, r0.w
mul r3.xyz, r0.wwww, r3.xyzx
eq r0.w, r3.w, l(1.000000)
if_nz r0.w
  add r0.w, r1.w, l(-1.000000)
  mad r0.w, cb0[20].x, r0.w, l(1.000000)
  mul r4.xyz, r1.wwww, cb0[19].xyzx
  mad r5.xyz, cb0[9].xyzx, r0.wwww, -r4.xyzx
  mad r4.xyz, r4.wwww, r5.xyzx, r4.xyzx
  add r5.xyz, r0.xyzx, -r11.xyzx
  dp3 r0.w, r5.xyzx, r5.xyzx
  rsq r0.w, r0.w
  mul r6.xyz, r0.wwww, r5.xyzx
  add r7.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
  mad r5.xyz, -r5.xyzx, r0.wwww, -cb0[7].xyzx
  dp3 r0.w, r5.xyzx, r5.xyzx
  max r0.w, r0.w, l(0.001000)
  rsq r0.w, r0.w
  mul r5.xyz, r0.wwww, r5.xyzx
  dp3 r0.w, r3.xyzx, -r6.xyzx
  lt r5.w, r0.w, l(0.000000)
  add r0.w, -r0.w, l(0.000010)
  mad r8.xyz, -r6.xyzx, r0.wwww, r3.xyzx
  movc r8.xyz, r5.wwww, r8.xyzx, r3.xyzx
  dp3 r0.w, r8.xyzx, -cb0[7].xyzx
  max r0.w, r0.w, l(0.000000)
  dp3 r5.w, r8.xyzx, r5.xyzx
  dp3 r6.x, r8.xyzx, -r6.xyzx
  max r6.x, r6.x, l(0.000000)
  dp3 r5.x, -cb0[7].xyzx, r5.xyzx
  max r5.xw, r5.xxxw, l(0.000000, 0.000000, 0.000000, 0.000000)
  mul r5.y, r7.x, r7.x
  mad r5.z, -r7.x, r7.x, l(1.000000)
  mad r6.y, r6.x, r5.z, r5.y
  mad r5.z, r0.w, r5.z, r5.y
  mul r5.z, r5.z, r6.x
  mad r5.z, r0.w, r6.y, r5.z
  add r5.z, r5.z, l(0.000010)
  div r5.z, l(2.000000), r5.z
  mul r6.x, r5.y, r5.y
  mul r5.w, r5.w, r5.w
  mad r5.y, r5.y, r5.y, l(-1.000000)
  mad r5.y, r5.w, r5.y, l(1.000000)
  mul r5.w, r5.y, l(3.14159274)
  mad r5.y, r5.w, r5.y, l(1.000000012E-007)
  div r5.y, r6.x, r5.y
  mul r5.y, r5.y, r5.z
  mul r5.y, r5.y, l(0.785398185)
  eq r5.z, cb0[3].w, l(0.000000)
  max r5.w, r5.y, l(0.000100)
  sqrt r5.w, r5.w
  movc r5.y, r5.z, r5.w, r5.y
  mul r5.y, r0.w, r5.y
  max r5.y, r5.y, l(0.000000)
  mul r6.xyz, r0.wwww, r4.xyzx
  mul r4.xyz, r4.xyzx, r5.yyyy
  add r0.w, -r5.x, l(1.000000)
  mul r5.x, r0.w, r0.w
  mul r5.x, r5.x, r5.x
  mul r0.w, r0.w, r5.x
  mad r5.xyz, r7.yzwy, r0.wwww, r2.xyzx
  mul r4.xyz, r4.xyzx, r5.xyzx
  mad r4.xyz, r1.xyzx, r6.xyzx, r4.xyzx
  min r4.xyz, r4.xyzx, l(8.000000, 8.000000, 8.000000, 0.000000)
else
  lt r0.w, l(0.600000), r3.w
  if_nz r0.w
    add r0.w, r1.w, l(-1.000000)
    mad r0.w, cb0[20].x, r0.w, l(1.000000)
    mul r5.xyz, r1.wwww, cb0[19].xyzx
    mad r6.xyz, cb0[9].xyzx, r0.wwww, -r5.xyzx
    mad r5.xyz, r4.wwww, r6.xyzx, r5.xyzx
    add r6.xyz, r0.xyzx, -r11.xyzx
    dp3 r0.w, r6.xyzx, r6.xyzx
    rsq r0.w, r0.w
    mul r7.xyz, r0.wwww, r6.xyzx
    dp3 r5.w, r3.xyzx, -cb0[7].xyzx
    max r6.w, r5.w, l(0.000000)
    mad r8.x, r5.w, l(0.500000), l(0.500000)
    mov r8.y, r2.y
    sample_l r8.xyzw, r8.xyxx, t5.xyzw, s5, l(0.000000)
    add r9.xy, -r2.wxww, l(1.000000, 1.000000, 0.000000, 0.000000)
    mad r6.xyz, -r6.xyzx, r0.wwww, -cb0[7].xyzx
    dp3 r0.w, r6.xyzx, r6.xyzx
    rsq r0.w, r0.w
    mul r6.xyz, r0.wwww, r6.xyzx
    dp3 r0.w, r3.xyzx, r6.xyzx
    max r0.w, r0.w, l(0.000000)
    dp3 r5.w, r3.xyzx, -r7.xyzx
    max r5.w, r5.w, l(0.000000)
    dp3 r6.x, -cb0[7].xyzx, r6.xyzx
    max r6.x, r6.x, l(0.000000)
    mul r6.y, r9.x, r9.x
    mul r6.z, r6.y, l(0.500000)
    mad r7.x, -r6.y, l(0.500000), l(1.000000)
    mad r7.y, r6.w, r7.x, r6.z
    mad r5.w, r5.w, r7.x, r6.z
    mad r5.w, r7.y, r5.w, l(0.000010)
    div r5.w, l(1.000000, 1.000000, 1.000000, 1.000000), r5.w
    mul r6.z, r6.y, r6.y
    mul r0.w, r0.w, r0.w
    mad r6.y, r6.y, r6.y, l(-1.000000)
    mad r0.w, r0.w, r6.y, l(1.000000)
    mul r6.y, r0.w, l(3.14159274)
    mad r0.w, r6.y, r0.w, l(1.000000012E-007)
    div r0.w, r6.z, r0.w
    mul r0.w, r0.w, r5.w
    mul r0.w, r6.w, r0.w
    eq r5.w, cb0[3].w, l(0.000000)
    movc r5.w, r5.w, l(0.616850257), l(0.785398185)
    mul r0.w, r0.w, r5.w
    max r0.w, r0.w, l(0.000000)
    mul r6.yzw, r1.xxyz, r5.xxyz
    mul r5.xyz, r5.xyzx, r0.wwww
    add r0.w, -r6.x, l(1.000000)
    mul r5.w, r0.w, r0.w
    mul r5.w, r5.w, r5.w
    mul r0.w, r0.w, r5.w
    mad r0.w, r9.y, r0.w, r2.x
    mul r5.xyz, r0.wwww, r5.xyzx
    mad r4.xyz, r6.yzwy, r8.xyzx, r5.xyzx
  else
    lt r0.w, l(0.300000), r3.w
    if_nz r0.w
      add r0.w, r1.w, l(-1.000000)
      mad r0.w, cb0[20].x, r0.w, l(1.000000)
      mul r5.xyz, r1.wwww, cb0[19].xyzx
      mad r6.xyz, cb0[9].xyzx, r0.wwww, -r5.xyzx
      mad r5.xyz, r4.wwww, r6.xyzx, r5.xyzx
      add r6.xyz, r0.xyzx, -r11.xyzx
      dp3 r0.w, r6.xyzx, r6.xyzx
      rsq r0.w, r0.w
      mul r7.xyz, r0.wwww, r6.xyzx
      max r3.w, r2.y, r2.x
      max r3.w, r2.z, r3.w
      mad r6.xyz, -r6.xyzx, r0.wwww, -cb0[7].xyzx
      dp3 r0.w, r6.xyzx, r6.xyzx
      rsq r0.w, r0.w
      mul r6.xyz, r0.wwww, r6.xyzx
      dp3_sat r0.w, r6.xyzx, -r7.xyzx
      dp3 r5.w, r3.xyzx, r6.xyzx
      max r5.w, r5.w, l(0.000000)
      min r5.w, r5.w, l(0.999999)
      mul r6.w, r5.w, r5.w
      dp3_sat r7.x, r3.xyzx, -r7.xyzx
      dp3_sat r7.y, r3.xyzx, -cb0[7].xyzx
      add r7.z, -r2.w, l(1.000000)
      add r7.w, -r3.w, l(1.000000)
      add r0.w, -r0.w, l(1.000000)
      mul r8.x, r0.w, r0.w
      mul r8.x, r8.x, r8.x
      mul r0.w, r0.w, r8.x
      mad r0.w, r7.w, r0.w, r3.w
      mad r3.w, -r5.w, r5.w, l(1.000000)
      div r5.w, r6.w, r3.w
      mul r3.w, r3.w, r3.w
      mad r6.w, r7.z, r7.z, l(0.000001)
      mad r7.w, r6.w, l(4.000000), l(1.000000)
      mul r7.w, r7.w, l(3.14159274)
      div r7.w, l(1.000000, 1.000000, 1.000000, 1.000000), r7.w
      div r5.w, -r5.w, r6.w
      mul r5.w, r5.w, l(1.442695)
      exp r5.w, r5.w
      mul r5.w, r5.w, l(4.000000)
      div r3.w, r5.w, r3.w
      add r3.w, r3.w, l(1.000000)
      mul r3.w, r3.w, r7.w
      add r5.w, r7.x, r7.y
      mad r5.w, -r7.y, r7.x, r5.w
      mul r5.w, r5.w, l(4.000000)
      div r5.w, l(1.000000, 1.000000, 1.000000, 1.000000), r5.w
      mul r0.w, r0.w, r3.w
      mul r0.w, r5.w, r0.w
      min r0.w, r0.w, l(4.000000)
      mul r0.w, r7.y, r0.w
      dp3_sat r3.w, -cb0[7].xyzx, r6.xyzx
      add r5.w, -r7.y, l(1.000000)
      mul r6.x, r5.w, r5.w
      mul r6.x, r6.x, r6.x
      mul r5.w, r5.w, r6.x
      add r6.x, -r7.x, 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 r3.w, r3.w, r3.w
      dp2 r3.w, r3.wwww, r7.zzzz
      add r3.w, r3.w, l(-0.500000)
      mad r5.w, r3.w, r5.w, l(1.000000)
      mad r3.w, r3.w, r6.x, l(1.000000)
      mul r3.w, r3.w, r5.w
      mul r3.w, r7.y, r3.w
      mul r6.xyz, r5.xyzx, r3.wwww
      mul r7.xzw, r2.xxyz, r0.wwww
      mul r5.xyz, r5.xyzx, r7.xzwx
      mul r5.xyz, r7.yyyy, r5.xyzx
      mad r4.xyz, r6.xyzx, r1.xyzx, r5.xyzx
    else
      add r0.w, r1.w, l(-1.000000)
      mad r0.w, cb0[20].x, r0.w, l(1.000000)
      mul r5.xyz, r1.wwww, cb0[19].xyzx
      mad r6.xyz, cb0[9].xyzx, r0.wwww, -r5.xyzx
      mad r5.xyz, r4.wwww, r6.xyzx, r5.xyzx
      add r6.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
      add r0.xyz, r0.xyzx, -r11.xyzx
      dp3 r0.w, r0.xyzx, r0.xyzx
      rsq r0.w, r0.w
      mul r7.xyz, r0.wwww, r0.xyzx
      dp3 r1.w, r3.xyzx, -cb0[7].xyzx
      max r1.w, r1.w, l(0.000000)
      mad r0.xyz, -r0.xyzx, r0.wwww, -cb0[7].xyzx
      dp3 r0.w, r0.xyzx, r0.xyzx
      max r0.w, r0.w, l(0.001000)
      rsq r0.w, r0.w
      mul r0.xyz, r0.wwww, r0.xyzx
      dp3 r0.w, r3.xyzx, r0.xyzx
      dp3 r2.w, r3.xyzx, -r7.xyzx
      max r2.w, r2.w, l(0.000000)
      dp3 r0.x, -cb0[7].xyzx, r0.xyzx
      max r0.xw, r0.xxxw, l(0.000000, 0.000000, 0.000000, 0.000000)
      max r0.y, r6.x, l(0.010000)
      mul r0.zw, r0.yyyw, r0.yyyw
      mad r0.y, -r0.y, r0.y, l(1.000000)
      mad r3.x, r2.w, r0.y, r0.z
      mad r0.y, r1.w, r0.y, r0.z
      mul r0.y, r0.y, r2.w
      mad r0.y, r1.w, r3.x, r0.y
      add r0.y, r0.y, l(0.000010)
      div r0.y, l(2.000000), r0.y
      mul r2.w, r0.z, r0.z
      mad r0.z, r0.z, r0.z, l(-1.000000)
      mad r0.z, r0.w, r0.z, l(1.000000)
      mul r0.w, r0.z, l(3.14159274)
      mad r0.z, r0.w, r0.z, l(1.000000012E-007)
      div r0.z, r2.w, r0.z
      mul r0.y, r0.z, r0.y
      mul r0.y, r0.y, l(0.785398185)
      mul r0.y, r1.w, r0.y
      max r0.y, r0.y, l(0.000000)
      mul r1.xyz, r1.xyzx, r5.xyzx
      add r0.x, -r0.x, l(1.000000)
      mul r0.z, r0.x, r0.x
      mul r0.z, r0.z, r0.z
      mul r0.x, r0.x, r0.z
      mad r0.xzw, r6.yyzw, r0.xxxx, r2.xxyz
      mul r0.xzw, r0.xxzw, r5.xxyz
      mul r0.xyz, r0.yyyy, r0.xzwx
      mad r4.xyz, r1.xyzx, r1.wwww, r0.xyzx
    endif
  endif
endif
mov o0.xyz, r4.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used