uniform vec2 iResolution;
uniform float iTime;

uniform sampler2D gm_BaseTexture;

uniform bool gm_PS_FogEnabled;
uniform vec4 gm_FogColour;
uniform bool gm_AlphaTestEnabled;
uniform float gm_AlphaRefValue;

void DoAlphaTest(vec4 SrcColour)
{
	if (gm_AlphaTestEnabled)
	{
		if (SrcColour.a <= gm_AlphaRefValue)
		{
			discard;
		}
	}
}

void DoFog(inout vec4 SrcColour, float fogval)
{
	if (gm_PS_FogEnabled)
	{
		SrcColour = mix(SrcColour, gm_FogColour, clamp(fogval, 0.0, 1.0)); 
	}
}

#define _YY_GLSL_ 1
//https://iarri.github.io/Shadertoy2GM/

varying vec2 fragCoord; 
#define PI      3.14159265358979
#define PI_HALF (PI / 2.0)

void main()
{
    vec2 fragCoord = openfl_TextureCoordv * iResolution;

    vec2 uv = (fragCoord - iResolution.xy * 0.5) / min(iResolution.x, iResolution.y);

    float scale = 5.0 + sin(iTime) * 0.25;
    uv.y -= fract(iTime * 0.2) / scale;
    
    vec2  uvGrid = floor(uv * scale);
    float uvYOffset = mod(uvGrid.x, 2.0) <= 0.0 ? 0.0 : 0.5;
    vec2  uvLocal = fract(uv * scale + vec2(0.0, uvYOffset)) - vec2(0.0, 0.5);
    float dist = 1e+5;
    
    // below grids (both sides only)
    for(float x=-1.0; x<2.0; x+=2.0)
        dist = min(dist, distance(vec2(x, -1), uvLocal));
    
    // self grid
    const float WAVE_DISTANCE = 1.0;
	if(WAVE_DISTANCE < dist)
    	dist = min(dist, distance(vec2(0, -0.5), uvLocal));

    // center grids (both sides only)
	if(WAVE_DISTANCE < dist)
  		for(float x=-1.0; x<2.0; x+=2.0)
        	dist = min(dist, distance(vec2(x, 0), uvLocal));

    const float STRIPES = 8.0;
    float stripeOffset = (-cos(fract(iTime * 0.5) * PI) * 0.5 + 0.5) * (4.0 * PI);
    gl_FragColor.rgb =
        (0.0 < sin(dist * STRIPES * PI - stripeOffset)) ?
    	vec3(1.0, 0.8, 0.4) :
    	vec3(1.0, 0.7, 0.2);

    float uvYGradient = fragCoord.y / iResolution.y;
    gl_FragColor.rgb *= uvYGradient * 0.4 + 0.6;
    gl_FragColor.a = 1.0;
}