//Black lines at screen depth.
// ---- Created with 3Dmigoto v1.2.64 on Sat Sep 09 12:03:13 2017

cbuffer _Globals : register(b0)
{
  float4 _g_hatching_filter_param : packoffset(c0);
  float4 _g_hatching_filter_control_point[3] : packoffset(c1);
  row_major float4x4 _g_hatching_filter_uv_rotate_mtx : packoffset(c4);
  float4 _g_hatching_filter_param2 : packoffset(c8);
  float4 _g_hatching_filter_control_point2[3] : packoffset(c9);
  row_major float4x4 _g_hatching_filter_uv_rotate_mtx2 : packoffset(c12);
}

SamplerState _sampSrc_samplerstate_s : register(s0);
SamplerState _sampHatching0_samplerstate_s : register(s1);
SamplerState _sampHatching1_samplerstate_s : register(s2);
Texture2D<float4> _sampSrc : register(t0);
Texture2D<float4> _sampHatching0 : register(t1);
Texture2D<float4> _sampHatching1 : register(t2);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main( 
  float4 v0 : SV_Position0,
  float2 v1 : TEXCOORD0,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r10,r11;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 stereo = StereoParams.Load(0);
  float4 iniparams = IniParams.Load(0);
  
  r0.xyzw = _sampSrc.Sample(_sampSrc_samplerstate_s, v1.xy).xyzw;
  //v1.x+=stereo.x*iniparams.x;
  r1.x = max(r0.x, r0.y);
  r1.x = max(r1.x, r0.y);
  r1.y = min(r0.x, r0.y);
  r1.y = min(r1.y, r0.y);
  r1.x = r1.x + r1.y;
  r1.x = 0.5 * r1.x;
  r1.y = max(_g_hatching_filter_control_point[0].x, r1.x);
  r1.x = max(_g_hatching_filter_control_point2[0].x, r1.x);
  r1.x = min(_g_hatching_filter_control_point2[2].x, r1.x);
  r1.y = min(_g_hatching_filter_control_point[2].x, r1.y);
  r1.z = cmp(r1.y < _g_hatching_filter_control_point[1].x);
  r2.xyzw = r1.zzzz ? _g_hatching_filter_control_point[0].xyzw : _g_hatching_filter_control_point[1].xyzw;
  r1.y = -r2.x + r1.y;
  r1.y = r1.y / r2.z;
  r1.y = saturate(r2.w * r1.y + r2.y);
  
  r11.zw = _g_hatching_filter_uv_rotate_mtx._m10_m11 * v1.yy;
  r11.zw = v1.xx * _g_hatching_filter_uv_rotate_mtx._m00_m01 + r11.zw;
  r11.zw = r11.zw * _g_hatching_filter_param.xy + _g_hatching_filter_param.zw;
  
  r10.xy=v1.xy;
  r10.x-=stereo.x*(0.5-stereo.y*_g_hatching_filter_control_point2[2].x*0.125);
  
  r1.zw = _g_hatching_filter_uv_rotate_mtx._m10_m11 * v1.yy;
  r1.zw = r10.xx * _g_hatching_filter_uv_rotate_mtx._m00_m01 + r1.zw;
  r1.zw = r1.zw * _g_hatching_filter_param.xy + _g_hatching_filter_param.zw;
  r2.xyzw = _sampHatching0.Sample(_sampHatching0_samplerstate_s, r1.zw).xyzw;
  r3.xyzw = float4(1,1,1,1) + -r2.xyzw;
  r2.xyzw = r1.yyyy * r3.xyzw + r2.xyzw;
  r0.xyzw = r2.xyzw * r0.xyzw;
  
  r1.y = cmp(r1.x < _g_hatching_filter_control_point2[1].x);
  r2.xyzw = r1.yyyy ? _g_hatching_filter_control_point2[0].xyzw : _g_hatching_filter_control_point2[1].xyzw;
  r1.x = -r2.x + r1.x;
  r1.x = r1.x / r2.z;
  r1.x = saturate(r2.w * r1.x + r2.y);
  r1.yz = _g_hatching_filter_uv_rotate_mtx2._m10_m11 * v1.yy;
  //r10.x-=stereo.x*iniparams.x*0.5;
  r1.yz = r10.xx * _g_hatching_filter_uv_rotate_mtx2._m00_m01 + r1.yz;
  r1.yz = r1.yz * _g_hatching_filter_param2.xy + _g_hatching_filter_param2.zw;
  r2.xyzw = _sampHatching1.Sample(_sampHatching1_samplerstate_s, r1.yz).xyzw;
  r3.xyzw = float4(1,1,1,1) + -r2.xyzw;
  r1.xyzw = r1.xxxx * r3.xyzw + r2.xyzw;
  o0.xyzw = r1.xyzw * r0.xyzw;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20789
//
//   using 3Dmigoto v1.2.64 on Sat Sep 09 12:03:13 2017
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4 _g_hatching_filter_param;   // Offset:    0 Size:    16
//   float4 _g_hatching_filter_control_point[3];// Offset:   16 Size:    48
//   row_major float4x4 _g_hatching_filter_uv_rotate_mtx;// Offset:   64 Size:    64
//   float4 _g_hatching_filter_param2;  // Offset:  128 Size:    16
//   float4 _g_hatching_filter_control_point2[3];// Offset:  144 Size:    48
//   row_major float4x4 _g_hatching_filter_uv_rotate_mtx2;// Offset:  192 Size:    64
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// _sampSrc_samplerstate             sampler      NA          NA    0        1
// _sampHatching0_samplerstate       sampler      NA          NA    1        1
// _sampHatching1_samplerstate       sampler      NA          NA    2        1
// _sampSrc                          texture  float4          2d    0        1
// _sampHatching0                    texture  float4          2d    1        1
// _sampHatching1                    texture  float4          2d    2        1
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float       
// TEXCOORD                 0   xy          1     NONE   float   xy  
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[14], immediateIndexed
dcl_sampler s0, mode_default
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_output o0.xyzw
dcl_temps 4
sample_indexable(texture2d)(float,float,float,float) r0.xyzw, v1.xyxx, t0.xyzw, s0
max r1.x, r0.y, r0.x
max r1.x, r0.y, r1.x
min r1.y, r0.y, r0.x
min r1.y, r0.y, r1.y
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)
max r1.y, r1.x, cb0[1].x
max r1.x, r1.x, cb0[9].x
min r1.x, r1.x, cb0[11].x
min r1.y, r1.y, cb0[3].x
lt r1.z, r1.y, cb0[2].x
movc r2.xyzw, r1.zzzz, cb0[1].xyzw, cb0[2].xyzw
add r1.y, r1.y, -r2.x
div r1.y, r1.y, r2.z
mad_sat r1.y, r2.w, r1.y, r2.y
mul r1.zw, v1.yyyy, cb0[5].xxxy
mad r1.zw, v1.xxxx, cb0[4].xxxy, r1.zzzw
mad r1.zw, r1.zzzw, cb0[0].xxxy, cb0[0].zzzw
sample_indexable(texture2d)(float,float,float,float) r2.xyzw, r1.zwzz, t1.xyzw, s1
add r3.xyzw, -r2.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
mad r2.xyzw, r1.yyyy, r3.xyzw, r2.xyzw
mul r0.xyzw, r0.xyzw, r2.xyzw
lt r1.y, r1.x, cb0[10].x
movc r2.xyzw, r1.yyyy, cb0[9].xyzw, cb0[10].xyzw
add r1.x, r1.x, -r2.x
div r1.x, r1.x, r2.z
mad_sat r1.x, r2.w, r1.x, r2.y
mul r1.yz, v1.yyyy, cb0[13].xxyx
mad r1.yz, v1.xxxx, cb0[12].xxyx, r1.yyzy
mad r1.yz, r1.yyzy, cb0[8].xxyx, cb0[8].zzwz
sample_indexable(texture2d)(float,float,float,float) r2.xyzw, r1.yzyy, t2.xyzw, s2
add r3.xyzw, -r2.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
mad r1.xyzw, r1.xxxx, r3.xyzw, r2.xyzw
mul o0.xyzw, r0.xyzw, r1.xyzw
ret 
// Approximately 36 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
