Code: Select all
local shader = love.graphics.newShader("palette/shader.glsl")
local palette = love.graphics.newImage("palette/Palette.png")
local sprite = love.graphics.newImage("sprite.png")
sprite:setFilter("nearest", "nearest")
function love.load()
row = 0.0
end
local w, h = love.graphics.getDimensions()
function love.draw()
love.graphics.setColor(0,0,0,1)
love.graphics.rectangle('fill',0,0,w,h)
love.graphics.setColor(1,1,1,1)
love.graphics.setShader(shader)
shader:send("palette", palette)
shader:send("row", row)
love.graphics.draw(sprite, 20, 20, 0, 8, 8)
love.graphics.setShader()
love.graphics.setColor(1,1,1,1)
love.graphics.print(" row :"..row, 0, 0)
end
function love.update(dt)
if love.keyboard.isDown("=") then
row = row + 0.005
elseif love.keyboard.isDown("-") then
row = row - 0.005
end
end
-- function love.keypressed(key)
-- if key == '=' then
-- row = row + 0.01
-- elseif key == '-' then
-- row = row - 0.01
-- end
-- end
Code: Select all
uniform sampler2D palette;
extern float row;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
vec2 u = Texel(texture, texture_coords).ra;
vec4 pixel = Texel(palette, vec2(u.r, row));
pixel.a = u.g;
return pixel * color;
}
The demo has a main.lua, and a folder called palette with glsl and sprite. Hold = or - to change the row of the texture. Note that there aren't any rows after a point and it's just blank.
note: love2d uses glsl 1.20, texelFetch was added in 1.30