// ---- Created with 3Dmigoto v1.3.16 on Thu Jan 06 16:53:05 2022

cbuffer SceneInfo : register(b0)
{
  row_major float4x4 viewProjMat : packoffset(c0);
  row_major float3x4 transposeViewMat : packoffset(c4);
  row_major float3x4 transposeViewInvMat : packoffset(c7);
  float4 projElement[2] : packoffset(c10);
  float4 projInvElements[2] : packoffset(c12);
  row_major float4x4 viewProjInvMat : packoffset(c14);
  row_major float4x4 prevViewProjMat : packoffset(c18);
  float3 ZToLinear : packoffset(c22);
  float subdivisionLevel : packoffset(c22.w);
  float2 screenSize : packoffset(c23);
  float2 screenInverseSize : packoffset(c23.z);
  float2 cullingHelper : packoffset(c24);
  float cameraNearPlane : packoffset(c24.z);
  float cameraFarPlane : packoffset(c24.w);
  float4 viewFrustum[6] : packoffset(c25);
  float4 clipplane : packoffset(c31);
}

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

SamplerState PointClamp_s : register(s0);
Texture2D<float> ReadonlyDepth : register(t0);
Texture2D<float4> tLightShaft : register(t1);


// 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;
  uint4 bitmask, uiDest;
  float4 fDest;
  
  float4 stereo = StereoParams.Load(0);
  
  //v0.x-=stereo.x*(1-stereo.y*0)*screenSize.x*0.5;
  
  r0.yz = (int2)v0.xy;
  r1.x = trunc(v0.x);
  r0.x = (int)r1.x;
  r0.w = 0;
  r2.xyzw = tLightShaft.Load(r0.xzw).xyzw;
  r0.x = cmp(0 >= r2.w);
  if (r0.x != 0) {
    o0.xyzw = float4(0,0,0,0);
    return;
  }
  r1.y = trunc(v0.y);
  r0.xw = screenInverseSize.xy * r1.xy;
  r1.x = ReadonlyDepth.SampleLevel(PointClamp_s, r0.xw, 0).x;
  r0.xw = r0.xw * float2(2,-2) + float2(-1,1);
  r3.xy = projInvElements[0].xy * r0.xw + projInvElements[1].xy;
  r3.zw = projInvElements[0].zw * r1.xx + projInvElements[1].zw;
  r1.xyz = r3.xyz / r3.www;
  r0.x = dot(r1.xyz, r1.xyz);
  r0.x = sqrt(r0.x);
  r0.w = 1 / cameraFarPlane;
  r0.x = saturate(r0.x * r0.w);
  r1.xyzw = mad(int4(-3,0,-4,0), filterScale, (int4)r0.yzyz);
  r3.xy = r1.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.w = r3.w + -r0.x;
  r0.w = -filterEdgeSharpness * abs(r0.w) + 1;
  r0.w = max(0, r0.w);
  r2.w = 0.362969995 * r0.w;
  r3.xyz = r3.xyz * r2.www;
  r2.xyz = r2.xyz * float3(0.153170004,0.153170004,0.153170004) + r3.xyz;
  r0.w = r0.w * 0.362969995 + 0.153170004;
  r1.zw = float2(0,0);
  r1.xyzw = tLightShaft.Load(r1.xyz).xyzw;
  r1.w = r1.w + -r0.x;
  r1.w = -filterEdgeSharpness * abs(r1.w) + 1;
  r1.w = max(0, r1.w);
  r2.w = 0.392902017 * r1.w;
  r1.xyz = r1.xyz * r2.www + r2.xyz;
  r0.w = r1.w * 0.392902017 + r0.w;
  r2.xyzw = mad(int4(-1,0,-2,0), filterScale, (int4)r0.yzyz);
  r3.xy = r2.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r1.w = r3.w + -r0.x;
  r1.w = -filterEdgeSharpness * abs(r1.w) + 1;
  r1.w = max(0, r1.w);
  r3.w = 0.422649026 * r1.w;
  r1.xyz = r3.xyz * r3.www + r1.xyz;
  r0.w = r1.w * 0.422649026 + r0.w;
  r2.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r2.xyz).xyzw;
  r1.w = r2.w + -r0.x;
  r1.w = -filterEdgeSharpness * abs(r1.w) + 1;
  r1.w = max(0, r1.w);
  r2.w = 0.444893003 * r1.w;
  r1.xyz = r2.xyz * r2.www + r1.xyz;
  r0.w = r1.w * 0.444893003 + r0.w;
  r2.xyzw = mad(int4(3,0,1,0), filterScale, (int4)r0.yzyz);
  r3.xy = r2.zw;
  r3.zw = float2(0,0);
  r3.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r1.w = r3.w + -r0.x;
  r1.w = -filterEdgeSharpness * abs(r1.w) + 1;
  r1.w = max(0, r1.w);
  r3.w = 0.444893003 * r1.w;
  r1.xyz = r3.xyz * r3.www + r1.xyz;
  r0.w = r1.w * 0.444893003 + r0.w;
  r3.xyzw = filterScale << int4(1,1,2,2);
  r3.xyzw = mad(int4(1,0,1,0), (int4)r3.zwxy, (int4)r0.yzyz);
  r4.xy = r3.zw;
  r4.zw = float2(0,0);
  r4.xyzw = tLightShaft.Load(r4.xyz).xyzw;
  r0.y = r4.w + -r0.x;
  r0.y = -filterEdgeSharpness * abs(r0.y) + 1;
  r0.y = max(0, r0.y);
  r0.z = 0.422649026 * r0.y;
  r1.xyz = r4.xyz * r0.zzz + r1.xyz;
  r0.y = r0.y * 0.422649026 + r0.w;
  r2.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r2.xyz).xyzw;
  r0.z = r2.w + -r0.x;
  r0.z = -filterEdgeSharpness * abs(r0.z) + 1;
  r0.z = max(0, r0.z);
  r0.w = 0.392902017 * r0.z;
  r1.xyz = r2.xyz * r0.www + r1.xyz;
  r0.y = r0.z * 0.392902017 + r0.y;
  r3.zw = float2(0,0);
  r2.xyzw = tLightShaft.Load(r3.xyz).xyzw;
  r0.z = r2.w + -r0.x;
  r0.z = -filterEdgeSharpness * abs(r0.z) + 1;
  r0.z = max(0, r0.z);
  r0.w = 0.362969995 * r0.z;
  r1.xyz = r2.xyz * r0.www + r1.xyz;
  r0.y = r0.z * 0.362969995 + r0.y;
  r0.y = 1.1920929e-007 + r0.y;
  o0.xyz = r1.xyz / r0.yyy;
  o0.w = r0.x;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//   using 3Dmigoto v1.3.16 on Thu Jan 06 16:53:05 2022
//
//
// Buffer Definitions:
//
// cbuffer SceneInfo
// {
//
//   row_major float4x4 viewProjMat;    // Offset:    0 Size:    64 [unused]
//   row_major float3x4 transposeViewMat;// Offset:   64 Size:    48 [unused]
//   row_major float3x4 transposeViewInvMat;// Offset:  112 Size:    48 [unused]
//   float4 projElement[2];             // Offset:  160 Size:    32 [unused]
//   float4 projInvElements[2];         // Offset:  192 Size:    32
//   row_major float4x4 viewProjInvMat; // Offset:  224 Size:    64 [unused]
//   row_major float4x4 prevViewProjMat;// Offset:  288 Size:    64 [unused]
//   float3 ZToLinear;                  // Offset:  352 Size:    12 [unused]
//   float subdivisionLevel;            // Offset:  364 Size:     4 [unused]
//   float2 screenSize;                 // Offset:  368 Size:     8 [unused]
//   float2 screenInverseSize;          // Offset:  376 Size:     8
//   float2 cullingHelper;              // Offset:  384 Size:     8 [unused]
//   float cameraNearPlane;             // Offset:  392 Size:     4 [unused]
//   float cameraFarPlane;              // Offset:  396 Size:     4
//   float4 viewFrustum[6];             // Offset:  400 Size:    96 [unused]
//   float4 clipplane;                  // Offset:  496 Size:    16 [unused]
//
// }
//
// 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
// ------------------------------ ---------- ------- ----------- ---- --------
// PointClamp                        sampler      NA          NA    0        1
// ReadonlyDepth                     texture   float          2d    0        1
// tLightShaft                       texture  float4          2d    1        1
// SceneInfo                         cbuffer      NA          NA    0        1
// cbLightShaftFilter                cbuffer      NA          NA    1        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[25], immediateIndexed
dcl_constantbuffer cb1[1], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps_siv linear noperspective v0.xy, position
dcl_output o0.xyzw
dcl_temps 5
ftoi r0.yz, v0.xxyx
round_z r1.x, v0.x
ftoi r0.x, r1.x
mov r0.w, l(0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r0.xzww, t1.xyzw
ge r0.x, l(0.000000), r2.w
if_nz r0.x
  mov o0.xyzw, l(0,0,0,0)
  ret
endif
round_z r1.y, v0.y
mul r0.xw, r1.xxxy, cb0[23].zzzw
sample_l_indexable(texture2d)(float,float,float,float) r1.x, r0.xwxx, t0.xyzw, s0, l(0.000000)
mad r0.xw, r0.xxxw, l(2.000000, 0.000000, 0.000000, -2.000000), l(-1.000000, 0.000000, 0.000000, 1.000000)
mad r3.xy, cb0[12].xyxx, r0.xwxx, cb0[13].xyxx
mad r3.zw, cb0[12].zzzw, r1.xxxx, cb0[13].zzzw
div r1.xyz, r3.xyzx, r3.wwww
dp3 r0.x, r1.xyzx, r1.xyzx
sqrt r0.x, r0.x
div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), cb0[24].w
mul_sat r0.x, r0.w, r0.x
imad r1.xyzw, l(-3, 0, -4, 0), cb1[0].yyyy, r0.yzyz
mov r3.xy, r1.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t1.xyzw
add r0.w, -r0.x, r3.w
mad r0.w, -cb1[0].x, |r0.w|, l(1.000000)
max r0.w, r0.w, l(0.000000)
mul r2.w, r0.w, l(0.362970)
mul r3.xyz, r2.wwww, r3.xyzx
mad r2.xyz, r2.xyzx, l(0.153170, 0.153170, 0.153170, 0.000000), r3.xyzx
mad r0.w, r0.w, l(0.362970), l(0.153170)
mov r1.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r1.xyzw, r1.xyzw, t1.xyzw
add r1.w, -r0.x, r1.w
mad r1.w, -cb1[0].x, |r1.w|, l(1.000000)
max r1.w, r1.w, l(0.000000)
mul r2.w, r1.w, l(0.392902017)
mad r1.xyz, r1.xyzx, r2.wwww, r2.xyzx
mad r0.w, r1.w, l(0.392902017), r0.w
imad r2.xyzw, l(-1, 0, -2, 0), cb1[0].yyyy, r0.yzyz
mov r3.xy, r2.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t1.xyzw
add r1.w, -r0.x, r3.w
mad r1.w, -cb1[0].x, |r1.w|, l(1.000000)
max r1.w, r1.w, l(0.000000)
mul r3.w, r1.w, l(0.422649026)
mad r1.xyz, r3.xyzx, r3.wwww, r1.xyzx
mad r0.w, r1.w, l(0.422649026), r0.w
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r2.xyzw, t1.xyzw
add r1.w, -r0.x, r2.w
mad r1.w, -cb1[0].x, |r1.w|, l(1.000000)
max r1.w, r1.w, l(0.000000)
mul r2.w, r1.w, l(0.444893)
mad r1.xyz, r2.xyzx, r2.wwww, r1.xyzx
mad r0.w, r1.w, l(0.444893), r0.w
imad r2.xyzw, l(3, 0, 1, 0), cb1[0].yyyy, r0.yzyz
mov r3.xy, r2.zwzz
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r3.xyzw, r3.xyzw, t1.xyzw
add r1.w, -r0.x, r3.w
mad r1.w, -cb1[0].x, |r1.w|, l(1.000000)
max r1.w, r1.w, l(0.000000)
mul r3.w, r1.w, l(0.444893)
mad r1.xyz, r3.xyzx, r3.wwww, r1.xyzx
mad r0.w, r1.w, l(0.444893), r0.w
ishl r3.xyzw, cb1[0].yyyy, l(1, 1, 2, 2)
imad r3.xyzw, l(1, 0, 1, 0), r3.zwxy, r0.yzyz
mov r4.xy, r3.zwzz
mov r4.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r4.xyzw, r4.xyzw, t1.xyzw
add r0.y, -r0.x, r4.w
mad r0.y, -cb1[0].x, |r0.y|, l(1.000000)
max r0.y, r0.y, l(0.000000)
mul r0.z, r0.y, l(0.422649026)
mad r1.xyz, r4.xyzx, r0.zzzz, r1.xyzx
mad r0.y, r0.y, l(0.422649026), r0.w
mov r2.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r2.xyzw, t1.xyzw
add r0.z, -r0.x, r2.w
mad r0.z, -cb1[0].x, |r0.z|, l(1.000000)
max r0.z, r0.z, l(0.000000)
mul r0.w, r0.z, l(0.392902017)
mad r1.xyz, r2.xyzx, r0.wwww, r1.xyzx
mad r0.y, r0.z, l(0.392902017), r0.y
mov r3.zw, l(0,0,0,0)
ld_indexable(texture2d)(float,float,float,float) r2.xyzw, r3.xyzw, t1.xyzw
add r0.z, -r0.x, r2.w
mad r0.z, -cb1[0].x, |r0.z|, l(1.000000)
max r0.z, r0.z, l(0.000000)
mul r0.w, r0.z, l(0.362970)
mad r1.xyz, r2.xyzx, r0.wwww, r1.xyzx
mad r0.y, r0.z, l(0.362970), r0.y
add r0.y, r0.y, l(1.192092896E-007)
div o0.xyz, r1.xyzx, r0.yyyy
mov o0.w, r0.x
ret
// Approximately 99 instruction slots used

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