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

<glsl_hacker>
	
  <window name="win3d01" title="MadShaders - GLSLSandbox/#3281.0" 
          width="800" height="400" 
          gl_version_major="2" gl_version_minor="1" />
          
         
<gpu_program name="glslsandbox_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[	 

// http://glsl.heroku.com/e#3281.0

// from http://frank.bitsnbites.eu/safe.html

#ifdef GL_ES
precision mediump float;
#endif

uniform float time;
//uniform vec2 mouse;
uniform vec2 resolution;


float gc=fract(time*3.2/3.),
gb=fract(gc*2.),
PI=3.14159;
vec3 ff(vec2 p){
    vec2 q=vec2(sin(.08*p.x),4.*p.y);
    vec3 c=vec3(0);
    for(float i=0.;i<10.;i++)
      c+=(1.+sin(i*sin(time)+vec3(0.,1.3,2.2)))*.2/length(q-vec2(sin(i),12.*sin(.3*time+i)));
    return c+vec3(mix(mod(floor(p.x*.2)+floor(p.y*2.2),2.),.2,gc));
}
vec3 ft(vec3 o,vec3 d){
    d.y*=.65+.1*sin(.5*time);
    float D=1./(d.y*d.y+d.z*d.z),
          a=(o.y*d.y+o.z*d.z)*D,
          b=(o.y*o.y+o.z*o.z-36.)*D,
          t=-a-sqrt(a*a-b);
    o+=t*d;
    return ff(vec2(o.x,atan(o.y,o.z)))*(1.+.01*t);
}
void main(){
    vec2 p=(2.*gl_FragCoord.xy-resolution)/resolution.y,
         q=2.*gl_FragCoord.xy/resolution-1.;
    vec3 cp=vec3(-time*20.+1.,1.6*sin(time*1.2),2.+2.*cos(time*.3)),
         ct=cp+vec3(1.,.3*cos(time),-.2),
         cd=normalize(ct-cp),
         cr=normalize(cross(cd,vec3(.5*cos(.3*time),0.,1.))),
         cu=cross(cr,cd),
         rd=normalize(2.*cd+cr*p.x+cu*p.y),
         c=ft(cp,rd)*
           min(1.,1.8-dot(q,q))*(.9+.1*sin(3.*sin(gc)*gl_FragCoord.y));
    gl_FragColor=vec4(c,1);
}  ]]></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)
glslsandbox_prog = moon3d.graphics.getGpuProgram("glslsandbox_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.bindPersp()

moon3d.graphics.bindGpuProgram(glslsandbox_prog)
moon3d.madshaders.updateGLSLSandboxCommonParams(glslsandbox_prog, global_time)
moon3d.graphics.draw(quad)

moon3d.madshaders.displayBenchmarkInfoV2("GLSLSandbox/#3281.0", 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>
