<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<glsl_hacker>
	
  <window name="win3d01" title="MadShaders - Shadertoy/queasy checkerboard" 
          width="800" height="400" 
          gl_version_major="2" gl_version_minor="1" />
          
          
<gpu_program name="shadertoy_prog" >
	<raw_data_vs><![CDATA[	 
void main()
{	
	gl_TexCoord[0] = gl_MultiTexCoord0;
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;		
}
  ]]></raw_data_vs>
  
	<raw_data_ps><![CDATA[	 

  
uniform vec3      iResolution;     // viewport resolution (in pixels)
uniform float     iGlobalTime;     // shader playback time (in seconds)
uniform vec4      iMouse;          // mouse pixel coords. xy: current (if MLB down), zw: click
//uniform sampler2D iChannel0;

  
  
// https://www.shadertoy.com/view/ldBXz3

#define time iGlobalTime*0.5

float grid(vec2 p) {
  vec2 orient = normalize(vec2(1.0,3.0));
  vec2 perp = vec2(orient.y, -orient.x);
  float g = mod(floor(1. * dot(p, orient)) + floor(1. * dot(p, perp)), 2.);
  return g;
}

#define samp 30.
void main(void)
{
  vec2 p = gl_FragCoord.xy / 50. + vec2(-time, time);
  vec2 q = (gl_FragCoord.xy - (iResolution.xy / 2.)) / iResolution.x / 1.5 ;
  vec4 c = vec4(grid(p));
  if (q.x + 0.1 * q.y > 100.) {
    gl_FragColor = c;
  }
  else {
    vec4 cc = vec4(0.0);
    float total = 0.0;
    
    float radius = length(q) * 100.;
    for (float t = -samp; t <= samp; t++) {
      float percent = t / samp;
      float weight = 1.0 - abs(percent);
	  float u = t / 100.;
      vec2 dir = vec2(fract(sin(537.3 * (u + 0.5)) ) , fract(sin(523.7 * (u + 0.25)) ));
      dir = normalize(dir) * 0.01;
      float skew = percent * radius;
      vec4 sample = vec4(
          grid(vec2(0.03,0.) + p +  dir * skew),
          grid(radius * vec2(0.005,0.00) + p +  dir * skew),
          grid(radius * vec2(0.007,0.00) + p +  dir * skew),
          1.0);
      cc += sample * weight;
      total += weight;
    }


    gl_FragColor = cc / total - length(q ) * vec4(1.,1.,1.,1.) * 1.5;
  }
}
]]></raw_data_ps>

</gpu_program>

 
	<script name="init_scene" run_mode="INIT" >
		<raw_data><![CDATA[	

app_dir = gh_utils.get_scripting_libs_dir() 		
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)
moon3d.graphics.vsync(0)

bmfont = moon3d.font.create("trebuchet_20px.fnt", "data/")
bmfont_texture = moon3d.font.getTexture(bmfont)
moon3d.madshaders.setBmFontData(bmfont, bmfont_texture)

winW, winH = moon3d.window.getSize()

quad = moon3d.graphics.newQuad(winW, winH)
shadertoy_prog = moon3d.graphics.getGpuProgram("shadertoy_prog")


moon3d.madshaders.resetBenchmarkData()

		]]></raw_data>
	</script> 

  
	<script name="update_scene" run_mode="FRAME" >
		<raw_data><![CDATA[	

moon3d.startFrame(0, 0, 0, 1)

local global_time = moon3d.getTime()

moon3d.madshaders.updateBenchmarkData(global_time)

moon3d.camera.bindOrtho()

moon3d.graphics.bindGpuProgram(shadertoy_prog)
moon3d.madshaders.updateShadertoyCommonParams(shadertoy_prog, global_time)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("Shadertoy/queasy checkerboard", global_time, 1, 1, 1, 1)

moon3d.endFrame()

		]]></raw_data>
	</script> 
	

	<script name="resize_scene" run_mode="SIZE" >
		<raw_data><![CDATA[	

moon3d.window.resize()
winW, winH = moon3d.window.getSize()
moon3d.graphics.resizeQuad(quad, winW, winH)

		]]></raw_data>
	</script> 
  
</glsl_hacker>
