// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed d02b8f0a2f3dd97f-ps.txt
// 3DMigoto: d02b8f0a2f3dd97f |    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 81 5 0
//   undeciphered1a: 6
//   Keywords { "POINT" }
//   undeciphered2: 1 5 3 5 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]
//   SetTexture 0 [_CameraDepthTexture] 2D 0
//   SetTexture 1 [_LightTextureB0] 2D 1
//   SetTexture 2 [_CameraGBufferTexture0] 2D 2
//   SetTexture 3 [_CameraGBufferTexture1] 2D 3
//   SetTexture 4 [_CameraGBufferTexture2] 2D 4
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//
// 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:02:21 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_constantbuffer cb0[6], 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_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_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 11

// 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) r6.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 d02b8f0a2f3dd97f-ps.txt

mul r6.w, -r6.x, r6.y
ne r8.x, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r8.x
  mul r6.w, r6.w, v2.w
  mad r7.xyz, -r6.wwww, cb2[18].xyzw, cb1[4].xyzw
else
  mad r7.xyz, -r6.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 r0.xyz, r0.wwww, r0.xyzx

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

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

add r2.xyz, r0.xyzx, -r7.xyzx
add r0.xyz, r0.xyzx, -cb0[4].xyzx
dp3 r0.w, r2.xyzx, r2.xyzx
rsq r0.w, r0.w
mul r2.xyz, r0.wwww, r2.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r1.z, r0.w
mul r0.w, r0.w, cb0[4].w
sample r3.xyzw, r0.wwww, t1.xyzw, s1
mul r3.xyz, r3.xxxx, cb0[5].xyzx
mad r4.xyz, -r0.xyzx, r1.zzzz, -r2.xyzx
mul r0.xyz, r0.xyzx, r1.zzzz
dp3 r0.w, r4.xyzx, r4.xyzx
max r0.w, r0.w, l(0.001000)
rsq r0.w, r0.w
mul r4.xyz, r0.wwww, r4.xyzx
sample r5.xyzw, r1.xyxx, t4.xyzw, s4
mad r5.xyz, r5.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r0.w, r5.xyzx, r5.xyzx
rsq r0.w, r0.w
mul r5.xyz, r0.wwww, r5.xyzx
dp3_sat r0.w, r5.xyzx, r4.xyzx
dp3_sat r1.z, -r0.xyzx, r4.xyzx
dp3_sat r0.x, r5.xyzx, -r0.xyzx
dp3 r0.y, r5.xyzx, -r2.xyzx
sample r2.xyzw, r1.xyxx, t3.xyzw, s3
sample r4.xyzw, r1.xyxx, t2.xyzw, s2
add r5.xyzw, -r2.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
mul r0.z, r5.x, r5.x
mul r1.x, r0.z, r0.z
mad r1.y, r0.w, r1.x, -r0.w
mad r0.w, r1.y, r0.w, l(1.000000)
mad r0.w, r0.w, r0.w, l(1.000000012E-007)
mul r1.x, r1.x, l(0.318309873)
div r0.w, r1.x, r0.w
mad r1.x, -r5.x, r5.x, l(1.000000)
mad r1.y, |r0.y|, r1.x, r0.z
mad r0.z, r0.x, r1.x, r0.z
mul r0.z, r0.z, |r0.y|
add r0.y, -|r0.y|, l(1.000000)
mad r0.z, r0.x, r1.y, r0.z
add r0.z, r0.z, l(0.000010)
div r0.z, l(0.500000), r0.z
mul r0.z, r0.w, r0.z
mul r0.z, r0.z, l(3.14159274)
mul r0.z, r0.x, r0.z
max r0.z, r0.z, l(0.000000)
dp3 r0.w, r2.xyzx, r2.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.xyw, r3.xyxz, r0.zzzz
add r0.z, -r1.z, l(1.000000)
mul r0.w, r1.z, r1.z
dp2 r0.w, r0.wwww, r5.xxxx
add r0.w, r0.w, l(-0.500000)
mul r1.z, r0.z, r0.z
mul r1.z, r1.z, r1.z
mul r0.z, r0.z, r1.z
mad r2.xyz, r5.yzwy, r0.zzzz, r2.xyzx
mul r1.xyz, r1.xywx, r2.xyzx
mul r0.z, r0.y, r0.y
mul r0.z, r0.z, r0.z
mul r0.y, r0.y, r0.z
mad r0.y, r0.w, r0.y, l(1.000000)
add r0.z, -r0.x, l(1.000000)
mul r1.w, r0.z, r0.z
mul r1.w, r1.w, r1.w
mul r0.z, r0.z, r1.w
mad r0.z, r0.w, r0.z, l(1.000000)
mul r0.y, r0.y, r0.z
mul r0.x, r0.x, r0.y
mul r0.xyz, r0.xxxx, r3.xyzx
mad r0.xyz, r4.xyzx, r0.xyzx, r1.xyzx
mov r0.w, l(1.000000)
exp o0.xyzw, -r0.xyzw
ret
// Approximately 0 instruction slots used