// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed 7ed5a446fc23c9d8-ps.txt
// 3DMigoto: 7ed5a446fc23c9d8 | 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_64" }
// 01000100:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 04000400:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 10001000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 40004000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00040004:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00100010:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00400040:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00020002:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 02000200:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 08000800:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 20002000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 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_64" }
// 00080008:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00200020:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
// 00800080:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_64" }
//             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:53 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.118705302, 0.795156479, 0, 0},
                              { 0.117367499, 0.608787775, 0, 0},
                              { -0.0995851830, 0.724884212, 0, 0},
                              { 0.425981194, 0.615271807, 0, 0},
                              { 0.372357398, 0.889278710, 0, 0},
                              { -0.0228967592, 0.997290790, 0, 0},
                              { -0.0823479071, 0.504838586, 0, 0},
                              { 0.182123497, 0.967378676, 0, 0},
                              { -0.213726401, 0.901174605, 0, 0},
                              { 0.311506599, 0.420541495, 0, 0},
                              { 0.121632896, 0.383266, 0, 0},
                              { 0.594893873, 0.759436071, 0, 0},
                              { 0.757646501, 0.533641696, 0, 0},
                              { -0.521125, 0.759980321, 0, 0},
                              { -0.292312711, 0.654569924, 0, 0},
                              { 0.678247273, 0.223850, 0, 0},
                              { -0.307715207, 0.469762713, 0, 0},
                              { 0.448491305, 0.261945486, 0, 0},
                              { -0.530879915, 0.499821514, 0, 0},
                              { -0.737963378, 0.530493617, 0, 0},
                              { 0.0261313301, 0.176430196, 0, 0},
                              { -0.146107301, 0.304738402, 0, 0},
                              { -0.845102727, 0.324907303, 0, 0},
                              { -0.450770706, 0.210199699, 0, 0},
                              { -0.613728225, 0.328367412, 0, 0},
                              { -0.238586798, 0.0871624425, 0, 0},
                              { 0.338654786, 0.0152841099, 0, 0},
                              { -0.0423083305, -0.149465203, 0, 0},
                              { 0.167115, -0.109864801, 0, 0},
                              { -0.525606, 0.0157201905, 0, 0},
                              { -0.796685517, 0.131872699, 0, 0},
                              { 0.570428729, 0.477827311, 0, 0},
                              { -0.951663673, 0.00272503193, 0, 0},
                              { -0.706822276, -0.157232106, 0, 0},
                              { 0.217330605, -0.349408299, 0, 0},
                              { 0.0610042587, -0.449281603, 0, 0},
                              { 0.233398199, 0.224718899, 0, 0},
                              { 0.0727098733, -0.639673412, 0, 0},
                              { 0.467080802, -0.232466906, 0, 0},
                              { 0.372952789, -0.512625, 0, 0},
                              { 0.567507684, -0.405454397, 0, 0},
                              { -0.369198412, -0.128435, 0, 0},
                              { 0.875247300, 0.225698799, 0, 0},
                              { -0.268012702, -0.468439311, 0, 0},
                              { -0.117755100, -0.720575094, 0, 0},
                              { -0.127012104, -0.310542405, 0, 0},
                              { 0.559539378, -0.0630923733, 0, 0},
                              { -0.929913580, -0.187000796, 0, 0},
                              { 0.974674, 0.0367734805, 0, 0},
                              { 0.772673488, -0.0694472417, 0, 0},
                              { -0.499536097, -0.366374910, 0, 0},
                              { 0.647416770, -0.231578693, 0, 0},
                              { 0.191144899, -0.885892093, 0, 0},
                              { 0.367100090, -0.797053516, 0, 0},
                              { -0.697035313, -0.444943190, 0, 0},
                              { -0.417599, -0.718932629, 0, 0},
                              { -0.558474779, -0.602650404, 0, 0},
                              { -0.0262444802, -0.914142311, 0, 0},
                              { 0.565636, -0.658514917, 0, 0},
                              { -0.874976, -0.399787903, 0, 0},
                              { 0.917784274, -0.211052403, 0, 0},
                              { 0.815692723, -0.396955699, 0, 0},
                              { -0.283305407, -0.839544415, 0, 0},
                              { 0.799141, -0.588637173, 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 7ed5a446fc23c9d8-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(64.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.015625, 0.015625, 0.015625, 0.015625), cb3[24].xxxx
ret
// Approximately 0 instruction slots used