// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed 63292a791807d111-ps.txt
// 3DMigoto: 63292a791807d111 |    Unity headers extracted from Internal-ScreenSpaceShadows.shader
//    Shader "Hidden/Internal-ScreenSpaceShadows" {
//      Properties {
//       _ShadowMapTexture ("", any) = "" { }
//      }
//      Fallback Off
//      SubShader 2/2 {
//        Tags { "ShadowmapFilter"="PCF_5x5" }
//        Pass 1/1 {
//          Tags { "ShadowmapFilter"="PCF_5x5" }
//          ZTest Always
//          ZWrite Off
//          Cull Off
//          GpuProgramID 88306
//          Program "fp" {
//            SubProgram "d3d11 " {
//              GpuProgramIndex 10
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Internal-ScreenSpaceShadows.shader.decompressed:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201510240 56 1 0
//   Keywords { "SHADOWS_SINGLE_CASCADE" }
//   undeciphered2: 1 2 4 2 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 128
//   Vector 112 [_ShadowMapTexture_TexelSize]
//   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 "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//   BindCB "UnityShadows" 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:53 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[8], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[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 11

// 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) r8.xyzw, l(0, 0, 0, 0), t125.xyzw

mov r0.xz, cb0[7].yyyy
mov r0.y, l(0.142857149)
sample r1.xyzw, v0.xyxx, t0.xyzw, s0
mad r0.w, cb1[7].x, r1.x, cb1[7].y
div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
add r1.y, -r0.w, r1.x
mad r0.w, cb1[8].w, r1.y, r0.w
add r1.yzw, -v2.xxyz, v3.xxyz
mad r1.xyz, r1.xxxx, r1.yzwy, v2.xyzx
mad r1.xyz, -v1.xyzx, r0.wwww, r1.xyzx
mul r2.xyz, r0.wwww, v1.xyzx
mad r1.xyz, cb1[8].wwww, r1.xyzx, r2.xyzx

// copy depth from r1.z to r9.x:
mov r9.x, r1.z


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

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

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

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

mul r2.xyz, r1.yyyy, cb3[9].xyzx
mad r2.xyz, cb3[8].xyzx, r1.xxxx, r2.xyzx
mad r1.xyz, cb3[10].xyzx, r1.zzzz, r2.xyzx
mad r1.xyz, cb3[11].xyzx, r1.wwww, r1.xyzx
mad r1.xy, r1.xyxx, cb0[7].zwzz, l(0.500000, 0.500000, 0.000000, 0.000000)
frc r2.xy, r1.xyxx
round_ni r1.xy, r1.xyxx
add r1.xy, r1.xyxx, l(-0.500000, -0.500000, 0.000000, 0.000000)
mad r2.zw, -r2.xxxy, l(0.000000, 0.000000, 2.000000, 2.000000), l(0.000000, 0.000000, 3.000000, 3.000000)
mad r3.xy, -r2.xyxx, l(3.000000, 3.000000, 0.000000, 0.000000), l(4.000000, 4.000000, 0.000000, 0.000000)
div r2.zw, r2.zzzw, r3.xxxy
add r4.xy, r2.zwzz, l(-2.000000, -2.000000, 0.000000, 0.000000)
mov r5.z, r4.y
mad r2.zw, r2.xxxy, l(0.000000, 0.000000, 3.000000, 3.000000), l(0.000000, 0.000000, 1.000000, 1.000000)
div r3.xz, r2.xxyx, r2.zzwz
add r5.xw, r3.xxxz, l(2.000000, 0.000000, 0.000000, 2.000000)
mov r4.w, r5.x
add r2.yz, r2.xxyx, l(0.000000, 3.000000, 3.000000, 0.000000)
mul r1.w, r2.x, l(3.000000)
mad r6.xz, r1.wwww, l(-1.000000, 0.000000, 1.000000, 0.000000), l(4.000000, 0.000000, 1.000000, 0.000000)
mul r5.xy, r2.yzyy, cb0[7].xyxx
mul r7.xyz, r0.xyzx, r5.zywz
mov r4.z, r5.x
mov r5.w, r7.x
mov r0.xz, cb0[7].xxxx
mov r0.y, l(0.142857149)
mul r5.xyz, r0.yxzy, r4.zxwz
mad r4.xyzw, r1.xyxy, cb0[7].xyxy, r5.ywxw
mad r0.xy, r1.xyxx, cb0[7].xyxx, r5.zwzz
sample_c_lz r0.x, r0.xyxx, t1.xxxx, s1, r1.z
sample_c_lz r0.y, r4.xyxx, t1.xxxx, s1, r1.z
sample_c_lz r0.z, r4.zwzz, t1.xxxx, s1, r1.z
mov r6.y, l(7.000000)
mul r2.xyz, r3.yyyy, r6.xyzx
mul r3.xyz, r2.wwww, r6.xyzx
mul r4.xy, r6.xzxx, l(7.000000, 7.000000, 0.000000, 0.000000)
mul r0.z, r0.z, r2.y
mad r0.y, r2.x, r0.y, r0.z
mad r0.x, r2.z, r0.x, r0.y
mov r7.w, r5.y
mad r2.xyzw, r1.xyxy, cb0[7].xyxy, r7.wywz
mov r5.yw, r7.yyyz
sample_c_lz r0.y, r2.xyxx, t1.xxxx, s1, r1.z
sample_c_lz r0.z, r2.zwzz, t1.xxxx, s1, r1.z
mad r0.x, r4.x, r0.y, r0.x
mad r2.xyzw, r1.xyxy, cb0[7].xyxy, r5.xyzy
mad r5.xyzw, r1.xyxy, cb0[7].xyxy, r5.xwzw
sample_c_lz r0.y, r2.xyxx, t1.xxxx, s1, r1.z
sample_c_lz r1.x, r2.zwzz, t1.xxxx, s1, r1.z
mad r0.x, r0.y, l(49.000000), r0.x
mad r0.x, r4.y, r1.x, r0.x
mad r0.x, r3.x, r0.z, r0.x
sample_c_lz r0.y, r5.xyxx, t1.xxxx, s1, r1.z
sample_c_lz r0.z, r5.zwzz, t1.xxxx, s1, r1.z
mad r0.x, r3.y, r0.y, r0.x
mad r0.x, r3.z, r0.z, r0.x
mul r0.x, r0.x, l(0.00694444450)
add r0.y, -cb3[24].x, l(1.000000)
mad r0.x, r0.x, r0.y, cb3[24].x
add o0.xyzw, r0.wwww, r0.xxxx
ret
// Approximately 0 instruction slots used