-- Shader test 13 planet 2 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("planet_tex_480x480.png") img_cloud = love.graphics.newImage("planet_cloud_only_496x496.png") img:setFilter("linear", "linear") img_cloud: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 b = asin(tx * 2); float u = b / PI; float r = cos(b); float a = asin(ty * 2 / r); float v = a / 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 = (ty * 2 > r)? 0.0 : texcolor.a; texcolor.a = (ty * 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) myshader_cloud = love.graphics.newShader(shadercode) myshader_cloud:send("start_x", 0.0) myshader_cloud:send("start_y", 0.0) ang = 0.0 px = scr_w / 2 py = scr_h / 2 end function love.update(dt) ang = ang + 0.07 * dt -- myshader:send("start_x", ang) myshader:send("start_y", ang) myshader_cloud:send("start_y", ang * 0.5) end function love.draw() love.graphics.setCanvas(canvas) love.graphics.clear(0, 0, 0, 255) love.graphics.setColor(255, 255, 255, 255) love.graphics.setShader(myshader) local ofsx = img:getWidth() / 2 local ofsy = img:getHeight() / 2 love.graphics.draw(img, px - ofsx, py - ofsy) love.graphics.setColor(255, 255, 255, 230) love.graphics.setShader(myshader_cloud) ofsx = img_cloud:getWidth() / 2 ofsy = img_cloud:getHeight() / 2 love.graphics.draw(img_cloud, px - ofsx, py - ofsy) 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