#include <metal_stdlib>
#pragma clang diagnostic ignored "-Wparentheses-equality"
using namespace metal;
constant float2 _xlat_mtl_const1[12] = {float2(-0.326212, -0.40581), float2(-0.840144, -0.07358), float2(-0.695914, 0.457137), float2(-0.203345, 0.620716), float2(0.96234, -0.194983), float2(0.473434, -0.480026), float2(0.519456, 0.767022), float2(0.185461, -0.893124), float2(0.507431, 0.064425), float2(0.89642, 0.412458), float2(-0.32194, -0.932615), float2(-0.791559, -0.59771)};
struct xlatMtlShaderInput {
  float2 xlv_TEXCOORD0;
};
struct xlatMtlShaderOutput {
  half4 _fragData [[color(0)]];
};
struct xlatMtlShaderUniform {
  float4 _ZBufferParams;
  float4 _MainTex_TexelSize;
  float _Jitter;
  float _MaxVelocity;
  float _SoftZDistance;
};
fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
  ,   texture2d<half> _MainTex [[texture(0)]], sampler _mtlsmp__MainTex [[sampler(0)]]
  ,   texture2d<float> _CameraDepthTexture [[texture(1)]], sampler _mtlsmp__CameraDepthTexture [[sampler(1)]]
  ,   texture2d<half> _VelTex [[texture(2)]], sampler _mtlsmp__VelTex [[sampler(2)]]
  ,   texture2d<half> _NeighbourMaxTex [[texture(3)]], sampler _mtlsmp__NeighbourMaxTex [[sampler(3)]]
  ,   texture2d<half> _NoiseTex [[texture(4)]], sampler _mtlsmp__NoiseTex [[sampler(4)]])
{
  xlatMtlShaderOutput _mtl_o;
  float2 tmpvar_1;
  tmpvar_1 = _mtl_i.xlv_TEXCOORD0;
  float4 jitteredDir_3;
  float4 sum_4;
  float weight_5;
  float zx_6;
  float2 vx_7;
  float2 x_8;
  float2 xf_9;
  xf_9 = _mtl_i.xlv_TEXCOORD0;
  x_8 = _mtl_i.xlv_TEXCOORD0;
  if ((_mtl_u._MainTex_TexelSize.y < 0.0)) {
    xf_9.y = (1.0 - _mtl_i.xlv_TEXCOORD0.y);
  };
  half4 tmpvar_10;
  tmpvar_10 = _NeighbourMaxTex.sample(_mtlsmp__NeighbourMaxTex, (float2)(xf_9), level(0.0));
  float2 tmpvar_11;
  tmpvar_11 = float2(tmpvar_10.xy);
  half4 tmpvar_12;
  tmpvar_12 = _MainTex.sample(_mtlsmp__MainTex, (float2)(_mtl_i.xlv_TEXCOORD0), level(0.0));
  float4 tmpvar_13;
  tmpvar_13 = float4(tmpvar_12);
  half4 tmpvar_14;
  tmpvar_14 = _VelTex.sample(_mtlsmp__VelTex, (float2)(xf_9), level(0.0));
  float2 tmpvar_15;
  tmpvar_15 = float2(tmpvar_14.xy);
  vx_7 = tmpvar_15;
  float4 tmpvar_16;
  tmpvar_16.zw = float2(0.0, 0.0);
  tmpvar_16.xy = _mtl_i.xlv_TEXCOORD0;
  float4 coord_17;
  coord_17 = (tmpvar_16 * 11.0);
  half4 tmpvar_18;
  tmpvar_18 = _NoiseTex.sample(_mtlsmp__NoiseTex, (float2)(coord_17.xy), level(coord_17.w));
  float4 tmpvar_19;
  tmpvar_19 = float4(((tmpvar_18 * (half)2.0) - (half)1.0));
  zx_6 = -((1.0/((
    (_mtl_u._ZBufferParams.x * _CameraDepthTexture.sample(_mtlsmp__CameraDepthTexture, (float2)(_mtl_i.xlv_TEXCOORD0), level(0.0)).x)
   + _mtl_u._ZBufferParams.y))));
  weight_5 = 1.0;
  sum_4 = tmpvar_13;
  float4 tmpvar_20;
  tmpvar_20 = (tmpvar_11.xyxy + (tmpvar_19 * (_mtl_u._MainTex_TexelSize.xyxy * _mtl_u._Jitter)).xyyz);
  jitteredDir_3 = ((max (
    abs(tmpvar_20.xyxy)
  , 
    ((_mtl_u._MainTex_TexelSize.xyxy * _mtl_u._MaxVelocity) * 0.15)
  ) * sign(tmpvar_20.xyxy)) * float4(1.0, 1.0, -1.0, -1.0));
  for (int l_2 = 0; l_2 < 12; l_2++) {
    float zy_21;
    float4 yf_22;
    float4 tmpvar_23;
    tmpvar_23 = (tmpvar_1.xyxy + ((jitteredDir_3.xyxy * _xlat_mtl_const1[l_2].xyxy) * float4(1.0, 1.0, -1.0, -1.0)));
    yf_22 = tmpvar_23;
    if ((_mtl_u._MainTex_TexelSize.y < 0.0)) {
      yf_22.yw = (1.0 - tmpvar_23.yw);
    };
    half4 tmpvar_24;
    tmpvar_24 = _VelTex.sample(_mtlsmp__VelTex, (float2)(yf_22.xy), level(0.0));
    float2 tmpvar_25;
    tmpvar_25 = float2(tmpvar_24.xy);
    zy_21 = -((1.0/((
      (_mtl_u._ZBufferParams.x * _CameraDepthTexture.sample(_mtlsmp__CameraDepthTexture, (float2)(tmpvar_23.xy), level(0.0)).x)
     + _mtl_u._ZBufferParams.y))));
    float2 x_26;
    x_26 = (x_8 - tmpvar_23.xy);
    float2 x_27;
    x_27 = (tmpvar_23.xy - x_8);
    float tmpvar_28;
    tmpvar_28 = sqrt(dot (tmpvar_25, tmpvar_25));
    float2 x_29;
    x_29 = (tmpvar_23.xy - x_8);
    float edge0_30;
    edge0_30 = (0.95 * tmpvar_28);
    float tmpvar_31;
    tmpvar_31 = clamp (((
      sqrt(dot (x_29, x_29))
     - edge0_30) / (
      (1.05 * tmpvar_28)
     - edge0_30)), 0.0, 1.0);
    float tmpvar_32;
    tmpvar_32 = sqrt(dot (vx_7, vx_7));
    float2 x_33;
    x_33 = (x_8 - tmpvar_23.xy);
    float edge0_34;
    edge0_34 = (0.95 * tmpvar_32);
    float tmpvar_35;
    tmpvar_35 = clamp (((
      sqrt(dot (x_33, x_33))
     - edge0_34) / (
      (1.05 * tmpvar_32)
     - edge0_34)), 0.0, 1.0);
    float tmpvar_36;
    tmpvar_36 = (((
      clamp ((1.0 - ((zy_21 - zx_6) / _mtl_u._SoftZDistance)), 0.0, 1.0)
     * 
      clamp ((1.0 - (sqrt(
        dot (x_26, x_26)
      ) / sqrt(
        dot (vx_7, vx_7)
      ))), 0.0, 1.0)
    ) + (
      clamp ((1.0 - ((zx_6 - zy_21) / _mtl_u._SoftZDistance)), 0.0, 1.0)
     * 
      clamp ((1.0 - (sqrt(
        dot (x_27, x_27)
      ) / sqrt(
        dot (tmpvar_25, tmpvar_25)
      ))), 0.0, 1.0)
    )) + ((
      (1.0 - (tmpvar_31 * (tmpvar_31 * (3.0 - 
        (2.0 * tmpvar_31)
      ))))
     * 
      (1.0 - (tmpvar_35 * (tmpvar_35 * (3.0 - 
        (2.0 * tmpvar_35)
      ))))
    ) * 2.0));
    half4 tmpvar_37;
    tmpvar_37 = _MainTex.sample(_mtlsmp__MainTex, (float2)(tmpvar_23.xy), level(0.0));
    float4 tmpvar_38;
    tmpvar_38 = float4(tmpvar_37);
    sum_4 = (sum_4 + (tmpvar_38 * tmpvar_36));
    weight_5 = (weight_5 + tmpvar_36);
  };
  float4 tmpvar_39;
  tmpvar_39 = (sum_4 / weight_5);
  _mtl_o._fragData = half4(tmpvar_39);
  return _mtl_o;
}


// stats: 99 alu 8 tex 4 flow
// inputs: 1
//  #0: xlv_TEXCOORD0 (high float) 2x1 [-1]
// uniforms: 5 (total size: 44)
//  #0: _ZBufferParams (high float) 4x1 [-1] loc 0
//  #1: _MainTex_TexelSize (high float) 4x1 [-1] loc 16
//  #2: _Jitter (high float) 1x1 [-1] loc 32
//  #3: _MaxVelocity (high float) 1x1 [-1] loc 36
//  #4: _SoftZDistance (high float) 1x1 [-1] loc 40
// textures: 5
//  #0: _MainTex (low 2d) 0x0 [-1] loc 0
//  #1: _CameraDepthTexture (high 2d) 0x0 [-1] loc 1
//  #2: _VelTex (low 2d) 0x0 [-1] loc 2
//  #3: _NeighbourMaxTex (low 2d) 0x0 [-1] loc 3
//  #4: _NoiseTex (low 2d) 0x0 [-1] loc 4
