Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ecf1e08
Showing
9 changed files
with
2,185 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
enum { | ||
SDL_ANYFORMAT = 0x10000000, | ||
SDL_HWPALETTE = 0x20000000, | ||
SDL_DOUBLEBUF = 0x40000000, | ||
SDL_FULLSCREEN = 0x80000000, | ||
SDL_OPENGL = 0x00000002, | ||
SDL_OPENGLBLIT = 0x0000000A, | ||
SDL_RESIZABLE = 0x00000010, | ||
SDL_NOFRAME = 0x00000020 | ||
}; | ||
|
||
enum { | ||
SDL_INIT_TIMER = 0x00000001, | ||
SDL_INIT_AUDIO = 0x00000010, | ||
SDL_INIT_VIDEO = 0x00000020, | ||
SDL_INIT_CDROM = 0x00000100, | ||
SDL_INIT_JOYSTICK = 0x00000200, | ||
SDL_INIT_EVERYTHING = 0x00100000, | ||
SDL_INIT_NOPARACHUTE = 0x01000000 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
|
||
uniform sampler2D sampler_prev; | ||
uniform sampler2D sampler_prev_n; | ||
uniform sampler2D sampler_blur; | ||
uniform sampler2D sampler_noise; | ||
uniform sampler2D sampler_noise_n; | ||
|
||
varying vec2 pixel; | ||
uniform vec2 pixelSize; | ||
uniform vec4 rnd; | ||
uniform vec2 mouse; | ||
uniform float time; | ||
uniform float fps; | ||
|
||
void main(void) { | ||
// grabbing the blurred gradients | ||
vec2 d = pixelSize*4.; | ||
vec4 dx = (texture2D(sampler_blur, pixel + vec2(1,0)*d) - texture2D(sampler_blur, pixel - vec2(1,0)*d))*0.5; | ||
vec4 dy = (texture2D(sampler_blur, pixel + vec2(0,1)*d) - texture2D(sampler_blur, pixel - vec2(0,1)*d))*0.5; | ||
|
||
vec2 zoom_in = pixel + vec2(dx.x,dy.x)*pixelSize*8.; // adding the traveling wave front | ||
vec2 rand_noise = texture2D(sampler_noise, zoom_in + vec2(rnd.x, rnd.y)).xy; | ||
gl_FragColor.x = texture2D(sampler_prev, zoom_in).x + (rand_noise.x-0.5)*0.0025 - 0.002; // decay with error diffusion | ||
gl_FragColor.x -= (texture2D(sampler_blur, zoom_in + (rand_noise-0.5)*pixelSize).x - | ||
texture2D(sampler_prev, zoom_in + (rand_noise-0.5)*pixelSize)).x*0.054; // reaction-diffusion | ||
|
||
gl_FragColor.a = 1.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
// original shader from http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/ | ||
// horizontal blur fragment shader | ||
uniform sampler2D src_tex; | ||
varying vec2 pixel; | ||
uniform vec2 pixelSize; | ||
void main(void) // fragment | ||
{ | ||
float h = pixelSize.x; | ||
vec4 sum = vec4(0.0); | ||
sum += texture2D(src_tex, vec2(pixel.x - 4.0*h, pixel.y) ) * 0.05; | ||
sum += texture2D(src_tex, vec2(pixel.x - 3.0*h, pixel.y) ) * 0.09; | ||
sum += texture2D(src_tex, vec2(pixel.x - 2.0*h, pixel.y) ) * 0.12; | ||
sum += texture2D(src_tex, vec2(pixel.x - 1.0*h, pixel.y) ) * 0.15; | ||
sum += texture2D(src_tex, vec2(pixel.x + 0.0*h, pixel.y) ) * 0.16; | ||
sum += texture2D(src_tex, vec2(pixel.x + 1.0*h, pixel.y) ) * 0.15; | ||
sum += texture2D(src_tex, vec2(pixel.x + 2.0*h, pixel.y) ) * 0.12; | ||
sum += texture2D(src_tex, vec2(pixel.x + 3.0*h, pixel.y) ) * 0.09; | ||
sum += texture2D(src_tex, vec2(pixel.x + 4.0*h, pixel.y) ) * 0.05; | ||
gl_FragColor.xyz = sum.xyz/0.98; // normalize | ||
gl_FragColor.a = 1.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
// original shader from http://www.gamerendering.com/2008/10/11/gaussian-blur-filter-shader/ | ||
// vertical blur fragment shader | ||
uniform sampler2D src_tex; | ||
varying vec2 pixel; | ||
uniform vec2 pixelSize; | ||
void main(void) // fragment | ||
{ | ||
float v = pixelSize.y; | ||
vec4 sum = vec4(0.0); | ||
sum += texture2D(src_tex, vec2(pixel.x, - 4.0*v + pixel.y) ) * 0.05; | ||
sum += texture2D(src_tex, vec2(pixel.x, - 3.0*v + pixel.y) ) * 0.09; | ||
sum += texture2D(src_tex, vec2(pixel.x, - 2.0*v + pixel.y) ) * 0.12; | ||
sum += texture2D(src_tex, vec2(pixel.x, - 1.0*v + pixel.y) ) * 0.15; | ||
sum += texture2D(src_tex, vec2(pixel.x, + 0.0*v + pixel.y) ) * 0.16; | ||
sum += texture2D(src_tex, vec2(pixel.x, + 1.0*v + pixel.y) ) * 0.15; | ||
sum += texture2D(src_tex, vec2(pixel.x, + 2.0*v + pixel.y) ) * 0.12; | ||
sum += texture2D(src_tex, vec2(pixel.x, + 3.0*v + pixel.y) ) * 0.09; | ||
sum += texture2D(src_tex, vec2(pixel.x, + 4.0*v + pixel.y) ) * 0.05; | ||
gl_FragColor.xyz = sum.xyz/0.98; | ||
gl_FragColor.a = 1.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
|
||
uniform sampler2D sampler_prev; | ||
uniform sampler2D sampler_prev_n; | ||
uniform sampler2D sampler_blur; | ||
uniform sampler2D sampler_noise; | ||
uniform sampler2D sampler_noise_n; | ||
|
||
varying vec2 pixel; | ||
uniform vec2 pixelSize; | ||
uniform vec2 aspect; | ||
uniform vec4 rnd; | ||
uniform vec2 mouse; | ||
uniform float time; | ||
|
||
void main(void) { | ||
|
||
vec2 lightSize=vec2(4.); | ||
|
||
// grabbing the blurred gradients | ||
vec2 d = pixelSize*2.; | ||
vec4 dx = (texture2D(sampler_blur, pixel + vec2(1,0)*d) - texture2D(sampler_blur, pixel - vec2(1,0)*d))*0.5; | ||
vec4 dy = (texture2D(sampler_blur, pixel + vec2(0,1)*d) - texture2D(sampler_blur, pixel - vec2(0,1)*d))*0.5; | ||
|
||
// adding the pixel gradients | ||
d = pixelSize*1.; | ||
dx += texture2D(sampler_prev, pixel + vec2(1,0)*d) - texture2D(sampler_prev, pixel - vec2(1,0)*d); | ||
dy += texture2D(sampler_prev, pixel + vec2(0,1)*d) - texture2D(sampler_prev, pixel - vec2(0,1)*d); | ||
|
||
vec2 displacement = vec2(dx.x,dy.x)*lightSize; // using only the red gradient as displacement vector | ||
float light = pow(max(1.-distance(0.5+(pixel-0.5)*aspect*lightSize + displacement,0.5+(mouse-0.5)*aspect*lightSize),0.),4.); | ||
// vec4 rd = 0.85-(1.-texture2D(sampler_prev,pixel-vec2(dx.x,dy.x)*pixelSize*2.5).x) + light*0.18; | ||
//rd = mix(rd, 1., light*(1.-texture2D(sampler_blur,pixel-vec2(dx.x,dy.x)*pixelSize*4.)).x); | ||
|
||
// recoloring the lit up red channel | ||
vec4 rd = vec4(texture2D(sampler_prev,pixel+vec2(dx.x,dy.x)*pixelSize*8.).x)*vec4(0.7,1.5,2.0,1.0)-vec4(0.3,1.0,1.0,1.0); | ||
gl_FragColor = mix(rd,vec4(8.0,6.,2.,1.), light*0.75*vec4(1.-texture2D(sampler_prev,pixel+vec2(dx.x,dy.x)*pixelSize*8.).x)); | ||
|
||
//gl_FragColor = texture2D(sampler_prev, pixel); // bypass | ||
gl_FragColor.a = 1.; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
attribute vec3 aPos; | ||
attribute vec2 aTexCoord; | ||
varying vec2 pixel; | ||
void main(void) { | ||
gl_Position = vec4(aPos, 1.); | ||
pixel = aTexCoord; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* Generate main header with gcc -I /usr/include/SDL -I /usr/include/GLES2 -E stub.c | grep -v '^#' > generated.h | ||
#include <SDL.h> | ||
#include <gl2.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local ffi = require 'ffi' | ||
local bit = require 'bit' | ||
local fs = require 'fs' | ||
local setInterval = require('timer').setInterval | ||
|
||
ffi.cdef(fs.readFileSync(__dirname .. "/manual.h")) | ||
ffi.cdef(fs.readFileSync(__dirname .. "/generated.h")) | ||
|
||
local sdl = ffi.load("/usr/lib/x86_64-linux-gnu/libSDL.so") | ||
local gles = ffi.load("/usr/lib/x86_64-linux-gnu/libGLESv2.so") | ||
|
||
sdl.SDL_Init(sdl.SDL_INIT_VIDEO) | ||
sdl.SDL_GL_SetAttribute(sdl.SDL_GL_DOUBLEBUFFER, 1) | ||
|
||
--local screen = sdl.SDL_SetVideoMode(0, 0, 0, bit.bor(sdl.SDL_OPENGL, sdl.SDL_FULLSCREEN)) | ||
local screen = sdl.SDL_SetVideoMode(640, 480, 0, sdl.SDL_OPENGL) | ||
sdl.SDL_WM_SetCaption("Triangle", "Triangle") | ||
|
||
|
||
local event = ffi.new("SDL_Event") | ||
|
||
setInterval(1000 / 60, function () | ||
while sdl.SDL_PollEvent(event) > 0 do | ||
p(event) | ||
if (event.type == sdl.SDL_QUIT) or | ||
(event.type == sdl.SDL_KEYDOWN and ( | ||
event.key.keysym.sym == sdl.SDLK_ESCAPE or | ||
(event.key.keysym.sym == sdl.SDLK_c and event.key.keysym.mod == sdl.KMOD_LCTRL) | ||
)) then | ||
process.exit() | ||
end | ||
end | ||
sdl.SDL_GL_SwapBuffers() | ||
end) | ||
|
||
gles.glViewport(0, 0, screen.w, screen.h) | ||
|