// asmtool.py -I ../.. --fix-unity-lighting-ps=TEXCOORD4 --only-autofixed d70b726b6c0239d5-ps.txt
// 3DMigoto: d70b726b6c0239d5 | Matched 8 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 103 2 8
//       undeciphered1a: 8
// 44:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 88:   Keywords { "NGSS_PCSS_FILTER_DIR" "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_USE_BIAS_FADE_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 11:   Keywords { "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "NGSS_NOISE_STATIC_DIR" "DIR_POISSON_32" }
// 22:   Keywords { "NGSS_USE_CASCADE_BLENDING" "NGSS_USE_EARLY_BAILOUT_OPTIMIZATION_DIR" "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 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 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 18:02:43 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.123298101, -0.0392337516, 0.487390190, -0.856959879},
                              { -0.562537730, -0.360242814, 0.346373707, -0.338793904},
                              { 0.640371919, 0.0682112277, 0.629005492, -0.473531395},
                              { 0.281338692, -0.588158786, 0.185585395, -0.884814203},
                              { -0.573121786, 0.270057201, 0.767791688, 0.0269116201},
                              { 0.203316599, 0.419773906, 0.300914198, -0.636587322},
                              { 0.846795797, -0.354558408, 0.426842213, -0.00613762904},
                              { -0.423045099, -0.797441, -0.0668298230, -0.783380508},
                              { 0.719025314, 0.569357514, 0.0347262993, -0.399412394},
                              { 0.0381546803, -0.991417110, 0.449469388, 0.520661414},
                              { -0.223626494, 0.502861381, 0.219377, 0.243884400},
                              { 0.172225401, 0.983663, 0.128576502, -0.121555403},
                              { -0.291246414, 0.898051202, 0.890704870, 0.433493108},
                              { -0.898414791, -0.0876278579, 0.255646914, 0.766552},
                              { -0.699508488, 0.673418522, -0.0369240604, 0.362923592},
                              { -0.293196, -0.0628911927, 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} }
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 11

// 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) r8.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 r9.x:
mov r9.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 d70b726b6c0239d5-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), v4.w
if_nz r8.w
  mad r0.x, -r10.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 r8.w
  mad r1.xyz, -r10.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)
mul r5.xy, v1.xyxx, cb0[68].yyyy
sample r5.xyzw, r5.xyxx, t1.xyzw, s1
sincos null, r1.w, r5.x
sincos r3.w, null, r5.y
add r4.w, cb0[68].z, l(0.001000)
mul r4.w, r4.w, l(0.150000)
mov r5.xy, l(0,0,0,0)
loop
  ige r5.z, r5.y, l(16)
  breakc_nz r5.z
  mul r5.zw, r4.wwww, icb[r5.y + 0].yyyx
  mul r6.xy, r3.wwww, r5.zwzz
  mad r7.x, r5.w, r1.w, -r6.x
  mad r7.y, r5.z, r1.w, r6.y
  add r5.zw, r0.xxxy, r7.xxxy
  sample_c_lz r5.z, r5.zwzz, t2.xxxx, s0, r0.w
  add r5.x, r5.z, r5.x
  iadd r5.y, r5.y, l(1)
endloop
eq r5.xy, r5.xxxx, l(0.000000, 16.000000, 0.000000, 0.000000)
or r5.y, r5.y, r5.x
if_z r5.y
  mov r5.yz, l(0,0,0,0)
  loop
    itof r5.w, r5.z
    ge r5.w, r5.w, l(32.000000)
    breakc_nz r5.w
    mul r6.xy, r4.wwww, icb[r5.z + 0].wzww
    mul r6.zw, r3.wwww, r6.xxxy
    mad r7.x, r6.y, r1.w, -r6.z
    mad r7.y, r6.x, r1.w, r6.w
    add r6.xy, r0.xyxx, r7.xyxx
    sample_c_lz r5.w, r6.xyxx, t2.xxxx, s0, r0.w
    add r5.y, r5.w, r5.y
    iadd r5.z, r5.z, l(1)
  endloop
  mul r0.x, r5.y, l(0.031250)
else
  movc r0.x, r5.x, l(0), l(1.000000)
endif
add r5.xyzw, r0.zzzz, -cb3[6].xyzw
add r6.xyzw, -cb3[6].xyzw, cb3[7].xyzw
div r5.xyzw, r5.xyzw, r6.xyzw
mul r5.xyzw, r2.xyzw, r5.xyzw
dp4 r0.y, r5.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
    ige r2.x, r1.z, l(16)
    breakc_nz r2.x
    mul r2.xy, r4.wwww, icb[r1.z + 0].yxyy
    mul r2.zw, r3.wwww, r2.xxxy
    mad r3.x, r2.y, r1.w, -r2.z
    mad r3.y, r2.x, r1.w, r2.w
    add r2.xy, r1.xyxx, r3.xyxx
    sample_c_lz r2.x, r2.xyxx, t2.xxxx, s0, r0.z
    add r0.w, r0.w, r2.x
    iadd r1.z, r1.z, l(1)
  endloop
  eq r2.xy, r0.wwww, l(0.000000, 16.000000, 0.000000, 0.000000)
  movc r0.w, r2.x, l(0), l(1.000000)
  or r1.z, r2.y, r2.x
  if_z r1.z
    mov r1.z, l(0)
    mov r2.x, l(0)
    loop
      itof r2.y, r2.x
      ge r2.y, r2.y, l(32.000000)
      breakc_nz r2.y
      mul r2.yz, r4.wwww, icb[r2.x + 0].wwzw
      mul r3.xy, r3.wwww, r2.yzyy
      mad r4.x, r2.z, r1.w, -r3.x
      mad r4.y, r2.y, r1.w, r3.y
      add r2.yz, r1.xxyx, r4.xxyx
      sample_c_lz r2.y, r2.yzyy, t2.xxxx, s0, r0.z
      add r1.z, r1.z, r2.y
      iadd r2.x, r2.x, l(1)
    endloop
    mul r0.w, r1.z, l(0.031250)
  endif
  add r0.z, -r0.x, r0.w
  mad r0.x, r0.y, r0.z, r0.x
endif
add o0.xyzw, r0.xxxx, cb3[24].xxxx
ret
// Approximately 0 instruction slots used