+ Code SnippetSetErrorMode(2)
// set window properties
SetWindowTitle( "SuperNova" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
createVSShaderFile()
createPSshaderFile()
chunk = CreateObjectPlane(1000,1000)
SetObjectColor(chunk,255,255,255,255)
Shader=LoadShader("supernova.vs","supernova.ps")
SetObjectShader(chunk,Shader)
SetShaderConstantByName( Shader,"iResolution",900,900,0,0 )
do
SetShaderConstantByName( Shader,"time",Timer()*.5,0,0,0 )
Print( ScreenFPS() )
Sync()
loop
// This is the function which creates the two files VS and PS
// These just simply output lines of code to the two files
function createVSShaderFile()
fw = OpenToWrite("supernova.vs")
WriteLine(fw,"attribute highp vec3 position;")
WriteLine(fw,"attribute mediump vec3 normal;")
WriteLine(fw,"varying highp vec3 posVarying;")
WriteLine(fw,"varying mediump vec3 normalVarying;")
WriteLine(fw,"varying mediump vec3 lightVarying;")
WriteLine(fw,"mediump vec3 GetVSLighting( mediump vec3 normal, highp vec3 pos );")
WriteLine(fw,"uniform highp mat3 agk_WorldNormal;")
WriteLine(fw,"uniform highp mat4 agk_World;")
WriteLine(fw,"uniform highp mat4 agk_ViewProj;")
WriteLine(fw,"attribute highp vec2 uv;")
WriteLine(fw,"varying highp vec2 uvVarying;")
WriteLine(fw,"uniform highp vec4 uvBounds0;")
WriteLine(fw,"void main()")
WriteLine(fw,"{ ")
WriteLine(fw,"uvVarying = uv * uvBounds0.xy + uvBounds0.zw;")
WriteLine(fw,"highp vec4 pos = agk_World * vec4(position,1.0);")
WriteLine(fw,"mediump vec3 norm = normalize(agk_WorldNormal * normal);")
WriteLine(fw,"gl_Position = agk_ViewProj * pos;")
WriteLine(fw,"posVarying = pos.xyz;")
WriteLine(fw,"normalVarying = norm;")
WriteLine(fw,"lightVarying = GetVSLighting( norm, posVarying );")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
function createPSshaderFile()
fw=OpenToWrite("supernova.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"#extension GL_OES_standard_derivatives : enable")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 mouse;")
WriteLine(fw,"uniform vec2 iResolution;")
WriteLine(fw,"//#define BOTH")
WriteLine(fw,"// uncomment this string to see left part")
WriteLine(fw,"#define LEFT")
WriteLine(fw,"//#define LOW_QUALITY")
WriteLine(fw,"#define DITHERING")
WriteLine(fw,"//#define TONEMAPPING")
WriteLine(fw,"//-------------------")
WriteLine(fw,"#define pi 3.14159265")
WriteLine(fw,"#define R(p, a) p=cos(a)*p+sin(a)*vec2(p.y, -p.x)")
WriteLine(fw,"vec3 hash( vec3 p )")
WriteLine(fw,"{")
WriteLine(fw," p = vec3( dot(p,vec3(127.1,311.7, 74.7)),")
WriteLine(fw," dot(p,vec3(269.5,183.3,246.1)),")
WriteLine(fw," dot(p,vec3(113.5,271.9,124.6)));")
WriteLine(fw," return -1.0 + 2.0*fract(sin(p)*43758.5453123);")
WriteLine(fw,"}")
WriteLine(fw,"float noise( in vec3 p )")
WriteLine(fw,"{")
WriteLine(fw," vec3 i = floor( p );")
WriteLine(fw," vec3 f = fract( p );")
WriteLine(fw," vec3 u = f*f*(3.0-2.0*f);")
WriteLine(fw," return mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), ")
WriteLine(fw," dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),")
WriteLine(fw," mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), ")
WriteLine(fw," dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),")
WriteLine(fw," mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), ")
WriteLine(fw," dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),")
WriteLine(fw," mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), ")
WriteLine(fw," dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z );")
WriteLine(fw,"}")
WriteLine(fw,"float fbm( vec3 p )")
WriteLine(fw,"{")
WriteLine(fw," return noise(p*.06125)*.5 + noise(p*.125)*.25 + noise(p*.25)*.125 + noise(p*.4)*.2;")
WriteLine(fw,"}")
WriteLine(fw,"float rand(vec2 co)")
WriteLine(fw,"{")
WriteLine(fw," return fract(sin(dot(co*0.123,vec2(12.9898,78.233))) * 43758.5453);")
WriteLine(fw,"}")
WriteLine(fw,"float Sphere( vec3 p, float r )")
WriteLine(fw,"{")
WriteLine(fw," return length(p)-r;")
WriteLine(fw,"}")
//==============================================================
// otaviogood's noise from https://www.shadertoy.com/view/ld2SzK
//--------------------------------------------------------------
// This spiral noise works by successively adding and rotating sin waves while increasing frequency.
// It should work the same on all computers since it's not based on a hash function like some other noises.
// It can be much faster than other noise functions if you're ok with some repetition.
WriteLine(fw,"const float nudge = 4.; // size of perpendicular vector")
WriteLine(fw,"float normalizer = 1.0 / sqrt(1.0 + nudge*nudge); // pythagorean theorem on that perpendicular to maintain scale")
WriteLine(fw,"float SpiralNoiseC(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw," float n = -mod(time * 0.2,-2.); // noise amount")
WriteLine(fw," float iter = 2.0;")
WriteLine(fw," for (int i = 0; i < 8; i++)")
WriteLine(fw," {")
// add sin and cos scaled inverse with the frequency
WriteLine(fw," n += -abs(sin(p.y*iter) + cos(p.x*iter)) / iter; // abs for a ridged look")
WriteLine(fw," // rotate by adding perpendicular and scaling down")
WriteLine(fw," p.xy += vec2(p.y, -p.x) * nudge;")
WriteLine(fw," p.xy *= normalizer;")
WriteLine(fw," // rotate on other axis")
WriteLine(fw," p.xz += vec2(p.z, -p.x) * nudge;")
WriteLine(fw," p.xz *= normalizer;")
// increase the frequency
WriteLine(fw," iter *= 1.733733;")
WriteLine(fw," }")
WriteLine(fw," return n;")
WriteLine(fw,"}")
WriteLine(fw,"float VolumetricExplosion(vec3 p)")
WriteLine(fw,"{")
WriteLine(fw," float final = Sphere(p,4.);")
WriteLine(fw," #ifdef LOW_QUALITY")
WriteLine(fw," final += noise(p*12.5)*.2;")
WriteLine(fw," #else")
WriteLine(fw," final += fbm(p*50.);")
WriteLine(fw," #endif")
WriteLine(fw," final += SpiralNoiseC(p.zxy*0.4132+333.)*3.0; //1.25;")
WriteLine(fw," return final;")
WriteLine(fw,"}")
WriteLine(fw,"float map(vec3 p) ")
WriteLine(fw,"{")
WriteLine(fw," R(p.xz, mouse.x*0.008*pi+time*0.1);")
WriteLine(fw," float VolExplosion = VolumetricExplosion(p/0.5)*0.5; // scale")
WriteLine(fw," return VolExplosion;")
WriteLine(fw,"}")
//--------------------------------------------------------------
// assign color to the media
WriteLine(fw,"vec3 computeColor( float density, float radius )")
WriteLine(fw,"{")
// color based on density alone, gives impression of occlusion within
// the media
WriteLine(fw," vec3 result = mix( vec3(1.0,0.9,0.8), vec3(0.4,0.15,0.1), density );")
// color added to the media
WriteLine(fw," vec3 colCenter = 7.*vec3(0.8,1.0,1.0);")
WriteLine(fw," vec3 colEdge = 1.5*vec3(0.48,0.53,0.5);")
WriteLine(fw," result *= mix( colCenter, colEdge, min( (radius+.05)/.9, 1.15 ) );")
WriteLine(fw," return result;")
WriteLine(fw,"}")
WriteLine(fw,"bool RaySphereIntersect(vec3 org, vec3 dir, out float near, out float far)")
WriteLine(fw,"{")
WriteLine(fw," float b = dot(dir, org);")
WriteLine(fw," float c = dot(org, org) - 8.;")
WriteLine(fw," float delta = b*b - c;")
WriteLine(fw," if( delta < 0.0) ")
WriteLine(fw," return false;")
WriteLine(fw," float deltasqrt = sqrt(delta);")
WriteLine(fw," near = -b - deltasqrt;")
WriteLine(fw," far = -b + deltasqrt;")
WriteLine(fw," return far > 0.0;")
WriteLine(fw,"}")
// Applies the filmic curve from John Hable's presentation
// More details at : http://filmicgames.com/archives/75
WriteLine(fw,"vec3 ToneMapFilmicALU(vec3 _color)")
WriteLine(fw,"{")
WriteLine(fw," _color = max(vec3(0), _color - vec3(0.004));")
WriteLine(fw," _color = (_color * (6.2*_color + vec3(0.5))) / (_color * (6.2 * _color + vec3(1.7)) + vec3(0.06));")
WriteLine(fw," return _color;")
WriteLine(fw,"}")
WriteLine(fw,"void main( void )")
WriteLine(fw,"{ ")
WriteLine(fw," vec2 uv = gl_FragCoord.xy/iResolution.xy;")
// ro: ray origin
// rd: direction of the ray
WriteLine(fw," vec3 rd = normalize(vec3((gl_FragCoord.xy-0.5*iResolution.xy)/iResolution.y, 1.));")
WriteLine(fw," vec3 ro = vec3(0., 0., -6.);")
WriteLine(fw," #ifdef DITHERING")
WriteLine(fw," vec2 seed = uv + fract(time);")
WriteLine(fw," #endif ")
// ld, td: local, total density
// w: weighting factor
WriteLine(fw," float ld=0., td=0., w=0.;")
// t: length of the ray
// d: distance function
WriteLine(fw," float d=1., t=0.;")
WriteLine(fw," const float h = 0.1;")
WriteLine(fw," vec4 sum = vec4(0.0);")
WriteLine(fw," float min_dist=0.0, max_dist=0.0;")
WriteLine(fw," if(RaySphereIntersect(ro, rd, min_dist, max_dist))")
WriteLine(fw,"{")
WriteLine(fw," t = min_dist*step(t,min_dist);")
// raymarch loop
WriteLine(fw," #ifdef LOW_QUALITY")
WriteLine(fw," for (int i=0; i<56; i++)")
WriteLine(fw," #else")
WriteLine(fw," for (int i=0; i<86; i++)")
WriteLine(fw," #endif")
WriteLine(fw," {")
WriteLine(fw," vec3 pos = ro + t*rd;")
// Loop break conditions.
WriteLine(fw," if(td>0.9 || d<0.12*t || t>10. || sum.a > 0.99 || t>max_dist) break;")
// evaluate distance function
WriteLine(fw," float d = map(pos);")
WriteLine(fw," #ifdef BOTH")
WriteLine(fw," if (uv.x<0.5)")
WriteLine(fw," {")
WriteLine(fw," d = abs(d)+0.07;")
WriteLine(fw," }")
WriteLine(fw," #else")
WriteLine(fw," #ifdef LEFT")
WriteLine(fw," d = abs(d)+0.07;")
WriteLine(fw," #endif")
WriteLine(fw," #endif")
// change this string to control density
WriteLine(fw," d = max(d,0.03);")
// point light calculations
WriteLine(fw," vec3 ldst = vec3(0.0)-pos;")
WriteLine(fw," float lDist = max(length(ldst), 0.001);")
// the color of light
WriteLine(fw," vec3 lightColor=vec3(1.0,0.5,0.25);")
WriteLine(fw," sum.rgb+=(lightColor/exp(lDist*lDist*lDist*.08)/30.); // bloom")
WriteLine(fw," if (d<h)")
WriteLine(fw," {")
// compute local density
WriteLine(fw," ld = h - d;")
// compute weighting factor
WriteLine(fw," w = (1. - td) * ld;")
// accumulate density
WriteLine(fw," td += w + 1./200.;")
WriteLine(fw," vec4 col = vec4( computeColor(td,lDist), td );")
// emission
WriteLine(fw," sum += sum.a * vec4(sum.rgb, 0.0) * 0.2 / lDist; ")
// uniform scale density
WriteLine(fw," col.a *= 0.2;")
// colour by alpha
WriteLine(fw," col.rgb *= col.a;")
// alpha blend in contribution
WriteLine(fw," sum = sum + col*(1.0 - sum.a); ")
WriteLine(fw," }")
WriteLine(fw," td += 1./70.;")
WriteLine(fw," #ifdef DITHERING")
WriteLine(fw," d=abs(d)*(.8+0.2*rand(seed*vec2(i)));")
WriteLine(fw," #endif ")
// trying to optimize step size
WriteLine(fw," #ifdef LOW_QUALITY")
WriteLine(fw," t += max(d*0.25,0.01);")
WriteLine(fw," #else")
WriteLine(fw," t += max(d * 0.08 * max(min(length(ldst),d),2.0), 0.01);")
WriteLine(fw," #endif")
WriteLine(fw," }")
// simple scattering
WriteLine(fw," #ifdef LOW_QUALITY ")
WriteLine(fw," sum *= 1. / exp( ld * 0.2 ) * 0.9;")
WriteLine(fw," #else")
WriteLine(fw," sum *= 1. / exp( ld * 0.2 ) * 0.8;")
WriteLine(fw," #endif")
WriteLine(fw," sum = clamp( sum, 0.0, 1.0 );")
WriteLine(fw," sum.xyz = sum.xyz*sum.xyz*(3.0-2.0*sum.xyz);")
WriteLine(fw," }")
WriteLine(fw," #ifdef TONEMAPPING")
WriteLine(fw," gl_FragColor = vec4(ToneMapFilmicALU(sum.xyz*2.2),1.0);")
WriteLine(fw," #else")
WriteLine(fw," gl_FragColor = vec4(sum.xyz,1.0);")
WriteLine(fw," #endif")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
+ Code SnippetSetErrorMode(2)
#constant KEY_SPACE = 32 //the space bar
// set window properties
SetWindowTitle( "circuit" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
createShaderFile()
CreateSprite(1,0)
CreateSprite(2,0)
CreateSprite(3,0)
NoiseInit()
SetSpriteImage (3,createRandomBgImage())
SetSpriteAdditionalImage (3,generateperlinimage(),1)
SetSpriteSize(1,1024,768)
SetSpriteSize(2,1024,768)
SetSpriteSize(3,1024,768)
LoadSpriteShader(1,"circuit.ps")
LoadSpriteShader(2,"circuit2.ps")
LoadSpriteShader(3,"circuit3.ps")
SetSpriteShader( 1,1 )
SetSpriteShader( 2,2 )
SetSpriteShader( 3,3 )
SetShaderConstantByName(1,"resolution",1024,768,0,0)
SetShaderConstantByName(2,"resolution",1024,768,0,0)
SetShaderConstantByName(3,"iResolution",1024,768,0,0)
num=1
SetSpriteDepth(num,0)
do
print("press space to switch shaders")
If GetRawKeyPressed(KEY_SPACE)
if num = 1
num=2:SetSpriteDepth(1,10):SetSpriteDepth(2,0):SetSpriteDepth(3,10)
elseif num =2
num=3:SetSpriteDepth(1,10):SetSpriteDepth(2,10):SetSpriteDepth(3,0)
else
num=1:SetSpriteDepth(1,0):SetSpriteDepth(2,10):SetSpriteDepth(3,10)
endif
endif
SetShaderConstantByName(num,"time",timer(),0,0,0)
print(num)
sync()
loop
function createShaderFile()
fw=OpenToWrite("circuit.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float iTime = 0.0;")
WriteLine(fw,"vec3 iResolution = vec3(0.0);")
WriteLine(fw,"#define texture(s, uv) vec4(0.0)")
WriteLine(fw,"#define textureLod(s, uv, lod) vec4(0.0)")
WriteLine(fw,"#define time iTime*.02")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw," float minit=0.;")
WriteLine(fw," float o,ot2,ot=ot2=1000.;")
WriteLine(fw," for (int i=0; i<9; i++) {")
WriteLine(fw," z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw," float l=length(z);")
WriteLine(fw," o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw," ot=min(ot,o);")
WriteLine(fw," ot2=min(l*.1,ot2);")
WriteLine(fw," minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw," }")
WriteLine(fw," minit+=1.;")
WriteLine(fw," float w=width*minit*2.;")
WriteLine(fw," float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw," shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw," vec3 col=normalize(.1+texture(iChannel1,vec2(minit*.1)).rgb);")
WriteLine(fw," color+=col*(.4+mod(minit/9.-time*10.+ot2*2.,1.)*1.6);")
WriteLine(fw," color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture(iChannel0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void mainImage( out vec4 fragColor, in vec2 fragCoord )")
WriteLine(fw,"{")
WriteLine(fw," vec2 pos = fragCoord.xy / iResolution.xy - .5;")
WriteLine(fw," pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw," vec2 uv=pos;")
WriteLine(fw," float sph = length(uv); sph = sqrt(1. - sph*sph); // curve for spheric distortion")
WriteLine(fw," uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw," float a=.5+mod(.5,1.)*.5;")
WriteLine(fw," vec2 luv=uv;")
WriteLine(fw," float b=a*5.48535;")
WriteLine(fw,"// zoom*=1.+sin(time*3.758123)*.8;")
WriteLine(fw," uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw," uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw," uv*=zoom;")
WriteLine(fw," float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw," float dof=max(1.,(10.-mod(time,1.)/.01));")
WriteLine(fw," float c=1.5+mod(floor(time),6.)*.125;")
WriteLine(fw," for (int aa=0; aa<36; aa++) {")
WriteLine(fw," vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw," formula(uv+aauv*pix*dof,c);")
WriteLine(fw," }")
WriteLine(fw," shape/=36.; color/=36.;")
WriteLine(fw," vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(time+.5,1.))*10.); ")
WriteLine(fw," colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw," fragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
WriteLine(fw,"#undef time")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw," iTime = time;")
WriteLine(fw," iResolution = vec3(resolution, 0.0);")
WriteLine(fw," mainImage(gl_FragColor, gl_FragCoord.xy);")
WriteLine(fw,"}")
CloseFile(fw)
fw=OpenToWrite("circuit2.ps")
WriteLine(fw,"#ifdef GL_ES")
WriteLine(fw,"precision mediump float;")
WriteLine(fw,"#endif")
WriteLine(fw,"uniform float time;")
WriteLine(fw,"uniform vec2 resolution;")
WriteLine(fw,"float iTime = 0.0;")
WriteLine(fw,"vec3 iResolution = vec3(0.0);")
WriteLine(fw,"#define texture(s, uv) vec4(0.0)")
WriteLine(fw,"#define textureLod(s, uv, lod) vec4(0.0)")
WriteLine(fw,"#define time iTime*.009")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw," float minit=0.;")
WriteLine(fw," float o,ot2,ot=ot2=1000.;")
WriteLine(fw," for (int i=0; i<9; i++) {")
WriteLine(fw," z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw," float l=length(z);")
WriteLine(fw," o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw," ot=min(ot,o);")
WriteLine(fw," ot2=min(l*.1,ot2);")
WriteLine(fw," minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw," }")
WriteLine(fw," minit+=1.;")
WriteLine(fw," float w=width*minit*2.;")
WriteLine(fw," float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw," shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw," vec3 col=normalize(.1+texture(iChannel1,vec2(minit*.1)).rgb);")
WriteLine(fw," color+=col*(.4+mod(minit/9.-time*10.+ot2*2.,1.)*1.6);")
WriteLine(fw," color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture(iChannel0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void mainImage( out vec4 fragColor, in vec2 fragCoord )")
WriteLine(fw,"{")
WriteLine(fw," vec2 pos = fragCoord.xy / iResolution.xy - .5;")
WriteLine(fw," pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw," vec2 uv=pos;")
WriteLine(fw," float sph = length(uv); sph = sqrt(1. - sph*sph)*1.5; // curve for spheric distortion")
WriteLine(fw," uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw," float a=time+mod(time,1.)*.5;")
WriteLine(fw," vec2 luv=uv;")
WriteLine(fw," float b=a*5.48535;")
WriteLine(fw,"// zoom*=1.+sin(time*3.758123)*.8;")
WriteLine(fw," uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw," uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw," uv*=zoom;")
WriteLine(fw," float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw," float dof=max(1.,(10.-mod(time,1.)/.01));")
WriteLine(fw," float c=1.5+mod(floor(time),6.)*.125;")
WriteLine(fw," for (int aa=0; aa<36; aa++) {")
WriteLine(fw," vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw," formula(uv+aauv*pix*dof,c);")
WriteLine(fw," }")
WriteLine(fw," shape/=36.; color/=36.;")
WriteLine(fw," vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(time+.5,1.))*10.); ")
WriteLine(fw," colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw," fragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
WriteLine(fw,"#undef time")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw," iTime = time;")
WriteLine(fw," iResolution = vec3(resolution, 0.0);")
WriteLine(fw," mainImage(gl_FragColor, gl_FragCoord.xy);")
WriteLine(fw,"}")
CloseFile(fw)
fw=OpenToWrite("circuit3.ps")
WriteLine(fw,"uniform vec3 iResolution; // viewport resolution (in pixels)")
WriteLine(fw,"uniform float time; // shader playback time (in seconds)")
WriteLine(fw,"uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click")
WriteLine(fw,"uniform sampler2D texture0;")
WriteLine(fw,"uniform sampler2D texture1;")
WriteLine(fw,"#define iTime time*.02")
WriteLine(fw,"#define width .005")
WriteLine(fw,"float zoom = .18;")
WriteLine(fw,"float shape=0.;")
WriteLine(fw,"vec3 color=vec3(0.),randcol;")
WriteLine(fw,"void formula(vec2 z, float c) {")
WriteLine(fw," float minit=0.;")
WriteLine(fw," float o,ot2,ot=ot2=1000.;")
WriteLine(fw," for (int i=0; i<9; i++) {")
WriteLine(fw," z=abs(z)/clamp(dot(z,z),.1,.5)-c;")
WriteLine(fw," float l=length(z);")
WriteLine(fw," o=min(max(abs(min(z.x,z.y)),-l+.25),abs(l-.25));")
WriteLine(fw," ot=min(ot,o);")
WriteLine(fw," ot2=min(l*.1,ot2);")
WriteLine(fw," minit=max(minit,float(i)*(1.-abs(sign(ot-o))));")
WriteLine(fw," }")
WriteLine(fw," minit+=1.;")
WriteLine(fw," float w=width*minit*2.;")
WriteLine(fw," float circ=pow(max(0.,w-ot2)/w,6.);")
WriteLine(fw," shape+=max(pow(max(0.,w-ot)/w,.25),circ);")
WriteLine(fw," vec3 col=normalize(.1+texture2D(texture1,vec2(minit*.1)).rgb);")
WriteLine(fw," color+=col*(.4+mod(minit/9.-iTime*10.+ot2*2.,1.)*1.6);")
WriteLine(fw," color+=vec3(1.,.7,.3)*circ*(10.-minit)*3.*smoothstep(0.,.5,.15+texture2D(texture0,vec2(.0,1.)).x-.5);")
WriteLine(fw,"}")
WriteLine(fw,"void main(void)")
WriteLine(fw,"{")
WriteLine(fw," vec2 pos = gl_FragCoord.xy / iResolution.xy - .5;")
WriteLine(fw," pos.x*=iResolution.x/iResolution.y;")
WriteLine(fw," vec2 uv=pos;")
WriteLine(fw," float sph = length(uv); sph = sqrt(1. - sph*sph)*1.5; // curve for spheric distortion")
WriteLine(fw," uv=normalize(vec3(uv,sph)).xy;")
WriteLine(fw," float a=iTime+mod(iTime,1.)*.5;")
WriteLine(fw," vec2 luv=uv;")
WriteLine(fw," float b=a*5.48535;")
WriteLine(fw," // zoom*=1.+sin(iTime*3.758123)*.8;")
WriteLine(fw," uv*=mat2(cos(b),sin(b),-sin(b),cos(b));")
WriteLine(fw," uv+=vec2(sin(a),cos(a*.5))*8.;")
WriteLine(fw," uv*=zoom;")
WriteLine(fw," float pix=.5/iResolution.x*zoom/sph;")
WriteLine(fw," float dof=max(1.,(10.-mod(iTime,1.)/.01));")
WriteLine(fw," float c=1.5+mod(floor(iTime),6.)*.125;")
WriteLine(fw," for (int aa=0; aa<36; aa++) {")
WriteLine(fw," vec2 aauv=floor(vec2(float(aa)/6.,mod(float(aa),6.)));")
WriteLine(fw," formula(uv+aauv*pix*dof,c);")
WriteLine(fw," }")
WriteLine(fw," shape/=36.; color/=36.;")
WriteLine(fw," vec3 colo=mix(vec3(.15),color,shape)*(1.-length(pos))*min(1.,abs(.5-mod(iTime+.5,1.))*10.); ")
WriteLine(fw," colo*=vec3(1.2,1.1,1.0);")
WriteLine(fw," gl_FragColor = vec4(colo,1.0);")
WriteLine(fw,"}")
CloseFile(fw)
endfunction
//creates texture 0 for sprite 3
function createRandomBgImage()
SetClearColor(0,0,0)
ClearScreen()
Render()
For num = 1 to 500
DrawEllipse(Random(1,1023),Random(1,787),random(10,30),random(10,30),makecolor(random(1,255),random(1,255),random(1,255)),makecolor(random(1,255),random(1,255),random(1,255)),1)
next num
swap()
img = getimage(0,0,1024,768)
//SetImageTransparentColor(img,0,0,0)
endfunction img
//the rest just creates a noise image for texture 1 for sprite x
function generateperlinimage()
// Generate image from memblock
w as integer = 100
h as integer =100
size = w * h * 4 + 12
mem = CreateMemblock(size)
SetMemblockInt(mem,0,w)
SetMemblockInt(mem,4,h)
SetMemblockInt(mem,8,32)
offset as integer = 12
a as float, b as float
a = 5.0
b = 2.0
for y = 0 to h - 1
for x = 0 to w - 1
a = a + 0.0001
b = b + 0.002
// Try out these two noise methods
//noise = 255.0*Noise2D(x/10.0,y/10.0)
noise = 255.0*Noise2D(x/100.0,y/100.0)
noise = abs(noise)
//clouds
if noise>200
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
//greenary
if noise>150 and noise<=200
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
//sand
if noise>100 and noise<=150
SetMemblockByte(mem, offset, noise)
SetMemblockByte(mem, offset+1, noise)
SetMemblockByte(mem, offset+2, 0)
SetMemblockByte(mem, offset+3, 255)
endif
// water
if noise<=100
SetMemblockByte(mem, offset, 0)
SetMemblockByte(mem, offset+1, 0)
SetMemblockByte(mem, offset+2, noise)
SetMemblockByte(mem, offset+3, 255)
endif
offset = offset + 4
next
next
map=CreateImageFromMemblock(mem)
endfunction map
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
Type sPNVECTOR
x as float
y as float
z as float
endtype
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
Function NoiseInit()
Local n as integer, rn as integer
For n=0 To 255
PNHash[n] = n
Next n
For n=0 To 255
rn=Random(0, 255)
PNHash.swap(n,rn)
Next n
For n=0 To 255
PNHash[256 + n] = PNHash[n]
Next n
PNHash[511] = PNHash[0]
For n=0 To 15
PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
Next n
endfunction
function Noise2D(xin as float, yin as float)
local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
s = (xin + yin) * PN3DF2
xs = xin + s
i = floor(xs)
ys = yin + s
j = floor(ys)
t = (i + j) * PN3DG2
x0 = xin - (i - t)
y0 = yin - (j - t)
if x0>y0
i1=1
j1=0
else
i1=0
j1=1
endif
x1 = x0 - i1 + PN3DG2
y1 = y0 - j1 + PN3DG2
x2 = x0 - 1.0 + 2.0 * PN3DG2
y2 = y0 - 1.0 + 2.0 * PN3DG2
i = i && 255
j = j && 255
gi0 = PNHash[i + PNHash[j]] && 15
gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
t0 = 0.5 - x0*x0-y0*y0
if t0<0
n0 = 0.0
else
t0 = t0 * t0
n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
endif
t1 = 0.5 - x1*x1-y1*y1
if t1<0
n1 = 0.0
else
t1 = t1 * t1
n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
endif
t2 = 0.5 - x2*x2-y2*y2
if t2<0
n2 = 0.0
else
t2 = t2 * t2
n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
endif
endfunction 70.0 * (n0 + n1 + n2)