Found a cool wobbly shader on glslsandbox. Tweaked it to look like flames! This is my first attempt at playing with shaders. FUN!
vertex.vs
attribute vec4 position;
attribute vec4 color;
attribute vec2 uv;
varying vec2 uvVarying;
varying vec4 colorVarying;
varying vec2 posVarying;
uniform mat4 agk_Ortho;
void main()
{
gl_Position = agk_Ortho * position;
posVarying = position.xy;
uvVarying = uv;
colorVarying = color;
}
pixel.ps
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 agk_resolution;
uniform float time;
uniform float alpha;
uniform vec2 speed;
uniform float shift;
float rand(vec2 n)
{
return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float flames(vec2 n)
{
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
float fbm(vec2 n)
{
float total = 0.0, amplitude = 1.0;
for (int i = 0; i < 4; i++) {
total += flames(n) * amplitude;
n += n;
amplitude *= .5;
}
return total;
}
void main()
{
const vec3 c1 = vec3(126.0/255.0, 10.0/255.0, 47.0/255.0);
const vec3 c2 = vec3(173.0/255.0, 161.0/255.0, 0.4/255.0);
const vec3 c3 = vec3(0.2, 0.0, 0.0);
const vec3 c4 = vec3(164.0/255.0, 1.0/255.0, 114.4/255.0);
const vec3 c5 = vec3(0.1);
const vec3 c6 = vec3(0.9);
vec2 p = gl_FragCoord.xy * 8.0 / agk_resolution.xx;
float q = fbm(p - time * 0.1);
vec2 r = vec2(fbm(p + q + time * speed.x - p.x - p.y), fbm(p + q - time * speed.y));
vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);
float grad = gl_FragCoord.y / agk_resolution.y;
gl_FragColor = vec4(c * cos(shift * gl_FragCoord.y / agk_resolution.y), 1.0);
gl_FragColor.xyz *= 1.0-grad;
}
main.agk
SetWindowTitle( "test" )
SetWindowSize( 640, 480, 0 )
// set display properties
SetVirtualResolution( 640, 480 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetPrintColor(0,0,0)
SetSyncRate(0,0)
ImageID=loadimage("grid.jpg")
SpriteID=createsprite(ImageID)
//ShaderID=LoadSpriteShader("pixel.ps" )
ShaderID=LoadShader("vertex.vs", "pixel.ps" )
SetSpriteShader(SpriteID,ShaderID)
do
Time#=Time#+8.5*getframetime()
setShaderConstantByName(ShaderID, "time",Time#,0,0,0)
Print( ScreenFPS() )
print(Time#)
Sync()
loop