-- Shader test 12 planet function love.load() love.graphics.setDefaultFilter("nearest", "nearest") scr_w, scr_h = 640, 480 canvas = love.graphics.newCanvas(scr_w, scr_h) img = love.graphics.newImage("grid_bg_480x480.png") img:setFilter("linear", "linear") -- make shader local shadercode = [[ extern number start_x; extern number start_y; const float PI = 3.14159265; vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ) { // float sx = (screen_coords.x - (love_ScreenSize.x / 2)) / love_ScreenSize.y; // float sy = (screen_coords.y - (love_ScreenSize.y / 2)) / love_ScreenSize.y; float tx = texture_coords.x - 0.5; float ty = texture_coords.y - 0.5; float a = asin(ty * 2); float v = a / PI; float r = cos(a); float b = asin(tx * 2 / r); float u = b / PI; texture_coords.x = mod((u + start_x) + 0.5, 1.0); texture_coords.y = mod((v + start_y) + 0.5, 1.0); vec4 texcolor = Texel(texture, texture_coords); texcolor.a = (tx * 2 > r)? 0.0 : texcolor.a; texcolor.a = (tx * 2 < -r)? 0.0 : texcolor.a; return texcolor * color; } ]] myshader = love.graphics.newShader(shadercode) myshader:send("start_x", 0.0) myshader:send("start_y", 0.0) ang = 0.0 px = (scr_w - img:getWidth()) / 2 py = (scr_h - img:getHeight()) / 2 end function love.update(dt) ang = ang + 0.1 * dt myshader:send("start_x", ang) end function love.draw() love.graphics.setCanvas(canvas) love.graphics.clear(24, 64, 176, 255) love.graphics.setColor(255, 255, 255) love.graphics.setShader(myshader) love.graphics.draw(img, px, py) love.graphics.setShader() love.graphics.setCanvas() -- draw canvas to window wdw_w, wdw_h = love.graphics.getDimensions() scr_scale = math.min((wdw_w / scr_w), (wdw_h / scr_h)) scr_ox = (wdw_w - (scr_w * scr_scale)) / 2 scr_oy = (wdw_h - (scr_h * scr_scale)) / 2 love.graphics.setColor(255, 255, 255) love.graphics.draw(canvas, scr_ox, scr_oy, 0, scr_scale, scr_scale) love.graphics.print("FPS: "..tostring(love.timer.getFPS()), 10, 10) end function love.keypressed(key, isrepeat) if key == "escape" then -- ESC to exit love.event.quit() elseif key == "f11" then -- toggle fullscreen if love.window.getFullscreen() then love.window.setFullscreen(false) else love.window.setFullscreen(true) end end end