// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed 177c87f646bbc23f-ps.txt
// 3DMigoto: 177c87f646bbc23f |    Unity headers extracted from Internal-ScreenSpaceShadows.shader
//    Shader "Hidden/Internal-ScreenSpaceShadows" {
//      Properties {
//       _ShadowMapTexture ("", any) = "" { }
//      }
//      Fallback Off
//      SubShader 1/2 {
//        Pass 1/1 {
//          ZTest Always
//          ZWrite Off
//          Cull Off
//          GpuProgramID 1194
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 6
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Internal-ScreenSpaceShadows.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201510240 21 1 0
//   Keywords { "SHADOWS_SINGLE_CASCADE" }
//   undeciphered2: 1 2 3 2 0 0
//   undeciphered3: 0 0
//   ConstBuffer "UnityPerCamera" 144
//   Vector 112 [_ZBufferParams]
//   Vector 128 [unity_OrthoParams]
//   ConstBuffer "UnityPerCameraRare" 352
//   Matrix 288 [unity_CameraToWorld]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Matrix 128 [unity_WorldToShadow0]
//   Matrix 192 [unity_WorldToShadow1]
//   Matrix 256 [unity_WorldToShadow2]
//   Matrix 320 [unity_WorldToShadow3]
//   SetTexture 0 [_CameraDepthTexture] 2D 0
//   SetTexture 1 [_ShadowMapTexture] 2D 1
//   BindCB "UnityPerCamera" 0
//   BindCB "UnityPerCameraRare" 1
//   BindCB "UnityShadows" 2
//
// 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:44 2018
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                 0   xy          0     NONE   float   xy
// TEXCOORD                 1   xyz         1     NONE   float   xyz
// TEXCOORD                 2   xyz         2     NONE   float   xyz
// TEXCOORD                 3   xyz         3     NONE   float   xyz
// TEXCOORD                 4      w        3     NONE   float      w
// SV_POSITION              0   xyzw        4      POS   float
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[9], immediateIndexed
dcl_constantbuffer cb1[22], immediateIndexed
dcl_constantbuffer cb2[25], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_comparison
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v0.xy
dcl_input_ps linear v1.xyz
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_output o0.xyzw
dcl_temps 5

// New input from vertex shader with unity_CameraInvProjection[0].x:
dcl_input_ps linear v3.w
dcl_constantbuffer cb10[4], immediateIndexed

// 3DMigoto StereoParams:
dcl_resource_texture2d (float,float,float,float) t125

ld_indexable(texture2d)(float,float,float,float) r2.xyzw, l(0, 0, 0, 0), t125.xyzw

sample r0.xyzw, v0.xyxx, t0.xyzw, s0
mad r0.y, cb0[7].x, r0.x, cb0[7].y
div r0.y, l(1.000000, 1.000000, 1.000000, 1.000000), r0.y
add r0.z, -r0.y, r0.x
mad r0.y, cb0[8].w, r0.z, r0.y
add r1.xyz, -v2.xyzx, v3.xyzx
mad r0.xzw, r0.xxxx, r1.xxyz, v2.xxyz
mad r0.xzw, -v1.xxyz, r0.yyyy, r0.xxzw
mul r1.xyz, r0.yyyy, v1.xyzx
mad r0.xyz, cb0[8].wwww, r0.xzwx, r1.xyzx

// copy depth from r0.z to r3.x:
mov r3.x, r0.z


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

add r4.x, r3.x, -r2.y
mul r4.x, r2.x, r4.x
ne r2.w, l(0.0, 0.0, 0.0, 0.0), v3.w
if_nz r2.w
  mad r0.x, -r4.x, v3.w, r0.x
endif

mul r1.xyzw, r0.yyyy, cb1[19].xyzw
mad r1.xyzw, cb1[18].xyzw, r0.xxxx, r1.xyzw
mad r1.xyzw, cb1[20].xyzw, r0.zzzz, r1.xyzw
mad_sat r0.x, r0.z, cb2[24].z, cb2[24].w
add r1.xyzw, r1.xyzw, cb1[21].xyzw

if_z r2.w
  mad r1.xyz, -r4.xxxx, cb10[0].xyzx, r1.xyzw
endif

mul r0.yzw, r1.yyyy, cb2[9].xxyz
mad r0.yzw, cb2[8].xxyz, r1.xxxx, r0.yyzw
mad r0.yzw, cb2[10].xxyz, r1.zzzz, r0.yyzw
mad r0.yzw, cb2[11].xxyz, r1.wwww, r0.yyzw
sample_c_lz r0.y, r0.yzyy, t1.xxxx, s1, r0.w
add r0.z, -cb2[24].x, l(1.000000)
mad r0.y, r0.y, r0.z, cb2[24].x
add o0.xyzw, r0.xxxx, r0.yyyy
ret
// Approximately 0 instruction slots used