// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed f9e7a53ba0221f7d-ps.txt
// 3DMigoto: f9e7a53ba0221f7d |    Unity headers extracted from Hidden_Internal-PrePassLighting
//    Shader "Hidden/Internal-PrePassLighting" {
//      SubShader 1/1 {
//        Pass 1/2 {
//          Tags { "SHADOWSUPPORT"="true" }
//          ZWrite Off
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Hidden_Internal-PrePassLighting:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201708220 68 3 0
//   undeciphered1a: 5
//   Keywords { "SPOT" "SHADOWS_DEPTH" "LIGHTMAP_SHADOW_MIXING" }
//   undeciphered2: 1 5 4 5 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 192
//   Vector 64 [_LightPos]
//   Vector 80 [_LightColor]
//   Vector 96 [unity_LightmapFade]
//   Vector 176 [_CameraNormalsTexture_ST]
//   Matrix 112 [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]
//   Matrix 128 [unity_WorldToShadow0]
//   Matrix 192 [unity_WorldToShadow1]
//   Matrix 256 [unity_WorldToShadow2]
//   Matrix 320 [unity_WorldToShadow3]
//   SetTexture 0 [_CameraDepthTexture] 2D 00
//   SetTexture 1 [_LightTexture0] 2D 20
//   SetTexture 2 [_LightTextureB0] 2D 10
//   SetTexture 3 [_CameraNormalsTexture] 2D 40
//   SetTexture 4 [_ShadowMapTexture] 2D 30
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//   BindCB "UnityShadows" 3
//
// 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.2 on Mon Jan 14 19:53:00 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[12], 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_comparison
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 10

// 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) r5.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 f9e7a53ba0221f7d-ps.txt

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

add r0.x, -cb3[24].x, l(1.000000)
div r0.yz, v1.xxyx, v1.wwww
sample r1.xyzw, r0.yzyy, t0.xyzw, s0
mad r0.yz, r0.yyzy, cb0[11].xxyx, cb0[11].zzwz
sample r2.xyzw, r0.yzyy, t3.xyzw, s4
mad r0.y, cb1[7].x, r1.x, cb1[7].y
div r0.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.y
div r0.z, cb1[5].z, v2.z
mul r1.xyz, r0.zzzz, v2.xyzx
mul r1.xyw, r0.yyyy, r1.xyxz

// copy depth from r1.w to r8.x:
mov r8.x, r1.w


// Unity light/shadow fix (pixel shader stage) inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed f9e7a53ba0221f7d-ps.txt

add r9.x, r8.x, -r5.y
mul r9.x, r5.x, r9.x
ne r5.w, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r5.w
  mad r1.x, -r9.x, v2.w, r1.x
endif

mul r3.xyz, r1.yyyy, cb2[19].xyzx
mad r3.xyz, cb2[18].xyzx, r1.xxxx, r3.xyzx
mad r3.xyz, cb2[20].xyzx, r1.wwww, r3.xyzx
add r3.xyz, r3.xyzx, cb2[21].xyzx

if_z r5.w
  mad r3.xyz, -r9.xxxx, cb10[0].xyzx, r3.xyzw
endif

mul r4.xyzw, r3.yyyy, cb3[9].xyzw
mad r4.xyzw, cb3[8].xyzw, r3.xxxx, r4.xyzw
mad r4.xyzw, cb3[10].xyzw, r3.zzzz, r4.xyzw
add r4.xyzw, r4.xyzw, cb3[11].xyzw
div r4.xyz, r4.xyzx, r4.wwww
sample_c_lz r0.z, r4.xyxx, t4.xxxx, s3, r4.z
mad r0.x, r0.z, r0.x, cb3[24].x
add r4.xyz, r3.xyzx, -cb3[25].xyzx
dp3 r0.z, r4.xyzx, r4.xyzx
sqrt r0.z, r0.z
mad r0.y, -r1.z, r0.y, r0.z
mad r0.y, cb3[25].w, r0.y, r1.w
mad_sat r0.z, r0.y, cb3[24].z, cb3[24].w
mad r0.y, r0.y, cb0[6].z, cb0[6].w
add_sat r0.y, -r0.y, l(1.000000)
add_sat r0.x, r0.z, r0.x
mul r1.xyz, r3.yyyy, cb0[8].xywx
mad r1.xyz, cb0[7].xywx, r3.xxxx, r1.xyzx
mad r1.xyz, cb0[9].xywx, r3.zzzz, r1.xyzx
add r1.xyz, r1.xyzx, cb0[10].xywx
div r0.zw, r1.xxxy, r1.zzzz
lt r1.x, r1.z, l(0.000000)
and r1.x, r1.x, l(0x3f800000)
sample_b r4.xyzw, r0.zwzz, t1.xyzw, s2, l(-8.000000)
mul r0.z, r1.x, r4.w
add r1.xyz, -r3.xyzx, cb0[4].xyzx
add r3.xyz, r3.xyzx, -r6.xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
mul r1.w, r0.w, cb0[4].w
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, r1.xyzx
sample r4.xyzw, r1.wwww, t2.xyzw, s1
mul r0.z, r0.z, r4.x
mul r0.x, r0.x, r0.z
mov_sat r0.z, r0.x
dp3 r0.w, r3.xyzx, r3.xyzx
rsq r0.w, r0.w
mad r3.xyz, -r3.xyzx, r0.wwww, r1.xyzx
dp3 r0.w, r3.xyzx, r3.xyzx
rsq r0.w, r0.w
mul r3.xyz, r0.wwww, r3.xyzx
mad r2.xyz, r2.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
mul r0.w, r2.w, l(128.000000)
dp3 r1.w, r2.xyzx, r2.xyzx
rsq r1.w, r1.w
mul r2.xyz, r1.wwww, r2.xyzx
dp3 r1.w, r3.xyzx, r2.xyzx
dp3 r1.x, r1.xyzx, r2.xyzx
max r1.x, r1.x, l(0.000000)
mul r0.x, r0.x, r1.x
mul r2.xyz, r0.xxxx, cb0[5].xyzx
max r0.x, r1.w, l(0.000000)
log r0.x, r0.x
mul r0.x, r0.x, r0.w
exp r0.x, r0.x
mul r0.x, r0.z, r0.x
dp3 r0.z, cb0[5].xyzx, l(0.220000, 0.707000, 0.071000, 0.000000)
mul r2.w, r0.z, r0.x
mul r0.xyzw, r0.yyyy, r2.xyzw
exp o0.xyzw, -r0.xyzw
ret
// Approximately 0 instruction slots used