// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed fdcf10734e4ba2fe-ps.txt
// 3DMigoto: fdcf10734e4ba2fe | 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 624
// a:              GpuProgramIndex 714
//               }
//             }
//           }
//         }
//       }
//
//    Unity 5.3 headers extracted from KyotoDeferredShading.shader.decompressed:
//      API d3d11
//      Shader model ps_4_0
//      undeciphered1: 201510240 234 6 8
// a:   Keywords { "DIRECTIONAL_COOKIE" "SHADOWS_SCREEN" "SHADOWS_SPLIT_SPHERES" "SPECULAR_ONLY" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
// 5:   Keywords { "DIRECTIONAL_COOKIE" "SHADOWS_SCREEN" "SPECULAR_ONLY" "UNITY_HDR_ON" "KYOTO_TEXEL_DENSITY" }
//      undeciphered2: 1 6 4 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]
//      ConstBuffer "UnityShadows" 416
//      Vector 384 [_LightShadowData]
//      Vector 400 [unity_ShadowFadeCenterAndType]
//      SetTexture 0 [_CameraGBufferTexture0] 2D 3
//      SetTexture 1 [_CameraGBufferTexture1] 2D 4
//      SetTexture 2 [_CameraGBufferTexture2] 2D 5
//      SetTexture 3 [_CameraDepthTexture] 2D 0
//      SetTexture 4 [_ShadowMapTexture] 2D 2
//      SetTexture 5 [_LightTexture0] 2D 1
//      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:59:12 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[26], 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 13

// 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) r8.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 fdcf10734e4ba2fe-ps.txt

mul r8.w, -r8.x, r8.y
ne r10.x, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r10.x
  mul r8.w, r8.w, v2.w
  mad r9.xyz, -r8.wwww, cb2[18].xyzw, cb1[4].xyzw
else
  mad r9.xyz, -r8.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 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 r11.x:
mov r11.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 fdcf10734e4ba2fe-ps.txt

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