/*
====================================================================================================

    Copyright (C) 2025 Pyvtron VX Shaders - Pyvton

    All Rights Reserved unless otherwise explicitly stated.

    Before You Do Something With Pyvtron VX Shaders, You MUST Read This:

    You Must Read The License: https://pyvton.pages.dev/minecraft-shaders/pyvtron-shaders-license
    And Read The Agreement: https://pyvton.pages.dev/minecraft-shaders/pyvtron-shaders-agreement

====================================================================================================
*/


#define c (1./256.)
#define e (1./8.)
#define f 8.

vec4 fxaa(sampler2D g, vec2 h, vec2 i){
    vec2 j=1./i;
    vec3 k=texture2D(g,h+(-j)).rgb,
         ne=texture2D(g,h+vec2(j.x,-j.y)).rgb,
         sw=texture2D(g,h+vec2(-j.x,j.y)).rgb,
         se=texture2D(g,h+j).rgb,
         m =texture2D(g,h).rgb;
    vec3 l=vec3(.299,.587,.114);
    float n=dot(k,l),lne=dot(ne,l),
          lsw=dot(sw,l),lse=dot(se,l),
          lm =dot(m, l),
          lmin=min(lm,min(min(n,lne),min(lsw,lse))),
          lmax=max(lm,max(max(n,lne),max(lsw,lse)));
    vec2 o=vec2(-(n+lne-lsw-lse),n+lsw-lne-lse);
    float p=max((n+lne+lsw+lse)*(.25*e),c),
          rc=1./(min(abs(o.x),abs(o.y))+p);
    o=clamp(o*rc,-f,f)*j;
    vec3 q=.5*(texture2D(g,h+o*(1./3.-.5)).rgb+
               texture2D(g,h+o*(2./3.-.5)).rgb),
         b=q*.5+.25*(texture2D(g,h+o*-.5).rgb+
                     texture2D(g,h+o*.5).rgb);
    return (dot(b,l)<lmin||dot(b,l)>lmax)?
           vec4(q,texture2D(g,h).a):vec4(b,texture2D(g,h).a);
}
