#include <metal_stdlib>
#pragma clang diagnostic ignored "-Wparentheses-equality"
using namespace metal;
constant float3 _xlat_mtl_const1[8] = {float3(0.0130572, 0.587232, -0.119337), float3(0.323078, 0.0220727, -0.418873), float3(-0.310725, -0.191367, 0.0561369), float3(-0.479646, 0.0939877, -0.580265), float3(0.139999, -0.33577, 0.559679), float3(-0.248458, 0.255532, 0.348944), float3(0.18719, -0.702764, -0.231748), float3(0.884915, 0.284208, 0.368524)};
struct xlatMtlShaderInput {
  float2 xlv_TEXCOORD0;
  float2 xlv_TEXCOORD1;
};
struct xlatMtlShaderOutput {
  half4 _glesFragData_0 [[color(0)]];
};
struct xlatMtlShaderUniform {
  float4 _ProjectionParams;
  float4 _Params;
};
fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
  ,   texture2d<float> _CameraDepthNormalsTexture [[texture(0)]], sampler _mtlsmp__CameraDepthNormalsTexture [[sampler(0)]]
  ,   texture2d<half> _RandomTexture [[texture(1)]], sampler _mtlsmp__RandomTexture [[sampler(1)]])
{
  xlatMtlShaderOutput _mtl_o;
  half tmpvar_1;
  float2 tmpvar_2;
  tmpvar_2 = _mtl_i.xlv_TEXCOORD0;
  float occ_4;
  float scale_5;
  float depth_6;
  float3 viewNorm_7;
  half3 randN_8;
  half3 tmpvar_9;
  tmpvar_9 = ((_RandomTexture.sample(_mtlsmp__RandomTexture, (float2)(_mtl_i.xlv_TEXCOORD1)).xyz * (half)2.0) - (half)1.0);
  randN_8 = tmpvar_9;
  float4 tmpvar_10;
  tmpvar_10 = _CameraDepthNormalsTexture.sample(_mtlsmp__CameraDepthNormalsTexture, (float2)(_mtl_i.xlv_TEXCOORD0));
  float3 n_11;
  float3 tmpvar_12;
  tmpvar_12 = ((tmpvar_10.xyz * float3(3.5554, 3.5554, 0.0)) + float3(-1.7777, -1.7777, 1.0));
  float tmpvar_13;
  tmpvar_13 = (2.0 / dot (tmpvar_12, tmpvar_12));
  n_11.xy = (tmpvar_13 * tmpvar_12.xy);
  n_11.z = (tmpvar_13 - 1.0);
  viewNorm_7 = n_11;
  depth_6 = (dot (tmpvar_10.zw, float2(1.0, 0.00392157)) * _mtl_u._ProjectionParams.z);
  scale_5 = (_mtl_u._Params.x / depth_6);
  occ_4 = 0.0;
  for (int s_3 = 0; s_3 < 8; s_3++) {
    half3 randomDir_14;
    float3 tmpvar_15;
    float3 I_16;
    I_16 = _xlat_mtl_const1[s_3];
    tmpvar_15 = (I_16 - (float3)((half)2.0 * ((half3)(
      dot ((float3)randN_8, I_16)
     * (float3)randN_8))));
    randomDir_14 = half3(tmpvar_15);
    float tmpvar_17;
    tmpvar_17 = dot (viewNorm_7, (float3)randomDir_14);
    half tmpvar_18;
    if ((tmpvar_17 < 0.0)) {
      tmpvar_18 = half(1.0);
    } else {
      tmpvar_18 = half(-1.0);
    };
    randomDir_14 = (randomDir_14 * -(tmpvar_18));
    randomDir_14 = half3(((float3)randomDir_14 + (viewNorm_7 * 0.3)));
    float tmpvar_19;
    tmpvar_19 = clamp (((depth_6 - 
      ((float)randomDir_14.z * _mtl_u._Params.x)
    ) - (
      dot (_CameraDepthNormalsTexture.sample(_mtlsmp__CameraDepthNormalsTexture, (float2)((tmpvar_2 + ((float2)randomDir_14.xy * scale_5)))).zw, float2(1.0, 0.00392157))
     * _mtl_u._ProjectionParams.z)), 0.0, 1.0);
    if ((tmpvar_19 > _mtl_u._Params.y)) {
      occ_4 = (occ_4 + pow ((1.0 - tmpvar_19), _mtl_u._Params.z));
    };
  };
  occ_4 = (occ_4 / 8.0);
  tmpvar_1 = half((1.0 - occ_4));
  _mtl_o._glesFragData_0 = half4(tmpvar_1);
  return _mtl_o;
}


// stats: 41 alu 3 tex 4 flow
// inputs: 2
//  #0: xlv_TEXCOORD0 (high float) 2x1 [-1]
//  #1: xlv_TEXCOORD1 (high float) 2x1 [-1]
// uniforms: 2 (total size: 32)
//  #0: _ProjectionParams (high float) 4x1 [-1] loc 0
//  #1: _Params (high float) 4x1 [-1] loc 16
// textures: 2
//  #0: _CameraDepthNormalsTexture (high 2d) 0x0 [-1] loc 0
//  #1: _RandomTexture (low 2d) 0x0 [-1] loc 1
