//Volumetric lighting clipping.
// ---- Created with 3Dmigoto v1.3.16 on Sat Jan 08 21:42:14 2022

cbuffer cbLightShaftFilter : register(b0)
{
  float filterEdgeSharpness : packoffset(c0);
  uint filterScale : packoffset(c0.y);
  float _LightShaftFilter_Reserved0 : packoffset(c0.z);
  float _LightShaftFilter_Reserved1 : packoffset(c0.w);
}

Texture2D<float4> tLightShaft : register(t0);


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


void main(
  float4 v0 : SV_Position0,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4,r10,r11;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  float4 iniparams10 = IniParams.Load(int2(10,0));
  
  r10.xy = (int2)v0.xy;
  
  //v0.x-=stereo.x*iniparams10.x*0.5;
  
  r0.xy = (int2)v0.xy;
  r1.x = trunc(v0.y);
  r0.z = (int)r1.x;
  r0.w = 0;
  
  r10.yzw=r0.yzw;
  r11.xyzw = tLightShaft.Load(r10.xzw).xyzw;
  
  r1.xyzw = tLightShaft.Load(r0.xzw).xyzw;
  r0.z = cmp(0 >= r1.w);
  if (r0.z != 0) {
    o0.xyzw = float4(0,0,0,0);
    return;
  }
  r2.xyzw = mad(int4(0,-3,0,-4), filterScale, (int4)r0.xyxy);
  r3.xy = r2.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.z = r3.w + -r1.w;
  r0.z = -filterEdgeSharpness * abs(r0.z) + 1;
  r0.z = max(0, r0.z);
  r0.w = 0.362969995 * r0.z;
  r3.xyz = r3.xyz * r0.www;
  r1.xyz = r1.xyz * float3(0.153170004,0.153170004,0.153170004) + r3.xyz;
  r0.z = r0.z * 0.362969995 + 0.153170004;
  r2.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r2.xyz).xyzw;
  r0.w = r2.w + -r1.w;
  r0.w = -filterEdgeSharpness * abs(r0.w) + 1;
  r0.w = max(0, r0.w);
  r2.w = 0.392902017 * r0.w;
  r1.xyz = r2.xyz * r2.www + r1.xyz;
  r0.z = r0.w * 0.392902017 + r0.z;
  r2.xyzw = mad(int4(0,-1,0,-2), filterScale, (int4)r0.xyxy);
  r3.xy = r2.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.w = r3.w + -r1.w;
  r0.w = -filterEdgeSharpness * abs(r0.w) + 1;
  r0.w = max(0, r0.w);
  r3.w = 0.422649026 * r0.w;
  r1.xyz = r3.xyz * r3.www + r1.xyz;
  r0.z = r0.w * 0.422649026 + r0.z;
  r2.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r2.xyz).xyzw;
  r0.w = r2.w + -r1.w;
  r0.w = -filterEdgeSharpness * abs(r0.w) + 1;
  r0.w = max(0, r0.w);
  r2.w = 0.444893003 * r0.w;
  r1.xyz = r2.xyz * r2.www + r1.xyz;
  r0.z = r0.w * 0.444893003 + r0.z;
  r2.xyzw = mad(int4(0,3,0,1), filterScale, (int4)r0.xyxy);
  r3.xy = r2.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.w = r3.w + -r1.w;
  r0.w = -filterEdgeSharpness * abs(r0.w) + 1;
  r0.w = max(0, r0.w);
  r3.w = 0.444893003 * r0.w;
  r1.xyz = r3.xyz * r3.www + r1.xyz;
  r0.z = r0.w * 0.444893003 + r0.z;
  r3.xyzw = filterScale << int4(1,1,2,2);
  r3.xyzw = mad(int4(0,1,0,1), (int4)r3.zwxy, (int4)r0.xyxy);
  r4.xy = r3.zw;
  r4.zw = float2(0,0);
  r4.xyzw = tLightShaft.Load(r4.xyz).xyzw;
  r0.x = r4.w + -r1.w;
  r0.x = -filterEdgeSharpness * abs(r0.x) + 1;
  r0.x = max(0, r0.x);
  r0.y = 0.422649026 * r0.x;
  r1.xyz = r4.xyz * r0.yyy + r1.xyz;
  r0.x = r0.x * 0.422649026 + r0.z;
  r2.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r2.xyz).xyzw;
  r0.y = r2.w + -r1.w;
  r0.y = -filterEdgeSharpness * abs(r0.y) + 1;
  r0.y = max(0, r0.y);
  r0.z = 0.392902017 * r0.y;
  r1.xyz = r2.xyz * r0.zzz + r1.xyz;
  r0.x = r0.y * 0.392902017 + r0.x;
  r3.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.y = r2.w + -r1.w;
  r0.y = -filterEdgeSharpness * abs(r0.y) + 1;
  r0.y = max(0, r0.y);
  r0.z = 0.362969995 * r0.y;
  r1.xyz = r2.xyz * r0.zzz + r1.xyz;
  r0.x = r0.y * 0.362969995 + r0.x;
  r0.x = 1.1920929e-007 + r0.x;
  o0.xyz = r1.xyz / r0.xxx;
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Sat Jan 08 21:42:14 2022
//
//
// Buffer Definitions:
//
// cbuffer cbLightShaftFilter
// {
//
//   float filterEdgeSharpness;         // Offset:    0 Size:     4
//   uint filterScale;                  // Offset:    4 Size:     4
//   float _LightShaftFilter_Reserved0; // Offset:    8 Size:     4 [unused]
//   float _LightShaftFilter_Reserved1; // Offset:   12 Size:     4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// tLightShaft                       texture  float4          2d    0        1
// cbLightShaftFilter                cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   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[1], immediateIndexed
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 5
ftoi r0.xy, v0.xyxx
round_z r1.x, v0.y
ftoi r0.z, r1.x
mov r0.w, l(0)
ld_indexable(texture2d)(float,float,float,float) r1.xyzw, r0.xzww, t0.xyzw
ge r0.z, l(0.000000), r1.w
if_nz r0.z
  mov o0.xyzw, l(0,0,0,0)
  ret
endif
imad r2.xyzw, l(0, -3, 0, -4), cb0[0].yyyy, r0.xyxy
mov r3.xy, r2.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t0.xyzw
add r0.z, -r1.w, r3.w
mad r0.z, -cb0[0].x, |r0.z|, l(1.000000)
max r0.z, r0.z, l(0.000000)
mul r0.w, r0.z, l(0.362970)
mul r3.xyz, r0.wwww, r3.xyzx
mad r1.xyz, r1.xyzx, l(0.153170, 0.153170, 0.153170, 0.000000), r3.xyzx
mad r0.z, r0.z, l(0.362970), l(0.153170)
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r2.xyzw, t0.xyzw
add r0.w, -r1.w, r2.w
mad r0.w, -cb0[0].x, |r0.w|, l(1.000000)
max r0.w, r0.w, l(0.000000)
mul r2.w, r0.w, l(0.392902017)
mad r1.xyz, r2.xyzx, r2.wwww, r1.xyzx
mad r0.z, r0.w, l(0.392902017), r0.z
imad r2.xyzw, l(0, -1, 0, -2), cb0[0].yyyy, r0.xyxy
mov r3.xy, r2.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t0.xyzw
add r0.w, -r1.w, r3.w
mad r0.w, -cb0[0].x, |r0.w|, l(1.000000)
max r0.w, r0.w, l(0.000000)
mul r3.w, r0.w, l(0.422649026)
mad r1.xyz, r3.xyzx, r3.wwww, r1.xyzx
mad r0.z, r0.w, l(0.422649026), r0.z
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r2.xyzw, t0.xyzw
add r0.w, -r1.w, r2.w
mad r0.w, -cb0[0].x, |r0.w|, l(1.000000)
max r0.w, r0.w, l(0.000000)
mul r2.w, r0.w, l(0.444893)
mad r1.xyz, r2.xyzx, r2.wwww, r1.xyzx
mad r0.z, r0.w, l(0.444893), r0.z
imad r2.xyzw, l(0, 3, 0, 1), cb0[0].yyyy, r0.xyxy
mov r3.xy, r2.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t0.xyzw
add r0.w, -r1.w, r3.w
mad r0.w, -cb0[0].x, |r0.w|, l(1.000000)
max r0.w, r0.w, l(0.000000)
mul r3.w, r0.w, l(0.444893)
mad r1.xyz, r3.xyzx, r3.wwww, r1.xyzx
mad r0.z, r0.w, l(0.444893), r0.z
ishl r3.xyzw, cb0[0].yyyy, l(1, 1, 2, 2)
imad r3.xyzw, l(0, 1, 0, 1), r3.zwxy, r0.xyxy
mov r4.xy, r3.zwzz
mov r4.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r4.xyzw, r4.xyzw, t0.xyzw
add r0.x, -r1.w, r4.w
mad r0.x, -cb0[0].x, |r0.x|, l(1.000000)
max r0.x, r0.x, l(0.000000)
mul r0.y, r0.x, l(0.422649026)
mad r1.xyz, r4.xyzx, r0.yyyy, r1.xyzx
mad r0.x, r0.x, l(0.422649026), r0.z
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r2.xyzw, t0.xyzw
add r0.y, -r1.w, r2.w
mad r0.y, -cb0[0].x, |r0.y|, l(1.000000)
max r0.y, r0.y, l(0.000000)
mul r0.z, r0.y, l(0.392902017)
mad r1.xyz, r2.xyzx, r0.zzzz, r1.xyzx
mad r0.x, r0.y, l(0.392902017), r0.x
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r3.xyzw, t0.xyzw
add r0.y, -r1.w, r2.w
mad r0.y, -cb0[0].x, |r0.y|, l(1.000000)
max r0.y, r0.y, l(0.000000)
mul r0.z, r0.y, l(0.362970)
mad r1.xyz, r2.xyzx, r0.zzzz, r1.xyzx
mad r0.x, r0.y, l(0.362970), r0.x
add r0.x, r0.x, l(1.192092896E-007)
div o0.xyz, r1.xyzx, r0.xxxx
mov o0.w, l(1.000000)
ret
// Approximately 88 instruction slots used

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