// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed 7da9b74c9d77493f-ps.txt
// 3DMigoto: 7da9b74c9d77493f | Matched 32 variants of 1 shaders: Hidden/NGSS_Directional
//
//              Unity headers extracted from Hidden_NGSS_Directional
//              Shader "Hidden/NGSS_Directional" {
//           1:   SubShader 1/4 {
//           2:   SubShader 3/4 {
//                  Tags { "ShadowmapFilter"="PCF_SOFT" }
//                  Pass 1/1 {
//                    Tags { "ShadowmapFilter"="PCF_SOFT" }
//                    ZWrite Off
//                    Program "fp" {
//                      SubProgram "d3d11" {
//                      }
//                    }
//                  }
//                }
//              }
//
//           Unity 5.3 headers extracted from Hidden_NGSS_Directional:
//             API d3d11
//             Shader model ps_4_0
//             undeciphered1: 201609010 32 2 1
//             undeciphered1a: 4
// 00010001:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 01000100:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 04000400:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 10001000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 40004000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00040004:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00100010:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00400040:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00020002:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 02000200:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 08000800:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 20002000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 80008000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00080008:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00200020:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 00800080:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
//             undeciphered2: 1 3 4 3 0 0
//             undeciphered3: 0 0
//             ConstBuffer "$Globals" 2144
//             Float 1092 [NGSS_POISSON_SAMPLING_NOISE_DIR]
//             Float 1096 [NGSS_PCSS_GLOBAL_SOFTNESS]
//             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 2
//             SetTexture 1 [unity_RandomRotation16] 2D 1
//             SetTexture 2 [_ShadowMapTexture] 2D 0
//             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.16 on Sun Apr 21 17:57:49 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy
// TEXCOORD                 1   xyz         2     NONE   float   xyz
// TEXCOORD                 2   xyz         3     NONE   float   xyz
// TEXCOORD                 3   xyz         4     NONE   float   xyz
// TEXCOORD                 4      w        4     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.487390190, -0.856959879, 0, 0},
                              { 0.346373707, -0.338793904, 0, 0},
                              { 0.629005492, -0.473531395, 0, 0},
                              { 0.185585395, -0.884814203, 0, 0},
                              { 0.767791688, 0.0269116201, 0, 0},
                              { 0.300914198, -0.636587322, 0, 0},
                              { 0.426842213, -0.00613762904, 0, 0},
                              { -0.0668298230, -0.783380508, 0, 0},
                              { 0.0347262993, -0.399412394, 0, 0},
                              { 0.449469388, 0.520661414, 0, 0},
                              { 0.219377, 0.243884400, 0, 0},
                              { 0.128576502, -0.121555403, 0, 0},
                              { 0.890704870, 0.433493108, 0, 0},
                              { 0.255646914, 0.766552, 0, 0},
                              { -0.0369240604, 0.362923592, 0, 0},
                              { 0.665110290, 0.728681087, 0, 0},
                              { -0.429309, -0.228226200, 0, 0},
                              { -0.273096889, -0.468351305, 0, 0},
                              { -0.275598586, 0.732791305, 0, 0},
                              { -0.332970500, 0.175463796, 0, 0},
                              { -0.173132598, -0.108771600, 0, 0},
                              { 0.921222627, -0.371663809, 0, 0},
                              { -0.538823485, 0.460396796, 0, 0},
                              { -0.630732119, 0.761592388, 0, 0},
                              { -0.770917475, -0.0889493674, 0, 0},
                              { -0.720597088, -0.360949308, 0, 0},
                              { -0.538620174, -0.584715903, 0, 0},
                              { -0.652083397, 0.178528398, 0, 0},
                              { -0.931058228, 0.204034299, 0, 0},
                              { -0.828178, 0.555959880, 0, 0},
                              { 0.629783571, 0.294650108, 0, 0},
                              { -0.0583608411, 0.900680721, 0, 0} }
dcl_constantbuffer cb0[69], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[25], immediateIndexed
dcl_sampler s0, mode_comparison
dcl_sampler s1, mode_default
dcl_sampler s2, 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_input_ps linear v1.xy
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_input_ps linear v4.xyz
dcl_output o0.xyzw
dcl_temps 7

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

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

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

sample r0.xyzw, v1.xyxx, t0.xyzw, s2
mad r0.y, cb1[7].x, r0.x, cb1[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, cb1[8].w, r0.z, r0.y
add r0.x, -r0.x, l(1.000000)
mul r1.xyz, r0.yyyy, v2.xyzx
add r2.xyz, -v3.xyzx, v4.xyzx
mad r0.xzw, r0.xxxx, r2.xxyz, v3.xxyz
mad r0.xyz, -v2.xyzx, r0.yyyy, r0.xzwx
mad r0.xyz, cb1[8].wwww, r0.xyzx, r1.xyzx

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

add r6.x, r5.x, -r4.y
mul r6.x, r4.x, r6.x
ne r4.w, l(0.0, 0.0, 0.0, 0.0), v4.w
if_nz r4.w
  mad r0.x, -r6.x, v4.w, r0.x
endif

mul r1.xyzw, r0.yyyy, cb2[19].xyzw
mad r1.xyzw, cb2[18].xyzw, r0.xxxx, r1.xyzw
mad r0.xyzw, cb2[20].xyzw, r0.zzzz, r1.xyzw
add r0.xyzw, r0.xyzw, cb2[21].xyzw

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

mul r1.xyz, r0.yyyy, cb3[9].xyzx
mad r1.xyz, cb3[8].xyzx, r0.xxxx, r1.xyzx
mad r0.xyz, cb3[10].xyzx, r0.zzzz, r1.xyzx
mad r0.xyz, cb3[11].xyzx, r0.wwww, r0.xyzx
mul r1.xy, v1.xyxx, cb0[68].yyyy
sample r1.xyzw, r1.xyxx, t1.xyzw, s1
sincos null, r0.w, r1.x
sincos r1.x, null, r1.y
add r1.y, cb0[68].z, l(0.001000)
mul r1.y, r1.y, l(0.150000)
mov r1.zw, l(0,0,0,0)
loop
  itof r2.x, r1.w
  ge r2.x, r2.x, l(32.000000)
  breakc_nz r2.x
  mul r2.xy, r1.yyyy, icb[r1.w + 0].yxyy
  mul r2.zw, r1.xxxx, r2.xxxy
  mad r3.x, r2.y, r0.w, -r2.z
  mad r3.y, r2.x, r0.w, r2.w
  add r2.xy, r0.xyxx, r3.xyxx
  sample_c_lz r2.x, r2.xyxx, t2.xxxx, s0, r0.z
  add r1.z, r1.z, r2.x
  iadd r1.w, r1.w, l(1)
endloop
mad o0.xyzw, r1.zzzz, l(0.031250, 0.031250, 0.031250, 0.031250), cb3[24].xxxx
ret
// Approximately 0 instruction slots used