/* ========================================================================
   $File: $
   $Date: $
   $Revision: $
   $Creator: Felipe Oliveira $
   $Notice: (C) Copyright 2020 by Felpz. All Rights Reserved. $
   ======================================================================== */

#version 450 core

uniform sampler2D SplatValues;
in vec2 texCoords;
out float outThick;

vec4 filterOne(){
    vec4 sum = vec4(0.0);
    float wsum = 0.0;
    float filterRadius = 30.0;
    ivec2 SplatSize = textureSize(SplatValues, 0);
    vec2 PixelSize = vec2(1.0/SplatSize.x, 1.0/SplatSize.y);
    for(float x = -filterRadius; x <= filterRadius; x += 3.0){
        vec2 Position = texCoords + vec2(x, 0.0) * PixelSize;
        vec4 Sample = texture(SplatValues, Position);
        float r = distance(Position, texCoords);
        float w = exp(-r*r/2.0);
        sum += Sample * w;
        wsum += w;
    }
    
    if(wsum > 0.0){
        sum = sum / wsum;
    }
    
    return sum;
}

void main(){
    vec4 sum = vec4(0.0);
#if 1
    sum = filterOne();
#else
    sum = texture(SplatValues, texCoords);
#endif
    outThick = sum.r;
}
