// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed 6a3b1f6d7961a004-ps.txt
// 3DMigoto: 6a3b1f6d7961a004 | Matched 64 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 35 1 1
//                     undeciphered1a: 5
// 0000000100000001:   Keywords { "SHADOWS_SINGLE_CASCADE" "DIR_POISSON_25" }
// 0001000000010000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "DIR_POISSON_25" }
// 0004000000040000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0100000001000000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 0400000004000000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 1000000010000000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 4000000040000000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0010000000100000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0040000000400000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000000400000004:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000010000000100:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 0000040000000400:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000100000001000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0000400000004000:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000001000000010:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0000004000000040:   Keywords { "SHADOWS_SINGLE_CASCADE" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000000200000002:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "DIR_POISSON_25" }
// 0002000000020000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "DIR_POISSON_25" }
// 0008000000080000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0200000002000000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 0800000008000000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 2000000020000000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 8000000080000000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0020000000200000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0080000000800000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_PCSS_FILTER_DIR" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000000800000008:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000020000000200:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 0000080000000800:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000200000002000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0000800000008000:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0000002000000020:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0000008000000080:   Keywords { "SHADOWS_SPLIT_SPHERES" "SHADOWS_SINGLE_CASCADE" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
//                     undeciphered2: 1 2 4 2 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 1
//                     SetTexture 1 [_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:56:51 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// 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.635181785, 0.217271104, 0, 0},
                              { -0.149960607, 0.232067496, 0, 0},
                              { -0.679780, 0.688492417, 0, 0},
                              { -0.775864720, -0.253409, 0, 0},
                              { -0.473191589, -0.283272296, 0, 0},
                              { -0.333007902, 0.643005908, 0, 0},
                              { -0.138415098, -0.0983022526, 0, 0},
                              { -0.818232715, -0.564593911, 0, 0},
                              { -0.919847190, 0.0654980168, 0, 0},
                              { -0.142208502, -0.487210900, 0, 0},
                              { -0.498083293, -0.588559926, 0, 0},
                              { -0.332615912, -0.849614799, 0, 0},
                              { 0.306673586, -0.140199706, 0, 0},
                              { 0.114831701, 0.374455, 0, 0},
                              { -0.0388568006, 0.807132900, 0, 0},
                              { 0.410288513, 0.696029484, 0, 0},
                              { 0.556387722, 0.337537706, 0, 0},
                              { -0.0178657603, -0.887376487, 0, 0},
                              { 0.234991, -0.455843806, 0, 0},
                              { 0.620677471, -0.155100495, 0, 0},
                              { 0.664064229, -0.569142699, 0, 0},
                              { 0.731272578, 0.583016813, 0, 0},
                              { 0.887970686, 0.0571521297, 0, 0},
                              { 0.312829614, -0.830803, 0, 0},
                              { 0.868976414, -0.339797288, 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_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_input_ps linear v4.xyz
dcl_output o0.xyzw
dcl_temps 8

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

sample r0.xyzw, v1.xyxx, t0.xyzw, s1
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 r6.x:
mov r6.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 6a3b1f6d7961a004-ps.txt

add r7.x, r6.x, -r5.y
mul r7.x, r5.x, r7.x
ne r5.w, l(0.0, 0.0, 0.0, 0.0), v4.w
if_nz r5.w
  mad r0.x, -r7.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 r5.w
  mad r0.xyz, -r7.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
dp3 r0.w, v1.zwwz, l(12.989800, 78.233002, 45.543201, 0.000000)
sincos r0.w, null, r0.w
mul r0.w, r0.w, l(43758.546875)
frc r0.w, r0.w
mul r0.w, r0.w, cb0[68].y
mul r0.w, r0.w, l(0.050000)
sincos r1.x, r2.x, r0.w
add r0.w, cb0[68].z, l(0.001000)
mul r0.w, r0.w, l(0.150000)
mov r1.yz, l(0,0,0,0)
loop
  itof r1.w, r1.z
  ge r1.w, r1.w, l(25.000000)
  breakc_nz r1.w
  mul r2.yz, r0.wwww, icb[r1.z + 0].yyxy
  mul r3.xy, r1.xxxx, r2.yzyy
  mad r4.x, r2.z, r2.x, -r3.x
  mad r4.y, r2.y, r2.x, r3.y
  add r2.yz, r0.xxyx, r4.xxyx
  sample_c_lz r1.w, r2.yzyy, t1.xxxx, s0, r0.z
  add r1.y, r1.w, r1.y
  iadd r1.z, r1.z, l(1)
endloop
mad o0.xyzw, r1.yyyy, l(0.040000, 0.040000, 0.040000, 0.040000), cb3[24].xxxx
ret
// Approximately 0 instruction slots used