Created
January 12, 2014 23:52
-
-
Save prusnak/8392400 to your computer and use it in GitHub Desktop.
love-android-sdl2 shader test
This file contains hidden or 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
local function firePalette() | |
local c = love.graphics.newCanvas(512,512) | |
love.graphics.setCanvas(c) | |
c:clear() | |
local i = 0 | |
for y = 0, 31 do | |
for x = 0, 31 do | |
local r = 255*(math.sin(i * math.pi / 128.0)/2.0 + 0.5) | |
local g = 0 | |
local s = math.sin(i * math.pi / 128.0) | |
if s > 0.5 then | |
s = s - 0.5 | |
g = (192*s*2.0); | |
end | |
local b = 128*(math.cos(i * math.pi / 96.0)/2.0 + 0.5) | |
local mf = math.floor | |
love.graphics.setColor(mf(r),mf(g),mf(b),255) | |
love.graphics.point(x+0.5,y+0.5) | |
i = i + 1 | |
end | |
end | |
love.graphics.setCanvas() | |
return c | |
end | |
function love.load() | |
balls = {{128,128}, {128,128}, {128,128}} | |
pal = firePalette() | |
love.graphics.setBackgroundColor(0,60,0) | |
love.graphics.setColor(255,255,255,255) | |
effect = love.graphics.newShader(([[ | |
extern vec2 ball1, ball2, ball3; | |
float dist(vec2 x) | |
{ | |
return sqrt(dot(x, x) + .00001); | |
} | |
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc) | |
{ | |
float p = 0.0; | |
float r = 0.0; | |
p += sin(dist(pc - ball1) / 129.0); | |
p += sin(dist(pc - ball2) / 149.0); | |
p += sin(dist(pc - ball3) / 139.0); | |
p += 3.0; | |
p /= 2.0 * 3.0; | |
p = p * 1024.0; | |
r = p - 32.0 * floor(p / 32.0); | |
return vec4(Texel(tex, vec2(r/(32.0*512.0), 1.0 - p/(32.0*512.0))).rgb, 1.0); | |
} | |
]])) | |
effect:send('ball1', balls[1]) | |
effect:send('ball2', balls[2]) | |
effect:send('ball3', balls[3]) | |
end | |
function love.keypressed(k) | |
if k == "q" or k == "escape" then | |
love.event.quit() | |
end | |
end | |
function love.draw() | |
love.graphics.setShader(effect) | |
love.graphics.draw(pal, 0, 0) | |
end | |
t = 0 | |
function love.update(dt) | |
t = t + dt | |
local midx = pal:getWidth()/2 | |
local midy = pal:getHeight()/2 | |
balls[1] = {math.sin(t/5) * 128 + midx, math.cos(t/5) * 128 + midy} | |
balls[2] = {math.sin(t) * 128 + midx, math.cos(t/3) * 128 + midy} | |
balls[3] = { | |
math.sin(t) * (110 + math.sin(.01*t) * 110) + midx, | |
math.cos(t) * (110 + math.sin(.01*t) * 110) + midy, | |
} | |
effect:send('ball1', balls[1]) | |
effect:send('ball2', balls[2]) | |
effect:send('ball3', balls[3]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment