// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed dfc3da46eb2f4b70-ps.txt
// 3DMigoto: dfc3da46eb2f4b70 |    Unity headers extracted from Hidden_Internal-DeferredShading
//    Shader "Hidden/Internal-DeferredShading" {
//      SubShader 1/1 {
//        Pass 1/2 {
//          Tags { "SHADOWSUPPORT"="true" }
//          ZWrite Off
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Hidden_Internal-DeferredShading:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 140 6 4
//   undeciphered1a: 8
//   Keywords { "POINT" "SHADOWS_CUBE" "SHADOWS_SOFT" "UNITY_HDR_ON" }
//   undeciphered2: 1 7 6 7 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1232
//   Vector 64 [_LightPos]
//   Vector 80 [_LightColor]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 80 [_ProjectionParams]
//   Vector 112 [_ZBufferParams]
//   ConstBuffer "UnityPerCameraRare" 352
//   Matrix 288 [unity_CameraToWorld]
//   ConstBuffer "UnityLighting" 752
//   Vector 16 [_LightPositionRange]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Vector 400 [unity_ShadowFadeCenterAndType]
//   ConstBuffer "UnityPerFrame" 384
//   Matrix 272 [unity_MatrixVP]
//   SetTexture 0 [_CameraDepthTexture] 2D 0
//   SetTexture 1 [_LightTextureB0] 2D 1
//   SetTexture 2 [unity_RandomRotation16] 2D 2
//   SetTexture 3 [_CameraGBufferTexture0] 2D 4
//   SetTexture 4 [_CameraGBufferTexture1] 2D 5
//   SetTexture 5 [_CameraGBufferTexture2] 2D 6
//   SetTexture 6 [_ShadowMapTexture] CUBE 3
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//   BindCB "UnityLighting" 3
//   BindCB "UnityShadows" 4
//   BindCB "UnityPerFrame" 5
//
// Headers extracted with DarkStarSword's extract_unity55_shaders.py
// https://github.com/DarkStarSword/3d-fixes

//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.16 on Sun Apr 21 18:03:13 2019
//
//
// 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_immediateConstantBuffer { { 0.123298101, -0.0392337516, -0.635181785, 0.217271104},
                              { -0.562537730, -0.360242814, -0.149960607, 0.232067496},
                              { 0.640371919, 0.0682112277, -0.679780, 0.688492417},
                              { 0.281338692, -0.588158786, -0.775864720, -0.253409},
                              { -0.573121786, 0.270057201, -0.473191589, -0.283272296},
                              { 0.203316599, 0.419773906, -0.333007902, 0.643005908},
                              { 0.846795797, -0.354558408, -0.138415098, -0.0983022526},
                              { -0.423045099, -0.797441, -0.818232715, -0.564593911},
                              { 0.719025314, 0.569357514, -0.919847190, 0.0654980168},
                              { 0.0381546803, -0.991417110, -0.142208502, -0.487210900},
                              { -0.223626494, 0.502861381, -0.498083293, -0.588559926},
                              { 0.172225401, 0.983663, -0.332615912, -0.849614799},
                              { -0.291246414, 0.898051202, 0.306673586, -0.140199706},
                              { -0.898414791, -0.0876278579, 0.114831701, 0.374455},
                              { -0.699508488, 0.673418522, -0.0388568006, 0.807132900},
                              { -0.293196, -0.0628911927, 0.410288513, 0.696029484},
                              { 0, 0, 0.556387722, 0.337537706},
                              { 0, 0, -0.0178657603, -0.887376487},
                              { 0, 0, 0.234991, -0.455843806},
                              { 0, 0, 0.620677471, -0.155100495},
                              { 0, 0, 0.664064229, -0.569142699},
                              { 0, 0, 0.731272578, 0.583016813},
                              { 0, 0, 0.887970686, 0.0571521297},
                              { 0, 0, 0.312829614, -0.830803},
                              { 0, 0, 0.868976414, -0.339797288} }
dcl_constantbuffer cb0[6], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[2], immediateIndexed
dcl_constantbuffer cb4[26], immediateIndexed
dcl_constantbuffer cb5[24], 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_texture2d (float,float,float,float) t5
dcl_resource_texturecube (float,float,float,float) t6
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 dfc3da46eb2f4b70-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

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, s0
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 r2.xyz, r0.wwww, r0.xyzx

// copy depth from r2.z to r11.x:
mov r11.x, r2.z


// Unity light/shadow fix (pixel shader stage) inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed dfc3da46eb2f4b70-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 r2.x, -r12.x, v2.w, r2.x
endif

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

if_z r8.w
  mad r2.xyw, -r12.xxxx, cb10[0].xyxz, r2.xyzw
endif

add r3.xyz, r2.xywx, -cb4[25].xyzx
dp3 r0.x, r3.xyzx, r3.xyzx
sqrt r0.x, r0.x
mad r0.x, -r0.z, r0.w, r0.x
mad r0.x, cb4[25].w, r0.x, r2.z
add r0.yzw, r2.xxyw, -cb0[4].xxyz
dp3 r1.z, r0.yzwy, r0.yzwy
rsq r1.w, r1.z
mul r3.xyz, r0.yzwy, r1.wwww
mul r2.z, r1.z, cb0[4].w
sample r4.xyzw, r2.zzzz, t1.xyzw, s1
mad_sat r0.x, r0.x, cb4[24].z, cb4[24].w
lt r2.z, r0.x, l(0.990000)
if_nz r2.z
  sqrt r1.z, r1.z
  mul r2.z, r1.z, cb3[1].w
  add r4.yzw, r0.yyzw, cb3[1].xxyz
  mul r5.xyz, r4.zzzz, cb5[18].xywx
  mad r5.xyz, cb5[17].xywx, r4.yyyy, r5.xyzx
  mad r4.yzw, cb5[19].xxyw, r4.wwww, r5.xxyz
  add r4.yzw, r4.yyzw, cb5[20].xxyw
  mul r5.xz, r4.yywy, l(0.500000, 0.000000, 0.500000, 0.000000)
  mul r3.w, r4.z, cb1[5].x
  mul r5.w, r3.w, l(0.500000)
  add r4.yz, r5.zzzz, r5.xxwx
  div r4.yz, r4.yyzy, r4.wwww
  sample r5.xyzw, r4.yzyy, t2.xyzw, s2
  mul r4.yzw, r5.xxyz, l(0.000000, 45.543201, 12.989800, 78.233002)
  mad r4.yzw, r5.zzxy, l(0.000000, 12.989800, 78.233002, 45.543201), -r4.yyzw
  sincos r4.yzw, null, r4.yyzw
  mul r4.yzw, r4.yyzw, l(0.000000, 43758.546875, 43758.546875, 43758.546875)
  frc r4.yzw, r4.yyzw
  mad r4.yzw, r4.yyzw, l(0.000000, 10.000000, 10.000000, 10.000000), l(0.000000, 0.000100, 0.000100, 0.000100)
  mul r5.xyz, r0.wyzw, r4.yzwy
  mad r4.yzw, r0.zzwy, r4.zzwy, -r5.xxyz
  dp3 r3.w, r4.yzwy, r4.yzwy
  rsq r3.w, r3.w
  mul r4.yzw, r3.wwww, r4.yyzw
  mul r5.xyz, r0.wyzw, r4.zwyz
  mad r5.xyz, r0.zwyz, r4.wyzw, -r5.xyzx
  dp3 r3.w, r5.xyzx, r5.xyzx
  rsq r3.w, r3.w
  mul r5.xyz, r3.wwww, r5.xyzx
  add r3.w, -cb4[24].x, l(1.000000)
  mul r3.w, r3.w, l(0.500000)
  mul r4.yzw, r3.wwww, r4.yyzw
  mul r5.xyz, r3.wwww, r5.xyzx
  mov r3.w, l(0)
  mov r5.w, l(0)
  loop
    ige r6.x, r5.w, l(16)
    breakc_nz r6.x
    mul r6.xyz, r5.xyzx, icb[r5.w + 0].yyyy
    mad r6.xyz, r4.yzwy, icb[r5.w + 0].xxxx, r6.xyzx
    add r6.xyz, r0.yzwy, r6.xyzx
    sample_l r6.xyzw, r6.xyzx, t6.xyzw, s3, l(0.000000)
    add r3.w, r3.w, r6.x
    iadd r5.w, r5.w, l(1)
  endloop
  mad r3.w, -r3.w, l(0.062500), r2.z
  div r2.z, r3.w, r2.z
  mul r3.w, cb3[1].w, l(0.015000)
  mov r5.w, l(0)
  mov r6.x, l(0)
  loop
    itof r6.y, r6.x
    ge r6.y, r6.y, l(25.000000)
    breakc_nz r6.y
    mul r6.yzw, r5.xxyz, icb[r6.x + 0].wwww
    mad r6.yzw, r4.yyzw, icb[r6.x + 0].zzzz, r6.yyzw
    mad r6.yzw, r6.yyzw, r2.zzzz, r0.yyzw
    sample_l r7.xyzw, r6.yzwy, t6.xyzw, s3, l(0.000000)
    mad r6.y, r1.z, cb3[1].w, -r7.x
    div_sat r6.y, r6.y, r3.w
    add r6.y, -r6.y, l(1.000000)
    add r5.w, r5.w, r6.y
    iadd r6.x, r6.x, l(1)
  endloop
  mul r1.z, r5.w, l(0.040000)
else
  mov r1.z, l(1.000000)
endif
add r2.z, -r1.z, l(1.000000)
mad r0.x, r0.x, r2.z, r1.z
mul r0.x, r0.x, r4.x
mul r4.xyz, r0.xxxx, cb0[5].xyzx
sample r5.xyzw, r1.xyxx, t3.xyzw, s4
sample r6.xyzw, r1.xyxx, t4.xyzw, s5
sample r7.xyzw, r1.xyxx, t5.xyzw, s6
mad r1.xyz, r7.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r0.x, r1.xyzx, r1.xyzx
rsq r0.x, r0.x
mul r1.xyz, r0.xxxx, r1.xyzx
add r2.xyz, r2.xywx, -r9.xyzx
dp3 r0.x, r2.xyzx, r2.xyzx
rsq r0.x, r0.x
mul r2.xyz, r0.xxxx, r2.xyzx
add r7.xyzw, -r6.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
mad r0.xyz, -r0.yzwy, r1.wwww, -r2.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, r1.xyzx, -r2.xyzx
dp3_sat r1.w, r1.xyzx, -r3.xyzx
dp3_sat r1.x, r1.xyzx, r0.xyzx
dp3_sat r0.x, -r3.xyzx, r0.xyzx
mul r0.y, r0.x, r0.x
dp2 r0.y, r0.yyyy, r7.xxxx
add r0.y, r0.y, l(-0.500000)
add r0.z, -r1.w, l(1.000000)
mul r1.y, r0.z, r0.z
mul r1.y, r1.y, r1.y
mul r0.z, r0.z, r1.y
mad r0.z, r0.y, r0.z, l(1.000000)
add r1.y, -|r0.w|, l(1.000000)
mul r1.z, r1.y, r1.y
mul r1.z, r1.z, r1.z
mul r1.y, r1.y, r1.z
mad r0.y, r0.y, r1.y, l(1.000000)
mul r0.y, r0.y, r0.z
mul r0.z, r7.x, r7.x
mad r1.y, -r7.x, r7.x, l(1.000000)
mad r1.z, |r0.w|, r1.y, r0.z
mad r1.y, r1.w, r1.y, r0.z
mul r0.w, |r0.w|, r1.y
mad r0.w, r1.w, r1.z, r0.w
add r0.w, r0.w, l(0.000010)
div r0.w, l(0.500000), r0.w
mul r0.z, r0.z, r0.z
mad r1.y, r1.x, r0.z, -r1.x
mad r1.x, r1.y, r1.x, l(1.000000)
mul r0.z, r0.z, l(0.318309873)
mad r1.x, r1.x, r1.x, l(1.000000012E-007)
div r0.z, r0.z, r1.x
mul r0.z, r0.z, r0.w
mul r0.z, r0.z, l(3.14159274)
mul r0.yz, r1.wwww, r0.yyzy
max r0.z, r0.z, l(0.000000)
dp3 r0.w, r6.xyzx, r6.xyzx
ne r0.w, r0.w, l(0.000000)
and r0.w, r0.w, l(0x3f800000)
mul r0.z, r0.w, r0.z
mul r1.xyz, r0.yyyy, r4.xyzx
mul r0.yzw, r4.xxyz, r0.zzzz
add r0.x, -r0.x, l(1.000000)
mul r1.w, r0.x, r0.x
mul r1.w, r1.w, r1.w
mul r0.x, r0.x, r1.w
mad r2.xyz, r7.yzwy, r0.xxxx, r6.xyzx
mul r0.xyz, r0.yzwy, r2.xyzx
mad o0.xyz, r5.xyzx, r1.xyzx, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used