// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 70da10d78f97f2e6-ps.txt
// 3DMigoto: 70da10d78f97f2e6 |    Unity headers extracted from Kyoto-DeferredReflections.shader
//    Shader "Hidden/Kyoto/KyotoDeferredReflections" {
//      Properties {
//       _SrcBlend ("", Float) = 1.000000
//       _DstBlend ("", Float) = 1.000000
//      }
//      Fallback Off
//      SubShader 1/1 {
//        Pass 1/2 {
//          ZWrite Off
//          Blend [_SrcBlend] [_DstBlend]
//          GpuProgramID 44435
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 1
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Kyoto-DeferredReflections.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201510240 91 4 1
//   undeciphered2: 1 5 4 5 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 288
//   Vector 48 [unity_ColorSpaceLuminance]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 80 [_ProjectionParams]
//   Vector 112 [_ZBufferParams]
//   ConstBuffer "UnityPerCameraRare" 352
//   Matrix 288 [unity_CameraToWorld]
//   ConstBuffer "UnityReflectionProbes" 128
//   Vector 0 [unity_SpecCube0_BoxMax]
//   Vector 16 [unity_SpecCube0_BoxMin]
//   Vector 32 [unity_SpecCube0_ProbePosition]
//   Vector 48 [unity_SpecCube0_HDR]
//   Vector 96 [unity_SpecCube1_ProbePosition]
//   SetTexture 0 [_CameraDepthTexture] 2D 1
//   SetTexture 1 [_CameraGBufferTexture0] 2D 2
//   SetTexture 2 [_CameraGBufferTexture1] 2D 3
//   SetTexture 3 [_CameraGBufferTexture2] 2D 4
//   SetTexture 4 [unity_SpecCube0] CUBE 0
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//   BindCB "UnityReflectionProbes" 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:55 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[4], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[7], 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_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_texturecube (float,float,float,float) t4
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 14

// 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) r9.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 70da10d78f97f2e6-ps.txt

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

div r0.x, cb1[5].z, v2.z
mul r0.xyz, r0.xxxx, v2.xyzx
div r1.xy, v1.xyxx, v1.wwww
sample r2.xyzw, r1.xyxx, t0.xyzw, s1
mad r0.w, cb1[7].x, r2.x, cb1[7].y
div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
mul r0.xyz, r0.wwww, r0.xyzx

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

add r13.x, r12.x, -r9.y
mul r13.x, r9.x, r13.x
ne r9.w, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r9.w
  mad r0.x, -r13.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 r9.w
  mad r0.xyz, -r13.xxxx, cb10[0].xyzx, r0.xyzw
endif

sample r2.xyzw, r1.xyxx, t1.xyzw, s2
sample r3.xyzw, r1.xyxx, t2.xyzw, s3
sample r1.xyzw, r1.xyxx, t3.xyzw, s4
eq r0.w, r1.w, l(0.666666687)
mul r1.w, r3.x, l(0.050000)
movc r2.xyz, r0.wwww, r1.wwww, r3.xyzx
max r0.w, r2.y, r2.x
max r0.w, r2.z, r0.w
add r0.w, -r0.w, l(1.000000)
mad r1.xyz, r1.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r1.w, r1.xyzx, r1.xyzx
rsq r1.w, r1.w
mul r1.xyz, r1.wwww, r1.xyzx
add r3.xyz, r0.xyzx, -r10.xyzx
dp3 r1.w, r3.xyzx, r3.xyzx
rsq r1.w, r1.w
mul r3.xyz, r1.wwww, r3.xyzx
dp3 r1.w, r3.xyzx, r1.xyzx
add r1.w, r1.w, r1.w
mad r4.xyz, r1.xyzx, -r1.wwww, r3.xyzx
lt r1.w, l(0.000000), cb3[2].w
if_nz r1.w
  add r5.xyz, cb3[1].xyzx, -cb3[6].wwww
  add r6.xyz, cb3[0].xyzx, cb3[6].wwww
  dp3 r1.w, r4.xyzx, r4.xyzx
  rsq r1.w, r1.w
  mul r7.xyz, r1.wwww, r4.xyzx
  add r6.xyz, -r0.xyzx, r6.xyzx
  div r6.xyz, r6.xyzx, r7.xyzx
  add r5.xyz, -r0.xyzx, r5.xyzx
  div r5.xyz, r5.xyzx, r7.xyzx
  lt r8.xyz, l(0.000000, 0.000000, 0.000000, 0.000000), r7.xyzx
  movc r5.xyz, r8.xyzx, r6.xyzx, r5.xyzx
  min r1.w, r5.y, r5.x
  min r1.w, r5.z, r1.w
  add r5.xyz, r0.xyzx, -cb3[2].xyzx
  mad r4.xyz, r7.xyzx, r1.wwww, r5.xyzx
endif
add r1.w, -r3.w, l(1.000000)
mad r4.w, -r1.w, l(0.700000), l(1.700000)
mul r4.w, r1.w, r4.w
mul r4.w, r4.w, l(6.000000)
sample_l r4.xyzw, r4.xyzx, t4.xyzw, s0, r4.w
log r4.w, r4.w
mul r4.w, r4.w, cb3[3].y
exp r4.w, r4.w
mul r4.w, r4.w, cb3[3].x
mul r4.xyz, r4.xyzx, r4.wwww
mul r4.xyz, r2.wwww, r4.xyzx
dp3 r2.w, r1.xyzx, -r3.xyzx
lt r4.w, r2.w, l(0.000000)
add r2.w, -r2.w, l(0.000010)
mad r5.xyz, -r3.xyzx, r2.wwww, r1.xyzx
movc r1.xyz, r4.wwww, r5.xyzx, r1.xyzx
dp3 r1.x, r1.xyzx, -r3.xyzx
max r1.x, r1.x, l(0.000000)
mul r1.y, r1.w, r1.w
eq r1.z, cb0[3].w, l(0.000000)
mul r1.w, r1.y, r1.w
mad r1.w, -r1.w, l(0.280000), l(1.000000)
mad r1.y, r1.y, r1.y, l(1.000000)
div r1.y, l(1.000000, 1.000000, 1.000000, 1.000000), r1.y
movc r1.y, r1.z, r1.w, r1.y
add r0.w, -r0.w, r3.w
add_sat r0.w, r0.w, l(1.000000)
mul r1.yzw, r4.xxyz, r1.yyyy
add r1.x, -r1.x, l(1.000000)
mul r2.w, r1.x, r1.x
mul r2.w, r2.w, r2.w
mul r1.x, r1.x, r2.w
add r3.xyz, -r2.xyzx, r0.wwww
mad r3.xyz, r1.xxxx, r3.xyzx, r2.xyzx
mul r1.xyz, r1.yzwy, r3.xyzx
min r1.xyz, r1.xyzx, l(8.000000, 8.000000, 8.000000, 0.000000)
eq r0.w, r3.w, l(1.000000)
dp3 r1.w, r2.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
mul r1.w, r1.w, l(0.333333343)
mul r1.w, r1.w, r1.w
mul r2.xyz, r1.xyzx, l(4.000000, 4.000000, 4.000000, 0.000000)
max r2.xyz, r2.xyzx, l(0.100000, 0.100000, 0.100000, 0.000000)
min r2.xyz, r2.xyzx, l(0.900000, 0.900000, 0.900000, 0.000000)
add r2.xyz, -r1.xyzx, r2.xyzx
mad r2.xyz, r1.wwww, r2.xyzx, r1.xyzx
movc o0.xyz, r0.wwww, r2.xyzx, r1.xyzx
add r1.xyz, r0.xyzx, -cb3[0].xyzx
add r0.xyz, -r0.xyzx, cb3[1].xyzx
max r0.xyz, r0.xyzx, r1.xyzx
max r0.xyz, r0.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
dp3 r0.x, r0.xyzx, r0.xyzx
sqrt r0.x, r0.x
div r0.x, r0.x, cb3[6].w
add_sat o0.w, -r0.x, l(1.000000)
ret
// Approximately 0 instruction slots used