Skip to content

Commit

Permalink
Rework color swap shader to be more compatible and work in a web cont…
Browse files Browse the repository at this point in the history
…ext #D716
  • Loading branch information
thomasgoldstein committed Sep 20, 2020
1 parent 1b5bda7 commit 28083dc
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/def/misc/shaders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ if not GLOBAL_SETTING.SHADERS_ENABLED then
love.graphics.setShader = function() end
end

local sh_swapColors = [[
extern number n = 1;
extern vec4 colors[16];
extern vec4 newColors[16];
local sh_swapColors = [[;
uniform vec4 colors[n];
uniform vec4 newColors[n];
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
for (int i = 0; i < n; i++) {
Expand All @@ -51,8 +50,7 @@ local sh_swapColors = [[
} ]]

local function swapColors(originalColors, alternativeColors)
local shader = love.graphics.newShader(sh_swapColors)
shader:send("n", #alternativeColors)
local shader = love.graphics.newShader([[const int n =]] .. tostring(#alternativeColors) .. sh_swapColors)
shader:sendColor("colors", unpack(originalColors))
shader:sendColor("newColors", unpack(alternativeColors))
return shader
Expand Down

0 comments on commit 28083dc

Please sign in to comment.