// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed d0f0a235cd9d8e92-ps.txt
// 3DMigoto: d0f0a235cd9d8e92 | Matched 16 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 85 1 3
//         undeciphered1a: 9
// 1010:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 2020:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 4040:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 8080:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0101:   Keywords { "NGSS_USE_CASCADE_BLENDING" "DIR_POISSON_25" }
// 0202:   Keywords { "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_BIAS_FADE_DIR" "DIR_POISSON_25" }
// 0404:   Keywords { "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "DIR_POISSON_25" }
// 0808:   Keywords { "NGSS_USE_CASCADE_BLENDING" "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 1088 [NGSS_CASCADE_BLEND_DISTANCE]
//         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 96 [_LightSplitsNear]
//         Vector 112 [_LightSplitsFar]
//         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 18:02:23 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 12

// 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) r9.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 r10.x:
mov r10.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 d0f0a235cd9d8e92-ps.txt

add r11.x, r10.x, -r9.y
mul r11.x, r9.x, r11.x
ne r9.w, l(0.0, 0.0, 0.0, 0.0), v4.w
if_nz r9.w
  mad r0.x, -r11.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 r1.xyzw, cb2[20].xyzw, r0.zzzz, r1.xyzw
add r1.xyzw, r1.xyzw, cb2[21].xyzw

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

ge r2.xyzw, r0.zzzz, cb3[6].xyzw
and r2.xyzw, r2.xyzw, l(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000)
lt r3.xyzw, r0.zzzz, cb3[7].xyzw
and r3.xyzw, r3.xyzw, l(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000)
mul r2.xyzw, r2.xyzw, r3.xyzw
mul r0.xyw, r1.yyyy, cb3[9].xyxz
mad r0.xyw, cb3[8].xyxz, r1.xxxx, r0.xyxw
mad r0.xyw, cb3[10].xyxz, r1.zzzz, r0.xyxw
mad r0.xyw, cb3[11].xyxz, r1.wwww, r0.xyxw
mul r3.xyz, r1.yyyy, cb3[13].xyzx
mad r3.xyz, cb3[12].xyzx, r1.xxxx, r3.xyzx
mad r3.xyz, cb3[14].xyzx, r1.zzzz, r3.xyzx
mad r3.xyz, cb3[15].xyzx, r1.wwww, r3.xyzx
mul r4.xyz, r1.yyyy, cb3[17].xyzx
mad r4.xyz, cb3[16].xyzx, r1.xxxx, r4.xyzx
mad r4.xyz, cb3[18].xyzx, r1.zzzz, r4.xyzx
mad r4.xyz, cb3[19].xyzx, r1.wwww, r4.xyzx
mul r5.xyz, r1.yyyy, cb3[21].xyzx
mad r5.xyz, cb3[20].xyzx, r1.xxxx, r5.xyzx
mad r1.xyz, cb3[22].xyzx, r1.zzzz, r5.xyzx
mad r1.xyz, cb3[23].xyzx, r1.wwww, r1.xyzx
mul r5.xyz, r2.yyyy, r3.xyzx
mad r0.xyw, r0.xyxw, r2.xxxx, r5.xyxz
mad r0.xyw, r4.xyxz, r2.zzzz, r0.xyxw
mad r0.xyw, r1.xyxz, r2.wwww, r0.xyxw
dp4 r1.w, r2.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
add r0.w, r0.w, -r1.w
add r0.w, r0.w, l(1.000000)
dp3 r1.w, v1.zwwz, l(12.989800, 78.233002, 45.543201, 0.000000)
sincos r1.w, null, r1.w
mul r1.w, r1.w, l(43758.546875)
frc r1.w, r1.w
mul r1.w, r1.w, cb0[68].y
mul r1.w, r1.w, l(0.050000)
sincos r5.x, r6.x, r1.w
add r1.w, cb0[68].z, l(0.001000)
mul r1.w, r1.w, l(0.150000)
mov r3.w, l(0)
mov r4.w, l(0)
loop
  itof r5.y, r4.w
  ge r5.y, r5.y, l(25.000000)
  breakc_nz r5.y
  mul r5.yz, r1.wwww, icb[r4.w + 0].yyxy
  mul r6.yz, r5.xxxx, r5.yyzy
  mad r7.x, r5.z, r6.x, -r6.y
  mad r7.y, r5.y, r6.x, r6.z
  add r5.yz, r0.xxyx, r7.xxyx
  sample_c_lz r5.y, r5.yzyy, t1.xxxx, s0, r0.w
  add r3.w, r3.w, r5.y
  iadd r4.w, r4.w, l(1)
endloop
mul r0.x, r3.w, l(0.040000)
add r7.xyzw, r0.zzzz, -cb3[6].xyzw
add r8.xyzw, -cb3[6].xyzw, cb3[7].xyzw
div r7.xyzw, r7.xyzw, r8.xyzw
mul r7.xyzw, r2.xyzw, r7.xyzw
dp4 r0.y, r7.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
add r0.z, -cb0[68].x, l(1.000000)
lt r0.w, r0.z, r0.y
if_nz r0.w
  add r0.y, -r0.z, r0.y
  div r0.y, r0.y, cb0[68].x
  mul r4.xyz, r2.yyyy, r4.xyzx
  mad r3.xyz, r3.xyzx, r2.xxxx, r4.xyzx
  mad r1.xyz, r1.xyzx, r2.zzzz, r3.xyzx
  dp3 r0.z, r2.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
  add r0.z, -r0.z, r1.z
  add r0.z, r0.z, l(1.000000)
  mov r0.w, l(0)
  mov r1.z, l(0)
  loop
    itof r2.x, r1.z
    ge r2.x, r2.x, l(25.000000)
    breakc_nz r2.x
    mul r2.xy, r1.wwww, icb[r1.z + 0].yxyy
    mul r2.zw, r5.xxxx, r2.xxxy
    mad r3.x, r2.y, r6.x, -r2.z
    mad r3.y, r2.x, r6.x, r2.w
    add r2.xy, r1.xyxx, r3.xyxx
    sample_c_lz r2.x, r2.xyxx, t1.xxxx, s0, r0.z
    add r0.w, r0.w, r2.x
    iadd r1.z, r1.z, l(1)
  endloop
  mad r0.z, r0.w, l(0.040000), -r0.x
  mad r0.x, r0.y, r0.z, r0.x
endif
add o0.xyzw, r0.xxxx, cb3[24].xxxx
ret
// Approximately 0 instruction slots used